Empty string: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 998: | Line 998: | ||
=={{header|M2000 Interpreter}}== |
=={{header|M2000 Interpreter}}== |
||
Easy reply for this task |
|||
<lang M2000 Interpreter> |
|||
A$="" |
|||
Print A$<>"", A$="", Len(A$)=0 |
|||
<lang> |
|||
Depends of variable visibility, and what we want to do: To make a new local, to shadow a local or a global on. |
|||
<lang M2000 Interpreter> |
<lang M2000 Interpreter> |
||
⚫ | |||
Module Checkit { |
Module Checkit { |
||
\\ |
|||
\\ Part 1: Make global variable, alter it, make a shadow local or global one, use temporary variable |
|||
⚫ | |||
\\ |
|||
Global a$="ok" |
|||
Module Global What { |
|||
Print a$ |
|||
} |
|||
Module Checkit { |
|||
Print a$="ok" |
|||
a$<="" |
|||
Print a$="" |
|||
a$<="ok2" |
|||
⚫ | |||
Print a$="", a$<>"" |
|||
⚫ | |||
Module Inner { |
|||
Print a$="ok again" |
|||
} |
|||
Inner |
|||
What \\ now What use new global a$ |
|||
\\ display list of public variables |
|||
List |
|||
\\ we can define locals using Def, but raise error if local exist |
|||
Try { |
|||
Def a$="error" |
|||
} |
|||
Def b$ |
|||
Print b$="" |
|||
For This { |
|||
\\ block for temporary definitions |
|||
For i=1 to 10 { |
|||
Local a$=str$(i) |
|||
} |
|||
\\ we get 10 more a$ |
|||
List |
|||
Print a$=" 10" |
|||
} |
|||
Print a$="" |
|||
List |
|||
\\ using current stack |
|||
} |
|||
\\ we call always a local module, or a global, but not this module, |
|||
\\ no recursion for standard call for modules. |
|||
\\ we have to use Call Checkit to call this module recursive |
|||
Checkit |
|||
What \\ now what use old global a$ |
|||
⚫ | |||
List |
|||
\\ |
|||
\\ Part 2: Pass an empty string to a variable through stack of values |
|||
\\ |
|||
Module Checkit2 { |
|||
\\ read make a local by default |
|||
Read a$ |
|||
Print a$="" ' true |
|||
For This { |
|||
Push "Hello" |
|||
Read New a$ |
|||
Print a$="Hello" |
|||
List |
|||
} |
|||
Print a$="" |
|||
} |
|||
Checkit2 "" |
|||
Print a$<>"" ' true |
|||
Module Checkit3 { |
|||
\\ using Set we change to global space, for the end of line |
|||
Set Read a$ |
|||
Print a$="" ' true |
|||
list |
|||
} |
|||
Checkit3 "" |
|||
Print a$<>"" ' true |
|||
Module Checkit4 { |
|||
\\ this make a local if no global exist |
|||
\\ so if global exist, alter the global one |
|||
Let a$=Letter$ |
|||
Print a$="" ' true |
|||
list |
|||
} |
|||
Checkit4 "" |
|||
Print a$="" ' true |
|||
} |
} |
||
Checkit |
Checkit |
||
⚫ | |||
</lang> |
</lang> |
||