external next up previous contents index
Next: Eval Options (by Andy Up: 16.6 Eval Previous: 16.6 Eval

Basic Eval (by Andy Bakun)


Acknowledgment: This text is a formatted version of a message posted to *Teaching on WorldMOO by Andy Bakun.

Eval, a command available to all programmers, is one of the most useful commands on the MOO. What it does is take it's arguments and 'evaluates' them, and returns the result. This has unending usefulness, 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.

will just evaluate the first expression that it gets. It essentially sticks a return command before that expression.

is just like ; except it takes more than one moo statement and doesn't stick a return command in it.. it's return value is dependent on what you chose to return. this is usually used to evaluate multi-line moo programs.

eval-d and it's cousin eval-d ;
runs the code with the d verb bit off, so you won't get a traceback if your eval crashes.

The best way to explain this is with some examples

   => 2
This just returns it's expression (the expression being 2) and is the same thing as a verb with one line of 'return 2;'
   => 7
This is just like 'return 2+5;'

   => 0
This 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;'

  #-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;

next up previous contents index external
Next: Eval Options (by Andy Up: 16.6 Eval Previous: 16.6 Eval

Daniel K. Schneider
Thu Apr 17 12:43:52 MET DST 1997