SliP is a programmable symbolic calculator. You can use it as a normal calculator, then keep the same session and define variables and small functions when you need more.
Language reference: SPEC (operators, tokens, modes).
2π 'r = 2 2πr cosπThe second line stores
r in the current session. Later lines can use it until you press Reset context or reload the page.
If typing the symbols is awkward, these ASCII aliases are also available:
pi // same as π euler // same as 𝑒 inf // same as ∞
2+3in the Source Area. You can do this either from the keyboard or from the keypad. Press the CALCULATE button and you will see the value 5 in the Result Area.
2-3under the formula above. Then press the CALCULATE button and you will see a value of -1 in the Result Area.
2×3under the above formula. You can also enter the multiplication symbol × from the keypad by pressing * on the keyboard if the '* → ×' checkbox in the Option Area is checked. If you press the CALCULATE button, you will see the value 6 in the Result Area.
2÷3under the formula above. The division symbol ÷ can be easily entered from the keypad, or by pressing / on the keyboard if the '/ → ÷' checkbox in the Option Area is checked. If you press the CALCULATE button, you will see the value 0.6666... in the Result Area.
2 × 3 ÷ (4+5-6)Pressing the CALCULATE button will calculate (4+5-6) first and this expression will be equal to 2×3÷3 and the value 2 will be displayed.
2 3 4Pressing the CALCULATE button will make this expression equal 2 × 3 × 4 and display the value 24.
+ means the next number as it is - means negative of the next number 3-+2 is evaluated as 1 3--2 is evaluated as 5 3-(-2) is also evaluated as 5
π // PI; ASCII alias: pi 𝑒 // Napier number; ASCII alias: euler ∞ // Infinity; ASCII alias: infASCII
e is a normal name, not Napier's number.
'r = 2Now let's enter the following equation
2 × π × rPressing the CALCULATE button displays the value 12.566370614359172, which is the circumference of a circle of radius 2. This equation can also be made to look like the following using the abbreviation of the multiplication operator above.
2πrThe names of the variables are actually a bit complicated, but they generally look like the following. Basically, it starts with a letter, followed by repeating letters or numbers, and ends with a space. For example
abc na12meThese names have not yet been defined and will result in 'undefined' error. Greek letters and ∞ are used with only one letter. For example, abπcd∞ef is five names: ab, π, cd, ∞, and ef.
cosπPressing the CALCULATE button displays the value -1. The arithmetic functions atan2, pow, hypot, max, and min require two or more parameters. You can pass parameters to them in an array.
atan2[ 1 1 ] // → 0.7853981633974483 pow[ 2 3 ] // → 8 hypot[ 3 4 ] // → 5 max[ 3 2 1 ] // → 3 min[ 3 2 1 ] // → 1
¤ random[ 1 2 ]
3 // → 3 "abc" // → "abc" × // → ×A list of SliP objects enclosed in parentheses is a sentence, and when evaluated, various calculations are performed according to the operators in the sentence. First, let's look at a function that returns the value of its argument multiplied by two as an example.
( 'mul2 = '( @ × 2 ) )The meaning of this sentence is to assign the expression '( @ × 2 )' to the name 'mul2'. ' is called 'quote' and when evaluated returns the next SliP object without evaluation. '@' denotes an argument. Let's use the function we just defined named mul2.
( 3 : mul2 ) // → 6Name returns the assigned SliP object when evaluated. In this case, the expression is ( @ × 2 ). : is an infix operator. It evaluates the right side (R) with the left side (L) as the stack-top argument
@.
( 'factorial = '(
@ == 0 ?
[ 1
( @ × ( @ - 1 ):factorial )
]
) )
( 4 : factorial ) // → 24
"This is `STRING` enclosed in \"" // → "This is `STRING` enclosed in "" `This is "STRING" enclosed in \`` // → `This is "STRING" enclosed in ``
( 'json = `{
"a" : 1
, "b" : "The String"
, "c" : [ 2, "Another string" ]
, "d" : {
"A" : 3
, "B" : [ 4, "Yet another string" ]
}
}`:byJSON
)
// → { a : 1 , b : "The String" ...
( json:"d" )
// → { A : 3 , B : [ 4 "Yet another string" ] }
( json:'d )
// → { A : 3 , B : [ 4 "Yet another string" ] }
{ ( 'a = 2 )
( 'b = 3 )
( a + b )
}
// → [ 2 3 5 ]
« ( 'a = 2 )
( 'b = 3 )
( a + b )
»
// → [ 2 3 5 ]
¶
// → {}
{ ( 'a = 2 )
( 'b = 3 )
( a + b )
}
// → [ 2 3 5 ]
¶
// → {}
« ( 'a = 2 )
( 'b = 3 )
( a + b )
»
// → [ 2 3 5 ]
¶
// → { a : 2 , b : 3 }
After a «» block, new bindings remain in the current context. After { }, bindings made inside the block are not visible outside (unless captured otherwise).