Skip site navigation (1)Skip section navigation (2)

  
 
  

home | help
KLEL-EXPR(1)			     libklel			    KLEL-EXPR(1)

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

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

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

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

   Executing Guarded Commands
     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 com-
     mand 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 OPERATION
     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.

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

RETURN VALUES
     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

EXAMPLES
     The following examples are intended to demonstrate different ways of invok-
     ing 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 expres-
     sion, evaluate it, and then print out the result ('3').

     Note that the quotes around the expression are required since klel-expr ac-
     cepts only a single expression argument.

   Example 2. A simple expression with debug output.
     In this example, another arithmetic expression is evaluated.  More impor-
     tantly, 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 expres-
     sion, evaluate it, and then print out the result (305.283) along with addi-
     tional 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 expres-
     sion, 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 expres-
     sion, 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 expres-
     sion, 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 ALSO
     klelapi(3), klellang(3), klelstdlib(3), kleltut(3)

1.1.0				   2026-08-27			    KLEL-EXPR(1)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=klel-expr&sektion=1&manpath=FreeBSD+Ports+15.1.quarterly>

home | help