fish operator command

Syntax

fish operator s ...

Define a new FISH operator. An operator is a special class of FISH function that is designed to be safe to use in a multi-threaded environment.

The operator will be named s, and must be a valid symbol name. Tokens following are assumed to be arguments that the function will take. Please see FISH Scripting Reference, and specifically Operators: Multi-threaded function support.

From here until an end statement is found, FISH syntax is expected instead of standard command processing. The FISH code is parsed into a compressed format called pseudo-code, which is what is executed by the FISH runtime. Compilation errors are reported as the statements are processed.

The pseudo-code is considered part of the model state, and so is cleared on a model new, saved with model save, and recovered with model restore.

The function s will be created as a global symbol if one does not already exist. If it already exists then it will be tagged as a function and the code will be executed whenever values are retrieved from it. Any function already defined on s will be deleted and overwritten.

Usage Example

The following example illustrates how fish operator can be used.

To define a simple FISH operator fred that returns the x-component of a data scalar pointer:

fish operator fred(scalar)
    return data.scalar.pos(scalar)->x
end

To define a FISH operator that adds a value to the x-component of a data scalar pointer

fish operator george(scalar,a)
    data.scalar.pos(scalar)->x += a
end