Remaining interpreter commands.
The commands described here enable you to:
For complicated simulations it is better to store your interpreter commands, at least those defining the simulation connectivity, in a file rather than typing them into the interpreter directly. This way you can run your favorite editor in one window and run the interpreter in another window, easily modifying the simulation and also keeping a permanent record. Two exceptions to this are changing parameters using the setparam command and running and continuing the simulation using run and cont, this is normally done interactively with the interpreter.
reads interpreter commands from the given filename, until the end of the file or until an error occurs. The # character indicates that the rest of the line is a comment. By convention, files meant to be read by the execute command should have the extension .ptcl
Using the tilde notation (˜) for home directories is allowed within filenames.
The seed command changes the seed of the random number generation. The default value is 1. The syntax is
where n is an unsigned integer. If the argument is omitted the command seed returns the current seed.
The cd command changes the current directory. The syntax is:
where name specifies the directory. If the argument is omitted the command cd changes the current directory to the user's home directory.
To see what the interpreters current directory is, you can type
The interpreter has the ability to extend itself by linking in outside object files. The object files in question must define single primitives, they will have the right format if they are produced from preprocessor input. Unlike using MLDesigner's graphical interface, the interpreter will not automatically run the preprocessor and compiler. It expects to be given object files that have already been compiled. The syntax is
Building object files for linking into MLDesigner can be tricky since the command line arguments to produce the object file depend on the operating system, the compiler, and whether or not shared libraries are used. $MLD/mk/primitive.mk includes rules to build the proper object file for a primitive.
It is also possible to link in several object files at once, or pull in functions from libraries by use of the multilink command. The syntax is
multilink <opt1> <opt2> <opt3> ...
where the options may be the names of object files or linker options such as -L or -l switches, etc. These arguments are supplied to the Unix linker along with whatever options are needed to completely specify the incremental link.
When the above linker commands are used, the linked code has temporary status. Symbols for it are not entered into the symbol table, meaning that the code cannot be linked against by future incremental links, and it can be replaced, for example, an error in the loaded modules could be corrected and the link or multilink command could be repeated. There is an alternative linking command that specifies that the new code is to be considered permanent. It causes a new symbol table to be produced for use in future links. See the Ptolemy language keyword derivedFrom item in the MLDesigner Programming Guide for more information. Such code cannot be replaced, but it can be linked against by future incremental link commands. The syntax is
permlink <opt1> <opt2> <opt3> ...
where the options are the same as for the multilink command.
returns the list of top-level blocks in the named block, or in the current module or system, if the argument is omitted.
The paramvalue command takes the form
paramvalue <block> <parameter> [<current|initial>]
and returns the current value of the parameter within the block. The command takes an optional third argument, which may be either current to specify that the current value should be returned (the default), or initial to specify that the initial value (the parameter value) should be returned.
The exit command exits the interpreter. The syntax is
The help command implements a simple help system describing the commands available and their syntax. It does not provide help for the standard Tcl functions. The syntax is
for a list of topics. If the argument is omitted, a short "help on help" is printed.
It is possible to associate a Tcl action with the firing of any primitive. The registerAction command does this. The syntax is
registerAction <pre|post> command
The first argument specifies whether the action should occur before or after the firing of a primitive. The second argument is a string giving the first part of a tcl command. Before this command is invoked, the name of the primitive that triggered the action will be appended as an argument. For example:
registerAction pre puts
will result in the name of a primitive being printed on the standard output before it is fired. A typical action resulting from this command would be
The value returned by registerAction is an action_handle, which must be used to cancel the action using cancelAction. The syntax is:
set action_handle [registerAction pre tcl_command]