Skip to content
pheuter edited this page Sep 12, 2010 · 4 revisions

Purpose

Provide means of quick and fun programming on the stack, both client (DOM) and server-side (Node).

Built-ins

Addition

  1 1 +

2

Subtraction

  9 5 -

4

Multiplication

  7 6 *

42

Division

  100 10 /

10

Exponent

  2 6 ^

64

Equality

  10 10 =

t

Comparisons

  2 2 <=

t

  5 6 >

f

Bitwise

  f f and

f

  t f or

t

Output

  5 print

5

  "Hello" println

Hello\n

Drop top from stack

  5 6 drop

5

Drop second to top from stack

  5 7 nip

7

Duplicate top of stack

  13 dup

13 13

Duplicate second to top of stack

  9 10 over

9 10 9

Swap top two entities

  1 2 3 swap

1 3 2

Length of String and Array

  { 1 2 "hello" } length

3

  "Hello, World" length

12

Create Array from range

  1 5 range

{1 2 3 4 5}

Reverse Array or String

  3 7 range reverse

{7 6 5 4 3}

  "racecar" reverse

"racecar"

Call Quotations

  [ 1 1 + ] call

2

Iterate and store in Array

  1 5 range [ dup * ] map

{1 4 9 16 25}

Iterate and push to stack

  {"hello" "world!"} [ length ] each

5 6

Reduce (fold) through an Array

  1 5 range 1 [ * ] reduce

120

Control flow

  144 12 2 ^ = [ "If true" ] [ "If false" ] if

"If true"

Defining functions

  : factorial | 1 swap range 1 [ * ] reduce ;
  5 factorial

120