Frag Logo
  Frag Home | Frag SF Project   index | contents | previous | next

Commands

Commands are Frag objects on which invocations can be dispatched just by invoking the object name and arguments, but no method name needs to be provided. (Internally, a command object is realized by just implementing one *-dispatcher method (see Section Dispatcher Methods: * and ?) and by having itself as a class.)

Predefined Commands

Some Frag commands are predefined. Examples are set, get, while, for, etc. For example, the invocation:
get a
invokes the object get (because the get object has get as a class). get has a method * defined in Java. Hence this method is invoked. This method then reads the variable a, and the whole invocation returns the variable value.

User-defined Commands

Commands can also be user-defined. Command is a class for defining Command objects in Frag. Each instance of Command has the Command object plus itself (i.e., the instance) as classes. In addition, the instances have a * dispatcher (see Section Dispatcher Methods: * and ?) that is defined via a method cmd. This command method is executed with all arguments given to the command instance, whenever the command is invoked. For reaching other methods of the command -* must be used (see Section Dispatcher Methods: * and ?). The syntax for the cmd method is:
<cmdInstance> cmd <vars> <body>
The following defines a simple Command c, which just returns its argument:
Command create c -cmd {a} {return $a}
Now c can be used just like the predefined commands. For instance, the following returns 1 2 3:
c "1 2 3"
Because the * dispatcher is used to define the Command, we must use -* to send ordinary messages like set or get to c:
c -* set r 1
c -* get r 
The code above returns 1.

  index | contents | previous | next