Skip to content

Tutorial: Types: NUM DBL TF STR FN CMD

molarmanful edited this page Nov 4, 2023 · 5 revisions

NUM

NUMs in sclin use Spire Reals, 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 NUMs are truthy.

1234
2.512934898123419
.8
$PI

DBL

DBL is sclin's double-precision floating point type. Compared to NUMs, DBLs trade precision for speed, allowing for much faster computations when precision is not a concern.

0 is falsy; all other DBLs are truthy.

When operating on both DBLs and NUMs, NUMs convert to DBLs.

1234D
2.512934898123419D
.8D
$PI D

TF

TF is sclin's Boolean type, primarily used as a return type and when dealing with JSON. TFs 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

STR

Pretty much self-explanatory. Adding a . in front of the string makes it possible to include escape characters.

Empty STR is falsy; all other STRs are truthy.

"Hello, world!"
"escaping quotes: \"how it's done\""
."this is a newline: \n"

You can create multiline STRs 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"

FN

Somewhat analogous to lambdas or anonymous functions in other languages. FNs 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 FNs 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.

FNs are almost identical in behavior to SEQs, except for that fact that FNs don't vectorize.

CMD

CMDs are almost entirely used internally by sclin to distinguish between commands. Documentation of built-in commands is here.

+
map
()

Some CMDs have special functionality when evaluated.

  • CMDs starting with # do nothing.
  • CMDs starting with \ convert to FN; e.g. \map becomes ( map ).
  • CMDs starting with ` begin building multiline strings.
  • CMDs starting with $ and =$ get and set local variables, respectively.
  • CMDs starting with $$ and =$$ get and set global variables, respectively.
  • CMDs containing entirely ()[]{} split into CMDs, with one individual bracket per CMD.

A more subtle thing to keep in mind is that sclin treats CMDs containing ()[]{} as brackets when building FNs. This allows for interactions like )~ in ( 1 1+ )~ to execute properly.

CMD truthiness mirrors that of STR.