Please enable JavaScript to view this site.

A-Shell Reference

Added February 2019

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

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

STREXPR$(expr) expects the argument to be a string expression, which means that it will interpret any + operator as concatenation, and will convert any numeric operands to strings. Since the resulting expression will be a string 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 = strexpr$(y + z)      ! concatenation; same as str$(y) + str$(z) (sum then converted to string)

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

a$ = strexpr$(y + z)     ! same; strexpr$() here has no effect

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

x = strexpr(a$ + b$)     ! concatenation; result then converted to string

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

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

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

fn'foo(strexpr$(x + y))  ! concatenation

 

STREXPR$(expr) is particularly useful when working with DYNSTRUCT members where the compiler is unable to determine at compile time the ultimate type of the member when it is bound at run time. Use of the casting functions eliminates the possible confusion and resulting logical errors of mistaking addition for concatenation or vice versa.

See Also

History

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