1,375
edits
| Line 37: | Line 37: | ||
== Dealing with Different Objects that have the Same Name == | == Dealing with Different Objects that have the Same Name == | ||
Back to the graph: each portion of the graph has its own variables, some of which might be functions with their own namespaces, and some are hashes that are used as objects or namespaces. We learned that the Nasal code executor looks first at the current namespace for a symbol, then the next higher namespace, until it reaches the top. But what if we define a variable in this scope and we want to access another variable that has the same name but lives in a different namespace? This is what happens in debug.nas; it defines a string function which obscures the string namespace (in computer science this is called [[wikipedia:Variable_shadowing|Variable shadowing]] | Back to the graph: each portion of the graph has its own variables, some of which might be functions with their own namespaces, and some are hashes that are used as objects or namespaces. We learned that the Nasal code executor looks first at the current namespace for a symbol, then the next higher namespace, until it reaches the top. But what if we define a variable in this scope and we want to access another variable that has the same name but lives in a different namespace? This is what happens in debug.nas; it defines a string function which obscures the string namespace (in computer science this is called [[wikipedia:Variable_shadowing|Variable shadowing]]). To use the string namespace, there are two options: use caller() to manually "hop" up the namespace tree or prefix "globals<nowiki>[dot]</nowiki>" to the symbol like this: | ||
). To use the string namespace, there are two options: use caller() to manually "hop" up the namespace tree or prefix "globals<nowiki>[dot]</nowiki>" to the symbol like this: | |||
<syntaxhighlight lang="nasal"> | <syntaxhighlight lang="nasal"> | ||
globals.string.isascii(n); | globals.string.isascii(n); | ||
edits