RosettaCodeData/Task/Empty-string/M2000-Interpreter/empty-string-2.m2000

87 lines
2.4 KiB
Plaintext

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"
a$=""
Print a$="", a$<>""
Global a$="ok again"
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$
Print a$<>"" ' true
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