SLet/algo
As the interpreter was finished, I am finally able to test and introduce advanced algorithms!
This will also be a tutorial.
Part 1: Basics
Data structures
Number
Simply enough, stores a number, whether it is a decimal or integer.
Pair
Stores 2 values, one "former", one "latter".
Set
The main data type. It is always sorted from small to large.
Commands
Flow control
*
takes 3 arguments, set val op
- For every val in set, execute op.
~
takes 2 arguments, cond op
- While cond is True, do op.
\
takes 1 argument, op
- Directly store op as an instruction instead of executing it.
@
takes 1 argument, op
- Executes op.
Arithmetic
-
and /
takes 1 argument.
- - negates it and / divides 1 by it.
+
takes 3 argument, lvl arg1 arg2
- lvl=0 returns arg1+arg2, lvl=1 does multiplication, lvl=2 does power, and lvl>=2 does Gardner Arrows.
Sets and Pairs
?
takes 3 argument, set val cond.
- For every val in set, if cond is False, waste the item. Returns the rest.
|
and &
takes various arguments, end with !
.
- | does union and & does intersect.
%
takes 2 arguments, former latter
- Makes a pair from the given two.
^
and _
takes 1 argument.
- ^ packs the argument into a set while _ returns the smallest value in a set.
<
and >
takes 1 argument.
- < returns former and > returns latter.
Part 2: Lists
- I feel that I really need to set a section about lists.
Wait... This language has no lists at all?
A list is stored as sets of pairs. In the pair, the former is index and the latter is value.
How to create a list?
Simply enough, just use [
.
[3,5,7,9!
After running that example in the console, you'll see:
= {(0 3),(1 5),(2 7),(3 9)}
How to get a value from a list?
A bit hard though. You first use ?
filter to select the pair, then return its latter value.
>_?list,i,$<i,^index
How to replace a value in a list?
Pop it from the original list and push it back with a completely new value with the same index!
|?list,i,+0,1,-$<i,^index,%index,value!
What about string?
It's a list of ASCII code, just as C++.