Acknowledgement: This text is a formatted version of a message posted to *Teaching on WorldMOO by Thwarted Efforts.
Eval, a command avaiable to all programmers, is one of the most useful commands on the MOO. What it does is take it's arguments and 'evaulates' them, and returns the result. This has unending usefullness, from setting property values, to examining something in the database, to testing code fragments.
A short form of eval is the semicolon (;)
There are a few forms of the eval command, ;, ;;, and eval-d.
;2 => 2This just returns it's expression (the expression being 2) and is the same thing as a verb with one line of 'return 2;'
;2+5 => 7This is just like 'return 2+5;'
;;2+5 => 0This is just like the code '2+5;' No return value is generated (0 is the default return value).
;;return 2+5 => 7
This is the code 'return 2+5;'
;length(1) #-1:Input to EVAL, line 13: Type mismatch
This eval is just like 'return length(1);' and since length(1) is an invalid expression, and returns E_TYPE, the eval tracebacks.
eval-d length(1) => E_TYPE (Type mismatch)
This is just like 'return length(1);' but run with the d bit unset, so length() doesn't cause it to traceback, it just returns the error value
;for x in (players()) if (x == #1353) return x; endif endfor => #1353 (ThwartedEfforts)This is just like the verb code:
program ..:.. for x in (players()) if (x == #1353) return x; endif endfor