1.6.19. Evaluate an expression

[<<<] [>>>]

EVALUATEEXPRESSION(x)
_EVALUATEEXPRESSION(x)

Use these macros to evaluate an expression. The argument is the root node of the expression. When a command has a parameter, which is an expression you should write:

  VARIABLE Param;

Param = EVALUATEEXPRESSION(PARAMETERNODE);

Implementing a function or operator you should write

  VARIABLE Param;

Param = EVALUATEEXPRESSION(CAR(PARAMETERLIST));

For further details see examples in the source files commands/let.c, commands/mathops.c.

NOTE:

When an expression is evaluated the returned pointer points to a struct which contains the value of the expression. This is usually a mortal variable which was created during expression evaluation. However in some cases this pointer points to a nonmortal variable. If the expression is a single global or local variable the result of the expression is the pointer to the variable value.

This helps writing for more efficient code. On ther other hand operators tend to convert the operands to long or double in case they expect a long or double but get a different type. The conversions, or other manipulations then change the original variable value, which is a side effect. For this reason the macro EVALUATEEXPRESSION also calls memory_DupMortalize which creates a new variable, and copies the content of the variable passed as argument if the variable is not a mortal.

_EVALUATEEXPRESSION does not do this and therefore you can use it for more efficient memory handling avoiding the creation of unneccesary copies of variables.

If you are not sure whichone to use use the first one without the leading underscore.


[<<<] [>>>]