scScript Defs
scScript supports (compile time) naming of pre-defined constants. For
example, a program can use the following to explicitly name a few:
Def #Monday = 1, #Tuesday = 2; // Integers
Def #Name = "George"; // Strings
Def #Big = 99E20; // Floats
Def #VeryBig = #Big * 2; // Def based on previous Def!!
While the leading # character is not mandatory it is
strongly encouraged. scEmacs will only recognize and
colorize these Def names if they start with #.
Additionally, key names used to access Dict with the dot format are
normally not evaluated. So MyDict.SomeDay is really read
as MyDict["SomeDay"] where the key is taken verbatim
as a small string. But the # starting the key
in MyDict.#Monday will trigger an evaluation, and scScript
(using the Def) will read it as MyDict[1]. Likewise,
MyDict.#Name will be processed
as MyDict["George"].
But beware that the lack of # in
Def HisName = "John";
will result in
MyDict.HisName
being simply read as
MyDict["HisName"].
But MyDict[HisName] will be read
as MyDict["John"] because [...] do evaluate
their contents!
scScript is limited to Def naming of integers, floats, and strings, as these are the only literal types. Importantly, Defs are only for the compiler. The runtime script is blissfully unaware of names, whether Defs, functions, or variables, it only sees values and memory locations. So Defs can be used to help program legibility with no impact whatsoever on runtime performance.
The scope of a Def extends to the end of the lexical {...} block in which it is defined. Any nested sub-blocks can simply inherit and use them. But such a nested sub-block can also re-define an inherited Def and lower-level blocks within it will then see and inherit the re-defined value.
Most packages
(Sys, Ed, Str, Pat,
etc.) will provide their own predefined set of Def constants (often for
flag names). These are accessed with the usual dot package
notation, such as Str.#Zulu, just as pkg functions
(e.g.