-
Notifications
You must be signed in to change notification settings - Fork 0
Command reference
When I say Func-like, I mean either a lambda ({...:...}) or a func ([...]).
When it is said that a function vectorizes, it means it performs the operation described element-wise, optionally to a specified side. For example, + is said to vectorize across both sides, and get is said to vectorize across the right side. Visually:
(* `+` vectorizes over left and right sides *)
(1 2 3 4) 1 + (* is equal to `(2 3 4 5)` *)
(1 2 3) (2 3 4) + (* is equal to `(3 5 7)` *)
1 (1 2 3) + (* is equal to `(2 3 4 5)` *)
1 3 + (* is equal to `4` *)
(* `get` vectorizes over the right side only *)
(1 2 3 4) 0 get (* is equal to `1` *)
(1 2 3 4) (0 1) get (* is equal to `(1 2)` *)
For convenience, if a function has arity 1, its argument is referred to as n, and this function is said to be monadic. If a function has arity 2, its first argument is said to be x and its second argument to be y, and is said to to be dyadic. (Note: y is found at the top of the stack; like x y op.) A monadic function that takes a function and yields a function is said to be an adverb, and its argument is called f.
As for types, a func-like is one of Lambda and Func; type[] is an array of that type (e.g. Decimal[] is an array of decimals).
[~] denotes that the types can be swapped (arguments are swapped accordingly).
| Command | Arity | Type | Vectorizes? | Effect | Examples |
|---|---|---|---|---|---|
! |
1 | Decimal | Yes | Factorial; multiplies n by all numbers from 1 to floor(n). |
3!6
|
! |
1 | Func-like | No | Executes a function; alias for exec. |
3 [1+] !4
|
!= |
2 | Any, Any | No | Yields non-equality of arguments. | |
" |
1 | Func-like | No | Vectorizes f; alias for oneach. |
{ a : a 3 = }" @:foo (1 2 3 4 5) foo(0 0 1 0 0)
|
# |
2 | Any, Any | Yes (right) | Obtains member y from x. For arrays, this is equivalent to getting the yth member. |
(1 2 3) 1 #2 ALPHA 9 get'J'
|
#! |
1 | Func-like[] | n/a | Yields a function that applies each monad f_k of F to the argument; alias for execeach. |
(sqrt square) #! @:t4 t(2 16)
|
## |
2 | Any, Any | Yes (right) | Obtains member k from x, for which k = y mod (size x). |
(1 2 3) 4 ##2
|
#$ |
2 | Any, Any | No | Forms x in the shape of y; alias for SHAPE. |
(4 4) (1 2 3) #$((1 2 3 1) |
#& |
1 | Any | No | Fixes the shape of n; alias for fixshape. |
((1 2 3) (4) (5 6)) #&((1 2 3) |
#, |
2 | Any, Any | No | The array (x y); alias for pair. |
3 (4) #,(3 (4))
|
#. |
1 | String | Yes | Gives the UTF-8 codepoint of the first character of n. |
('a' 'b') #.(97 98)
|
#/ |
1 | Func-like | No | Yields a function that reduces f over the argument. |
$+ #/ @:SUM(1 2 3) SUM6
|
#: |
1 | Decimal | Yes | Gives the UTF-8 character with codepoint n. |
(97 98) #:('a' 'b')
|
#> |
2 | Decimal, Decimal | Yes | Range from x to x + y, inclusive. |
2 4 #>(2 3 4 5 6)
|
#\ |
1 | Func-like | Yes | Equivalent to #\ !. |
(1 2 3 4) $+ #\10
|
#` |
1 | Iterable, String | Yes (right) | Equivalent to join. |
'asdf' ' ' #`'a s d f'
|
#~ |
1 | String | Yes | Equivalent to eval. |
'3 4 +' #~7
|
% |
2 | Decimal, Decimal | Yes | Modulus function |
(_3 _2 _1 0 1 2 3) 2 %(_1 0 _1 0 1 0 1)
|
%% |
2 | Decimal, Decimal | Yes | Modulus function (strictly positive) |
(_3 _2 _1 0 1 2 3) 2 %%(1 0 1 0 1 0 1)
|
* |
2 | Decimal, Decimal | Yes | Multiplication |
3 (4 5 6) *(12 15 18)
|
* |
2 | [~] String, Decimal | Yes | String repetition |
3 'Hi' *'HiHiHi'
|
* |
2 | [~] Func-like, Decimal | Yes | Applies x y times. |
3 [1+] 4*7
|
+ |
2 | Decimal, Decimal | Yes | Addition |
3 (1 2 3) +(4 5 6)
|
+ |
2 | String, String | Yes | String concatenation |
'He' 'llo' +'Hello'
|
+ |
2 | Func-like, Func-like | Yes | Applies x then y. |
2 $square $double + !8
|
++ |
2 | Iterable, Iterable | No | Concatenation. |
(1 2 3) (4 5 6) ++(1 2 3 4 5 6)
|
++ |
2 | Func-like, Func-like | No | Equivalent to \+. |
3 [1+] [2*] ++ !7
|
, |
2 | Any, Any | No | Like ++, but doesn't complain about types. |
3 (4) ,(3 4)
|
- |
2 | Decimal, Decimal | Yes | Subtraction. |
5 (1 2 3) -(4 3 2)
|
- |
2 | String, String | Yes | Removes all (Regex) instances of y from x. |
'Hello' 'l+' -'Heo'
|
.. |
2 | Decimal, Decimal | Yes | Range from x to y, right-exclusive. |
3 6 ..(3 4 5)
|
... |
1 | Any[] | No | Merges the contents of n into the stack. |
1 2 (4 5) ...Stack: (1 2 4 5)
|
... |
1 | Any | No | No-op. |
3 'hi' ...Stack: (3 'hi')
|
/ |
2 | Decimal, Decimal | Yes | Division. |
4 (1 2 4) /(4 2 1)
|
/ |
2 | String, String | Yes | Removes all instances of y from x. |
'3 + 4' ' + ' /'34'
|
: |
n/a | n/a | Duplicate the top of the stack. |
3 :Stack: (3 3)
|
|
:> |
1 | Decimal | Yes | Range from 0 to n, right-exclusive. |
4 :>(0 1 2 3)
|
< |
2 | Decimal, Decimal | Yes | Less-than. |
3 (2 3 4) <(0 0 1)
|
< |
2 | String, String | Yes | Less-than by alphabetic ordering. |
'a' 'b' <1
|
<= |
2 | Decimal, Decimal | Yes | Less-than or equal-to. |
3 (2 3 4) <=(0 1 1)
|
<= |
2 | String, String | Yes | Less-than or equal-to by alphabetic ordering. |
'a' 'b' <=1
|
> |
2 | Decimal, Decimal | Yes | Greater-than. |
3 (2 3 4) >(1 0 0)
|
> |
2 | String, String | Yes | Greater-than by alphabetic ordering. |
'a' 'b' >0
|
>= |
2 | Decimal, Decimal | Yes | Greater-than or equal-to. |
3 (2 3 4) >=(1 1 0)
|
>= |
2 | String, String | Yes | Greater-than or equal-to by alphabetic ordering. |
'a' 'b' >=0
|
<=> |
2 | Decimal, Decimal | Yes |
-1 if x < y, 0 if x == y, 1 if x > y. |
2 (1 2 3) <=>(1 0 _1)
|
<=> |
2 | String, String | Yes |
-1 if x < y, 0 if x == y, 1 if x > y. |
'b' ('a' 'b' 'c') <=>(1 0 _1)
|
= |
2 | Any, Any | No | Equality. |
1 2 =0
|
BAND |
2 | Decimal, Decimal | Yes | 32-bit-wise and. |
3 5 BAND1
|
BOR |
2 | Decimal, Decimal | Yes | 32-bit-wise or. |
3 5 BOR7
|
BXOR |
2 | Decimal, Decimal | Yes | 32-bit-wise xor. |
3 5 BOR6
|
DEBUG |
n/a | Debugs the stack. | |||
DEL |
2 | String | No | Removes all (Regex) instances of y recursively from x. |
'<<><><>>>' '<>' DEL`'>' |
FIX |
1 | Any | No | See #&. |
((1 2 3) (4) (5 6)) #&((1 2 3) |
FSHAPE |
3 | Any[], Any, Func-like | No | Creates an array of shape x: then, applies F(y, i) for i from 0 to prod(x). |
(3 4) (0 5) $## FSHAPE((0 5 0 5) |
table |
3 | Any, Any, Func-like | No | Maps f over a with b. |
(1 2 3) (4 5 6) $+ table((5 6 7) |