|
NAMEklel-expr - Compile and execute a KL-EL expressionSYNOPSISklel-expr [{-d|--debug-output}] {-e|--expression} expressionklel-expr {-v|--version} Note: Command line arguments are position dependent, and argument snuggling (e.g., '-de') is not supported. All arguments and their values (if any) must be separated by whitespace. DESCRIPTIONklel-expr executes a single KL-EL expression (see klellang(3)) and displays its result. User-provided expressions have full access to the variables and functions exported by KL-EL standard library (see klelstdlib(3)).Executing Value Expressionsklel-expr will execute a value expression (see klellang(3)) by calculating its value and displaying the result.Executing Guarded Commandsklel-expr will execute a guarded command (see klellang(3)) by testing the guard. If the guard succeeds (i.e., evaluates to Boolean true), the command is executed using the specified interpreter, which can be one of echo or system.The echo interpreter takes an arbitrary number of string arguments and echos them back to the display separated by whitespace. The system interpereter takes a single string argument, passes that string unchanged to system(3), and displays the output (if any) of the executed command. MODES OF OPERATIONThe modes of operation described in this section are mutually exclusive. In other words, only one mode may be specified per invocation.
OPTIONS
RETURN VALUESUpon successful completion, a value of 0 (XER_OK) is returned. Otherwise, one of the following error codes is returned:
EXAMPLESThe following examples are intended to demonstrate different ways of invoking klel-expr. Lines prefixed with $ indicate user input within a Bourne or Bourne-like shell.Example 1. A simple expression.In this example, a simple arithmetic expression is evaluated.$ klel-expr -e '1 + 2' 3 When you run the command shown above, klel-expr will compile the expression, evaluate it, and then print out the result ('3'). Note that the quotes around the expression are required since klel-expr accepts only a single expression argument. Example 2. A simple expression with debug output.In this example, another arithmetic expression is evaluated. More importantly, the debug-output option is exercised.$ klel-expr -d -e '2 * pi + 7 / 42 + entier(299.398)' KlelType='value expression' KlelExpr='((2 * pi) + 7 / 42) + entier(299.398)' KlelExprName='expr(00003e7b)' KlelExprStatus='pass' KlelExprType='real' KlelExprOutput=<<EndOfOutput 305.283 EndOfOutput When you run the command shown above, klel-expr will compile the expression, evaluate it, and then print out the result (305.283) along with additional data that are useful for debugging and/or informational purposes. Example 3. Executing a guarded command.In this example, a guarded command is evaluated and conditionally executed using system(3).$ klel-expr -e 'if (true) then eval("system", "echo -n GIGO | sum")' 41101 1 When you run the command shown above, klel-expr will compile the expression, evaluate it, and conditionally execute the guarded command ('echo -n GIGO | sum'). Since the expression always evaluates to true, the guarded command will always be executed. Note that klel-expr supports two interpreters, system and echo. The system interpreter takes one argument (a string) and passes it to system(3). The echo interpreter takes an arbitrary number of arguments (the first of which must be a literal string) and echos them to the standard output. Example 4. Executing a named expression.In this example, a named expression is evaluated.$ klel-expr -e 'my_expression : 1 + 2.1' 3.1 When you run the command shown above, klel-expr will compile the expression, evaluate it, and then print out the result (3.1). Example 5. Using let and variable interpolation.In this example, a simple expression involving the use of let and variable interpolation is evaluated.$ klel-expr -e 'let t = now() in odd(t) ? "%{t} --> odd" : "%{t} --> even"' 1353099233 --> odd When you run the command shown above, klel-expr will compile the expression, evaluate it, and then print out the result. Note how the variable t is expressed as '%{t}' in the ternary, which allows its value to be interpolated to produce the resulting string value. SEE ALSOklelapi(3), klellang(3), klelstdlib(3), kleltut(3)
Visit the GSP FreeBSD Man Page Interface. |