-
Notifications
You must be signed in to change notification settings - Fork 1
Tutorial: Types: NUM DBL TF STR FN CMD
NUM
s in sclin use Spire Real
s, allowing for
robust exact and inexact representation of arbitrarily large/precise real
numbers. These numbers maintain exactness for all integer, rational, and even
trigonometric numbers, but become inexact when dealing with irrational roots.
0 is falsy; all other NUM
s are truthy.
1234
2.512934898123419
.8
$PI
DBL
is sclin's double-precision floating point type. Compared to NUM
s,
DBL
s trade precision for speed, allowing for much faster computations when
precision is not a concern.
0 is falsy; all other DBL
s are truthy.
When operating on both DBL
s and NUM
s, NUM
s convert to DBL
s.
1234D
2.512934898123419D
.8D
$PI D
TF
is sclin's Boolean type, primarily used as a return type and when dealing
with JSON. TF
s are perhaps less useful in sclin than in other languages
because each sclin type already has inherent truthiness and falsiness.
$T
and $F
convert to 0
and 1
, respectively.
$T
$F
Pretty much self-explanatory. Adding a .
in front of the string makes it
possible to include escape characters.
Empty STR
is falsy; all other STR
s are truthy.
"Hello, world!"
"escaping quotes: \"how it's done\""
."this is a newline: \n"
You can create multiline STR
s with the help of `
:
``
1 2 3
4 5 6
`
=> "1 2 3\n 4 5 6"
This consumes lines until a line with the specified query matches (in this case,
`
). Another example:
`#a
asdf
qwer
#a "ty"++
=> "asdf\nqwerty"
A quirk of this STR
builder is that the line that matches the query will
execute in full after the STR
constructs. In the above examples, `
and
#a
do nothing, but something like this would still work:
`__
asdf
qwer
__ "ty"++
=> "rewq\nfdsaty"
Somewhat analogous to lambdas or anonymous functions in other languages. FN
s
represent their code as a parsed lazy list; this allows you to manipulated them
in a variety of strange ways seldom found in other languages.
Empty FN
is falsy; all other FN
s are truthy.
( 6+ 5- 4* 3/ )
( "hello " swap ++ )
\map
The lazy list representation makes it possible to have "infinite" functions.
1 ( 1+ dup n>o ) cyc #
sclin can simulate function arguments via ->
or )=
:
( \a -> \a 1+ )
(( a b )= $b $a * )
Each FN
contains data on the file and line number of their creation so that
multi-line/multi-file commands can work properly.
FN
s are almost identical in behavior to SEQ
s, except for that fact that FN
s
don't vectorize.
CMD
s are almost entirely used internally by sclin to distinguish between
commands. Documentation of built-in commands is here.
+
map
()
Some CMD
s have special functionality when evaluated.
-
CMD
s starting with#
do nothing. -
CMD
s starting with\
convert toFN
; e.g.\map
becomes( map )
. -
CMD
s starting with`
begin building multiline strings. -
CMD
s starting with$
and=$
get and set local variables, respectively. -
CMD
s starting with$$
and=$$
get and set global variables, respectively. -
CMD
s containing entirely()[]{}
split intoCMD
s, with one individual bracket perCMD
.
A more subtle thing to keep in mind is that sclin treats CMD
s containing ()[]{}
as brackets when building FN
s. This allows for interactions like )~
in
( 1 1+ )~
to execute properly.
CMD
truthiness mirrors that of STR
.
Made with ❤️ by Ben Pang (@molarmanful).