Next: , Previous: , Up: Arithmetic expressions   [Contents][Index]

Evaluation contexts

Evaluation contexts

coNCePTuaL normally evaluates arithmetic expressions in “integer context”, meaning that each subexpression is truncated to the nearest integer after being evaluated. Hence, ‘24/5*5’ is ‘20’, not ‘24’, because ‘24/5*5’ =(24/5)*5’ =4*5’ =20’. There are a few situations, however, in which coNCePTuaL evaluates expressions in “floating-point context”, meaning that no truncation occurs:

Within any of the preceding statements, the expression ‘24/5*5’ evaluates to 24. Furthermore, the expression ‘24/5’ evaluates to 4.8, which is a number that can’t be entered directly in a coNCePTuaL program. (The language supports only integral constants, as mentioned in Primitives.)

The coNCePTuaL language provides a special form called REAL, which resembles a single-argument function. When evaluated in floating-point context, REAL returns its argument evaluated normally, as if ‘REAL’ were absent. When evaluated in integer context, however, REAL evalutes its argument in floating-point context and then rounds the result to the nearest integer. For example, in integer context, ‘9/2 + 1/2’ is ‘4’ while ‘REAL(9/2 + 1/2)’ is ‘5’.

Scott Pakin,