Please enable JavaScript to view this site.

A-Shell Consolidated Reference

ADDED February 2019

NUMEXPR(expr) is the mirror image of STREXPR$(expr). It tells the compiler to expect and treat the argument expression as a numeric expression. This may seem similar to the VAL(x) function but differs in important ways.

VAL() is designed to convert a string value (variable or expression) to a number. If given an expression for an argument, it expects the expression to be a string expression, which means that it will intepret any + operator as concatenation, and will convert any numeric operands to string. Only after the expression argument is fully evaluated (as a string) does it get converted to a numeric value.

NUMEXPR(expr) expects the argument to be a numeric expression, which means that it will interpret any + operator as addition, and will convert any string operands to numbers. Since the resulting expression will be a numeric value, there is no need for a final conversion. Examples:

map1 x,f,6

map1 y,b,2

map1 z,f,6

map1 a$,s,10

map1 b$,s,10

 

x = y + z                ! addition

x = numexpr(y + z)       ! same; numexpr() has no effect here

a$ = y + z               ! concatenation (due to string target)

a$ = numexpr(y + z)      ! addition

x = a$ + b$              ! addition; same as val(a$) + val(b$)

x = numexpr(a$ + b$)     ! addition; same as above

x = val(a$ + b$)         ! concatenation; (val expects a string argument)

x = str$(a$ + b$)        ! addition(!); same as val(a$) + val(b$)

fn'foo(a$ + b$)          ! concatenation; (a$ sets string mode here)

fn'foo(numexpr(a$ + b$)) ! addition 

 

NUMEXPR(expr) is particularly useful when working with DYNSTRUCT members, since they are always treated by the compiler as strings, possibly causing intended addition operations to be compiled as concatenation. In fact, the compiler will now treat any expression involving a dynstruct.member and the + operator as an error, unless one of the casting functions NUMEXPR(expr) or STREXPR$(expr) is used.

See Also

History

2019 February, A-Shell 6.5.1654, compiler edit 890:  Added to A-Shell.