Words

The words the tutorial uses, with what each does to the values stack. Stacks are written top first, the way programs print them, so ( a b ) means a is on top. In this notation the subject-on-top rule reads left to right: - turns ( a b ) into ( a−b ), and # 3 # 10 - leaves ( 10 3 ) before the subtraction, so it gives 7.

The values stack

wordtakesleaves
dup( a )( a a )
del( a )( )
swap( a b )( b a )
swap2( a b c )( c a b )the third value to the top
debug( a )( )prints a

Numbers and comparisons

wordtakesleaves
# w( )( n )reads the next word w as a whole number
+ - * /( a b )( a+b ) … ( a÷b )# 3 # 10 - is 10 − 3; division drops any fraction
%( a b )( remainder of a÷b )
++ --( a )( a+1 ) ( a−1 )
max min( a b )( larger ) ( smaller )
less-than( a b )( a<b )# 10 # 3 less-than asks whether 3 < 10
greater-than( a b )( a>b )
equals( a b )( a=b )any two objects
true false( )( true ) ( false )
not( a )( not a )
and or( a b )( a and b ) ( a or b )

Lists

wordtakesleaves
{ … }( )( list )the words in between, not run
[ … ]( )( list )the values the words in between push; the first one pushed is the top
call( list )( )runs the list
size( list )( n )also counts the bytes of text
peek( list )( first )
pop( list )( first rest )
push( list v )( list with v first )a stack changes in place; a tuple gives a new tuple
reversed sort( list )( list′ )
append( b a )( a then b ){ a b } { c d } append is ( "a" "b" "c" "d" )
stack tuple( )( empty list )thawed, frozen
freeze( thawed )( frozen copy )
clone( a )( copy of a )
inspect( a )( a )prints what a is

Names

wordtakesleaves
= w( v )( )binds w to push v
=> w( list )( )binds w to run the list, looking names up when it runs
=: w( list )( )binds w to run the list in the macro table as it is now
\ w( )( w )pushes the next word without running it
macros( )( table )the macro table
scope( list )( )runs the list, then restores the macro table

Decisions and loops

wordtakesleaves
if unless( list b )( )runs the list when b is true (if) or false (unless)
either( else then b )( )b { then } { else } either
while until( body cond )( ){ cond } { body } while; until stops when cond is true
foreach( body list )( )pushes each element, first first, and runs body
map( body list )( list′ )collects the top value each turn leaves
loop( list )( )forever
terminate( )( )ends the process

Tables

wordtakesleaves
tree array( )( empty table )thawed, frozen
pair( key value )( (key value) )# 3 \ apples pair
unpair( (key value) )( key value )
table( list of pairs )( table )
get( table key )( value )an error if the key is missing
has( table key )( b )
set( table pair )( table′ )a tree changes in place
remove( table key )( table′ )
keys( table )( list )in no particular order

Text

wordtakesleaves
" … "( )( text )the words in between joined by single spaces; \n \t \s
words( text )( list )
split( text sep )( list )
join( list sep )( text )
find( text part )( list of offsets )
string( a )( text )
integer( text )( n )
rom( list of texts )( text )

Errors

wordtakesleaves
exception( message )( exception )
throw( exception )runs the handler, or ends the program
trust( handler body ){ body } { handler } trust; the handler starts with the exception on top

Processes

wordtakesleaves
process( )( table )keys v i m h
queue( )( (output input) )queue unpair = out = in
send( output message )( )the message is copied
receive( input )( message )waits for one
poll( input )( false ) or ( true message )
fork( list of lists )( )all but the last run in copies; each goes on with the rest of the program

Under the hood

wordtakesleaves
evade( list )( w )pops the next instruction w, runs the list after it

Every word Ether defines is in its macro table: macros keys lists them.