11.8 Function Scope in Modules

Sometime later, we decide to edit the example application:


  <SCRIPT LANGUAGE=vortex>

  <USES lookfeel>

  <A NAME=main PUBLIC>
    <look title="My Site">
    This is our main application page.
    <whaturl>
    <P> You came from the URL: $ret
    </look>
  </A>

  <A NAME=whaturl PRIVATE>
    <RETURN $HTTP_REFERER>
  </A>

  </SCRIPT>

We changed the title.

We also added a <whaturl> function to determine what URL the user came from last, because we want to print out that information in main . Since it's a quick little function, we make it PRIVATE because no one else will use it.

Function scope

But look out! We already have a <whaturl> function in our module lookfeel , which is included in this script. We have two different functions doing two different things, but with the same name because we forgot about our long-ago <whaturl> function in the module. Name conflict!

Had both the module code and our example app been in the same traditional script, this would be an error. But instead, the PRIVATE scope comes to our rescue: each function is only visible to the file it is declared in. So our example 's <whaturl> function and call is completely independent of the lookfeel module.

This is another reason functions should always be declared with as small a scope as possible - PRIVATE before EXPORT before PUBLIC . It avoids nasty suprises with functions that "nobody else will ever see...".

Had we declared both functions EXPORT or PUBLIC , then we'd have a name conflict and compile error, just as if they were in the same script.

(next page):

Back: Using a New Revision Next: Using Older Revisions
Copyright © 2024 Thunderstone Software LLC. All rights reserved.