GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
KLEL-EXPR(1) libklel KLEL-EXPR(1)

klel-expr - Compile and execute a KL-EL expression

klel-expr [{-d|--debug-output}] {-e|--expression} expression

klel-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.

klel-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)).

klel-expr will execute a value expression (see klellang(3)) by calculating its value and displaying the result.

klel-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.

The modes of operation described in this section are mutually exclusive. In other words, only one mode may be specified per invocation.
{-e|--expression} expression
Compile and execute the specified expression.
{-v|--version}
Display version information and exit.

{-d|--debug-output}
Print additional debug output during program execution.

Upon successful completion, a value of 0 (XER_OK) is returned. Otherwise, one of the following error codes is returned:
  • 1 = XER_Usage
  • 2 = XER_Setup
  • 3 = XER_Out_Of_Memory
  • 4 = XER_Execute
  • 5 = XER_GuardedCommand

The 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.

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.

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.

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.

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).

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.

klelapi(3), klellang(3), klelstdlib(3), kleltut(3)
2022-04-08 1.1.0

Search for    or go to Top of page |  Section 1 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.