Exploring context and globals with Nu
Global name definitions are put into the symbol table; that is
slightly more efficient than normal assignments (such as those made
with the set, macro, and function operators), which are kept in
NSDictionaries. It also makes them easier to use in Nu code that is
called from Objective-C without specifying a context, which you can do
by sending the evalWithContext: message to a parsed code object with a
nil argument. Usually that happens in Objective-C, but since you can
send nearly any ObjC message from Nu, here's a little demo in nush
[ed: I expanded it to show more information]:
$ nush Nu Shell. % (parse "(puts 22)") (progn (puts 22)) % (set prog (parse "(puts 22)")) (progn (puts 22)) % (prog class) NuCell % (set progx (parse "(puts x)")) (progn (puts x)) % (progx class) NuCell % (set x 23) 23 % (x class) NSCFNumber % (eval progx) 23 () % (prog evalWithContext: nil) 22 () % (progx evalWithContext: nil) NuUndefinedSymbol: undefined symbol: x % (progx evalWithContext: (context)) 23 () % (global x 50) 50 % (progx evalWithContext: (context)) 23 () % (progx evalWithContext: nil) 50 ()