Other functions
toString ( <Expr> )
toInt ( <Expr> )
toFloat ( <Expr> )
toString
, as the name implies, converts its argument to a string. It
can be applied to _Integer
_s and _Float
_s. It currently cannot be
applied to _Boolean
_s or any other types.
toInt
and toFloat
work similarly, and on the same three types
only. toInt
will truncate floats (the same behavior as casting in C.)
Note: We’re really sorry about the asymmetry of
toInt
being abbreviated, while none of the others are. That parser was feeling lonely again, and it has a gun.
Example
toString(1)
will return the string
"1"
.
toInt(1.5)
will return the integer
1
.
error ( <Expr> )
error
takes a string argument, and returns any type necessary. It should
be used to produce unexpected errors, as they immediately terminate the program
when evaluated. Do not use this to report semantic errors in an AST; use it
for internal compiler errors.
Example:
if null(something)
then error("unexpected empty list!")
else dosomething(head(something))