INT
, FLOAT
, STR
, LIST
, OBJ
, or ERR
.
Thus, one usually writes code like this:
if (typeof(x) == LIST) ...
and not like this:
if (typeof(x) == 3) ...
because the former is much more readable than the latter.
tostr(17) => "17" tostr(1.0/3.0) => "0.333333333333333" tostr(#17) => "#17" tostr("foo") => "foo" tostr({1, 2}) => "{list}" tostr(E_PERM) => "Permission denied" tostr("3 + 4 = ", 3 + 4) => "3 + 4 = 7"
Note that tostr()
does not do a good job of converting lists into
strings; all lists, including the empty list, are converted into the string
"{list}"
. The function toliteral()
, below, is better for this
purpose.
toliteral(17) => "17" toliteral(1.0/3.0) => "0.333333333333333" toliteral(#17) => "#17" toliteral("foo") => "\"foo\"" toliteral({1, 2}) => "{1, 2}" toliteral(E_PERM) => "E_PERM"
<=
as the errors themselves. Toint()
raises
E_TYPE
if value is a list. If value is a string but the
string does not contain a syntactically-correct number, then toint()
returns 0.
toint(34.7) => 34 toint(-34.7) => -34 toint(#34) => 34 toint("34") => 34 toint("34.7") => 34 toint(" - 34 ") => -34 toint(E_TYPE) => 1
toint()
except
that for strings, the number may be preceded by `#'.
toobj("34") => #34 toobj("#34") => #34 toobj("foo") => #0 toobj({1, 2}) error--> E_TYPE
toint()
and then converted as integers are. Tofloat()
raises
E_TYPE
if value is a list. If value is a string but the
string does not contain a syntactically-correct number, then tofloat()
returns 0.
tofloat(34) => 34.0 tofloat(#34) => 34.0 tofloat("34") => 34.0 tofloat("34.7") => 34.7 tofloat(E_TYPE) => 1.0
value1 == value2
"
except that, unlike ==
, the equal()
function does not treat
upper- and lower-case characters in strings as equal.
"Foo" == "foo" => 1 equal("Foo", "foo") => 0 equal("Foo", "Foo") => 1
string_hash(toliteral(value))
; see the
description of string_hash()
for details.