F♭ (pronounced F-flat) is a toy language.
@
(at)returns the item at the specified index/key
seq x -> a
f♭> [ 1 2 3 ] 1 @
[ 2 ]
f♭> [ 1 2 3 ] -1 @
[ 3 ]
f♭> 'abc' 2 @
[ 'c' ]
f♭> [ 1 2 3 ] 1 @
[ 2 ]
f♭> 3.14159 2 @
[ 4 ]
f♭> { first: 'Manfred' last: 'von Thun' } 'first' @
[ 'Manfred' ]
choose
conditional (ternary) operator
bool a b -> c
f♭> true 1 2 choose
[ 1 ]
q<
moves the top of the stack to the tail of the queue
a ->
f♭> 1 2 4 q< 3
[ 1 2 3 4 ]
q>
moves the tail of the queue to the top of the stack
-> a
f♭> 1 2 q> 4 3
[ 1 2 3 4 ]
stack
replaces the stack with a quote containing the current stack
`a* -> [ a* ] )
f♭> 1 2 3 stack
[ [ 1 2 3 ] ]
unstack
push items in a quote to the stack without evaluation
[ A* ] -> A*
f♭> [ 1 2 * ] unstack
[ 1 2 * ]
clr
clears the stack
a* ->
f♭> 1 2 3 clr
[ ]
depth
pushes the size of the current stack (number of items on the stack)
-> x
f♭> 0 1 2 depth
[ 0 1 2 3 ]
eval
evaluate quote or string
[A*] -> a*
f♭> [ 1 2 * ] eval
[ 2 ]
in
evalues the quote in a child environment
[A*] -> [a*]
f♭> [ 1 2 * ] in
[ [ 2 ] ]
in-catch
Evaluates the quotation in a child environment calls the second quotation in a child throws an error
[A*] [B*] -> [ {a*|b*} ]
throw
Throws an error
str ->
f♭> 'PC LOAD LETTER' throw
[ ]
send
pushes one element from stack to parent.
a ->
f♭> [ 1 2 3 send 4 ] in
[ 3 [ 1 2 4 ] ]
drop
drops the item on the bottom of the stack
a ->
> 1 2 3 drop
[ 1 2 ]
swap
swaps the items on the bottom of the stack
a b -> b c
> 1 2 3 swap
[ 1 3 2 ]
dup
duplicates the item on the bottom of the stack
a -> a a
> 1 2 3 dup
[ 1 2 3 3 ]
indexof
returns the position of the first occurrence of a specified value in a sequence
[a*] b -> x
f♭> [ '1' '2' '3' '4' ] '2' indexof
[ 1 ]
zip
[A*] [B*] -> [C*]
f♭> [ 1 2 3 ] [ 4 5 6 ] zip
[ 1 4 2 5 3 6 ]
zipinto
[A*] [B*] [C*] -> [D*]
f♭> [ 1 2 3 ] [ 4 5 6 ] [ 7 8 9 ] zipinto
[ [ 1 4 7 8 9 2 5 7 8 9 3 6 7 8 9 ] ]
(
(immediate quote)pushes a quotation maker onto the stack
-> #(
)
(immediate dequote)collects stack items upto the last quote marker
#( a -> [ a ]
[
(lazy quote)pushes a quotation maker onto the stack, increments depth
-> #(
]
(lazy dequote)decrements depth, collects stack items upto the last quote marker
#( A* -> [ A* ]
{
(immediate object quote)pushes a quotation marker onto the stack
-> #(
}
(immediate object dequote)collects stack items upto the last quote marker, converts to an object
#( a* -> { A* }
template
converts a string to a string template
str -> [A*]
f♭> 'hello $(world)' template
[ [ '' 'hello ' + '(world)' eval string + '' + ] ]
sleep
wait x milliseconds
x ->
undo
restores the stack to state before previous eval
str a -> bool
Matches a string a regex and returns an array containing the results of that search.
=~
a b -> bool
Returns a Boolean value that indicates whether or not the lhs matches the rhs.
_
-> #_
Match symbol