This chapter replicates the REPL help system contents, also
found in the repository in
docs/help.txt.
It is the practical reference for the language.
More in-depth explanations of specific topics can be found
in the
FAQ
chapter.
TOPICS HELP
Type help TOPIC or h TOPIC where TOPIC is one of:
"s" syntax
"t" value types
"v" verbs (like +*-%,)
"nv" named verbs (like in, sign)
"a" adverbs (/\')
"tm" time handling
"rt" runtime system
op where op is a builtin’s name (like "+" or "in")
ext name of built extension (like "os" or "math")
Notations:
i (integer) n (number) s (string) r (regexp)
d (dict) t (dict S!Y) h (handle) e (error)
fs (file system) m (map) c (channel)
f (function) F (dyadic function)
x,y,z (any other) I,N,S,X,Y,A (arrays)
————————————————————————————————————————————————————————————————————————————————
SYNTAX HELP
numbers 1 1.5 0b0110 1.7e-3 0xab 0n 0w 3h2m
strings "text\x2c\u00FF\n" "\"" "\u65e5" "interpolated $var"
qq/$var\n or ${var}/ qq#text# (delimiters :+-*%!&|=~,^#_?@`/)
raw strings rq/anything until single slash/ rq#doubling ## escapes#
arrays 1 2 -3 4 1 "ab" -2 "cd" (1 2;"a";3 "b";(4 2;"c");*)
regexps rx/[a-z]/ (see FAQ for syntax and usage details)
dyadic verbs : + - * % ! & | < > = ~ , ^ # _ $ ? @ . (right-associative)
monadic verbs :: +: -: abs uc error …
adverbs / \ ' ` ´ (alone or after expr. with no space, left-associative)
expressions 2*3+4 → 14 1+|2 3 4 → 5 4 3 +/'(1 2 3;4 5 6) → 6 15
separator ; or newline except when ignored after {[( and before )]}
variables x a.b f data t1 π (. only in globals or with p. q. pfx)
assign x:2 (local within lambda, global otherwise) x::2 (global)
op assign x+:1 (sugar for x:x+1 or x::x+1) x@':y (sugar for x:x@'y)
list assign (x;y;z):X (where 2<#X) (x;y):1 2;y → 2 (;y):1 2;y → 2
eval. order apply:f[e1;e2] apply:e1 op e2 (e2 before)
list:(e1;e2) seq: [e1;e2] lambda:{e1;e2} (e1 before)
sequence [x:2;y:x+3;x*y] → 10 (bracket not following noun tightly)
index/apply x[y] or x y is sugar for x@y; x[] ~ x[*] ~ x[!#x] ~ x (arrays)
index deep x[y;z;…] → x.(y;z;…) (except for x in (?;and;or))
index assign x[y]:z → x:@[x;y;:;z] (or . for x[y;…]:z)
index op assign x[y]op:z → x:@[x;y;op;z] (for symbol dyad or derived verb)
lambdas {x+y-z}[3;5;7] → 1 {[a;b;c]a+b-c}[3;5;7] → 1
{[;b;c]b*c}[2;3;4] → 12 (unnamed/ignored first argument)
{?[x>1;x*o x-1;1]}5 → 120 (o is recursive self-reference)
projections +[2;] 3 → 5 (2+) 3 → 5 (partial application)
{x+p.a} → {[p0;x]x+p0}[a;] (p. projects)
{[a;b|c;d]…} → {[a;b;c;d]…}[a;b] (named partial application)
compositions ~0> → {~0>x} -+ → {- x+y} *|: → {*|x}
index at field x..a → x["a"] (.. binds identifiers tightly, interpolable)
field expr. ..a+b → {x["a"]+x["b"]} (field names without . and not in x,y,z)
..p.a+b+q.c → {[p0;x]p0+x["b"]+c}[a;] (p. projects; q. quotes)
field expr. at x.. a+b → {x["a"]+x["b"]}[x] (same as (..a+b)x)
dict fields ..[a:e1;b:e2;c] → "a""b""c"!(e1;e2;c)
amend fields x..[a:e1;b:e2] → @[x;"a""b";:;x..(e1;e2)]
cond ?[1;2;3] → 2 ?[0;2;3] → 3 ?[0;2;"";3;4] → 4
and/or and[1;2] → 2 and[1;0;3] → 0 or[0;2] → 2 or[0;0;0] → 0
return [1;:2;3] → 2 (a : at start of expression)
try 'x is sugar for ?["e"~@x;:x;x] (return if it’s an error)
log \x logs a string representation of x (debug/display tool)
defer f defer y calls f@y before returning (rank 1)
or does r:f[y;r] where r is the returned value (rank 2)
(in case of panic r is an error dict as in “try at”)
discard `e discards well-formed e during parsing (ignore expression)
comments from line with a single / until line with a single \
or from / (after space or start of line) to end of line
————————————————————————————————————————————————————————————————————————————————
TYPES HELP
atom array name examples
i I integer 0 -2 !5 4 3 -2 5 0i
n N number 0.0 1.5 0.0+!5 1.2 3 0n 1e+10
s S string "abc" "d" "a" "b" "c"
r regexp rx/[a-z]/ rx/\s+/
d dictionary "a""b"!1 2 ..[a:1;b:1]
f function + {x-1} 2* %[;2]
h handle open"/path/to/file" "w"open"/path/to/file"
e error error"msg"
/ file system dirfs"/path/to/dir"
m map map.new@..[a:1;b:2]
c channel chan.new 0 chan.after 2s
A generic array ("a" 1;"b" 2;"c" 3) (+;-;*;"any")
————————————————————————————————————————————————————————————————————————————————
VERBS HELP
:x identity :[42] → 42 (recall that : is also syntax for return and assign)
x:y right 2:3 → 3 "a":"b" → "b"
+d swap k/v +"a""b"!0 1 → 0 1!"a" "b"
+x flip +(1 2;3 4) → (1 3;2 4) +42 → ,,42
n+n add 2+3 → 5 2+3 4 → 5 6 +[1;2;3] → 6
s+s concat "a"+"b" → "ab" "a" "b"+"c" → "ac" "bc"
-n negate - 2 3 → -2 -3 -(1 2.5;3 4) → (-1.0 -2.5;-3 -4)
-s rtrim space -"a\tb \r\n" " c d \n" → "a\tb" " c d" (Unicode’s White Space)
n-n subtract 5-3 → 2 5 4-3 → 2 1
s-s trim suffix "file.txt"-".txt" → "file"
*x first *7 8 9 → 7 *"ab" → "ab" *(+;*) → +
n*n multiply 2*3 → 6 1 2 3*3 → 3 6 9 *[2;3;4] → 24
s*i repeat "a"*3 2 1 0 → "aaa" "aa" "a" ""
%X classify %7 8 9 7 8 9 → 0 1 2 0 1 2 %"a" "b" "a" → 0 1 0
n%n divide 3%2 → 1.5 3 4%2 → 1.5 2.0
s%s glob match "*.csv"%"data.csv" "code.goal" "dir/data.csv" → 1 0 0
!i enum !5 → 0 1 2 3 4 !-5 → -5 -4 -3 -2 -1
!s fields !"a b\tc\nd \u00a0e" → "a""b""c""d""e" (Unicode’s White Space)
!I odometer !2 3 → (0 0 0 1 1 1;0 1 2 0 1 2)
!d keys !"a""b"!1 2 → "a" "b"
i!n mod/div 3!9 8 7 → 0 2 1 -3!9 8 7 → 3 2 2
i!s pad fields 3!"a" → "a " -3!"1" "23" "456" → " 1" " 23" "456"
s!s fields ",;"!"a,b;c" → "a""b""c" (fields cut on any of ",;"; ""!s is !s)
X!Y dict d:"a""b"!1 2; d"a" → 1 (same as d:..[a:1;b:2]; d..a)
&s byte-count &"abc" → 3 &"π" → 2 &"αβγ" → 6
&I where &0 0 1 0 0 0 1 → 2 6 &2 3 → 0 0 1 1 1
&d keys where &"a""b""c""d"!0 1 1 0 → "b" "c"
x&y min/and 2&3 → 2 4&3 → 3 "b"&"a" → "a" 0&1 → 0
|X reverse |!5 → 4 3 2 1 0
x|y max/or 2|3 → 3 4|3 → 4 "b"|"a" → "b" 0|1 → 1
<d sort up <"a""b""c"!2 3 1 → "c""a""b"!1 2 3
<X ascend <3 5 4 → 0 2 1 (index permutation for ascending order)
x<y less 2<3 → 1 "c"<"a" → 0 7 8<6 9 → 0 1
>d sort down >"a""b""c"!2 3 1 → "b""a""c"!3 2 1
>X descend >3 5 4 → 1 2 0 (index permutation for descending order)
x>y more 2>3 → 0 "c">"a" → 1 7 8>6 9 → 1 0
=s lines ="ab\ncd\r\nef gh" → "ab" "cd" "ef gh"
=I index-count =1 0 0 2 2 3 -1 2 1 1 1 → 2 4 3 1
=d group keys ="a""b""c"!0 1 0 → ("a" "c";,"b") ="a""b"!0 -1 → ,,"a"
f=Y group by (2!)=!10 → (0 2 4 6 8;1 3 5 7 9)
x=y equal 2 3 4=3 → 0 1 0 "ab" = "ba" → 0
~x not ~0 1 2 → 1 0 0 ~"a" "" "0" → 0 1 0
x~y match 3~3 → 1 2 3~3 2 → 0 ("a";%)~'("b";%) → 0 1
,x enlist ,1 → ,1 #,2 3 → 1 (list with one element)
d,d merge ("a""b"!1 2),"b""c"!3 4 → "a""b""c"!1 3 4
x,y join 1,2 → 1 2 "ab" "c","d" → "ab" "c" "d"
^d sort keys ^"c""a""b"!1 2 3 → "a""b""c"!2 3 1
^X sort ^3 5 0 → 0 3 5 ^"ca" "ab" "bc" → "ab" "bc" "ca"
i^s windows 2^"abcde" → "abcd" "bcde"
i^Y windows 2^!4 → (0 1 2;1 2 3) -2^!4 → (0 1;1 2;2 3)
s^s trim " #"^" #a ## b# " → "a ## b" ""^" \na\t b\t" → "a\t b"
r^S weed out rx/a/^"ab" "bc" "cd" "da" → "bc" "cd"
f^y weed out {0 1 1 0}^4 1 5 3 → 4 3 (0<)^2 -3 1 → ,-3
X^t w/o keys & (,"b";1 0)^..[a:6 7;b:8 9] → (,"a")!,,7
(0;..a>1;..b<0)^..[a:1 2 3;b:4 -5 6] → "a""b"!(,1;,4)
X^d w/o keys (,"b")^"a""b""c"!0 1 2 → "a""c"!0 2
X^Y w/o values 2 3^1 1 2 3 3 4 → 1 1 4 (like in[;X]^Y)
#x length #7 8 9 → 3 #"ab" "cd" → 2 #42 → 1 #"ab" → 1
i#y take/repeat 2#6 7 8 → 6 7 5#6 7 8 → 6 7 8 6 7 3#1 → 1 1 1
s#s count "ab"#"cabdab" "cd" "deab" → 2 0 1 ""#"αβγ" → 4
r#S filter rx/a/#"ab" "bc" "cd" "da" → "ab" "da"
f#y replicate {0 1 2 0}#4 1 5 3 → 1 5 5 (0<)#2 -3 1 → 2 1
X#t w/ keys & (,"a";0 1)#..[a:6 7;b:8 9] → (,"a")!,,7
(1;..a>1;..b>0)#..[a:1 2 3;b:4 -5 6] → "a""b"!(,3;,6)
X#d with keys "a""c""e"#"a""b""c""a"!2 3 4 5 → "a""c""a"!2 4 5
X#Y with values 2 3#1 1 2 3 3 4 → 2 3 3 (like in[;X]#Y)
_n floor _2.3 → 2.0 _1.5 3.7 → 1.0 3.0
_s to lower _"ABC" → "abc" _"AB" "CD" "Π" → "ab" "cd" "π"
i_s drop bytes 2_"abcde" → "cde" -2_"abcde" → "abc"
i_Y drop 2_3 4 5 6 → 5 6 -2_3 4 5 6 → 3 4
s_s trim prefix "pfx-"_"pfx-name" "pfx2-name" → "name" "pfx2-name"
r_Y cut where rx/a/_"ab" "bc" "cd" "da" → ("ab" "bc" "cd";,"da")
f_Y cut where {0=3!x}_!10 → (0 1 2;3 4 5;6 7 8;,9) (same as (&f Y)_Y)
I_s cut string 1 3_"abcdef" → "bc" "def" (I ascending)
I_Y cut 2 5_!10 → (2 3 4;5 6 7 8 9) (I ascending)
$x string $2 3 → "2 3" $"text" → "\"text\""
i$s cut shape 3$"abcdefghijk" → "abc" "defg" "hijk"
i$Y cut shape 3$!6 → (0 1;2 3;4 5) -3$!6 → (0 1 2;3 4 5)
s$y strings "s"$(1;"c";+) → "1""c""+"
s$s chars/bytes "c"$"aπ" → 97 960 "b"$"aπ" → 97 207 128
s$i to string "c"$97 960 → "aπ" "b"$97 207 128 → "aπ"
s$n cast "i"$2.3 → 2 @"n"$42 → "n"
s$s parse i/n "i"$"42" "0b100" → 42 4 "n"$"2.5" "1e+20" → 2.5 1e+20
s$s rx string "r"$rx#[a-z]# → "[a-z]" "r"$"[a-z]" → "\\[a-z\\]"
s$s parse value "v"$qq/(2 3;"a")/ → (2 3;"a") ($x inverse for types in "inrs")
s$y format "%.2g"$1 4%3 → "0.33" "1.3" "%s=%03d"$"a" 42 → "a=042"
X$y binsearch 2 3 5 7$8 2 7 5 5.5 3 0 → 4 1 4 3 3 2 0 (X ascending)
?i uniform ?2 → 0.6046602879796196 0.9405090880450124 (between 0 and 1)
?i normal ?-2 → -1.233758177597947 -0.12634751070237293 (mean 0, dev 1)
?X distinct ?2 2 4 3 2 3 → 2 4 3 (keeps first occurrences)
i?i roll 5?100 → 10 51 21 51 37
i?Y roll array 5?"a" "b" "c" → "c" "a" "c" "c" "b"
i?i deal -5?100 → 19 26 0 73 94 (always distinct)
i?Y deal array -3?"a""b""c" → "a""c""b" (0i?Y is (-#Y)?Y) (always distinct)
s?r rindex "abcde"?rx/b../ → 1 3 (offset;length)
s?s index "a = a + 1"?"=" "+" → 2 6
d?y find key ("a""b"!3 4)?4 → "b" ("a" "b"!3 4)?5 → ""
X?y find 9 8 7?8 → 1 9 8 7?6 → 3
@x type @2 → "i" @1.5 → "n" @"ab" → "s" @2 3 → "I" @(+) → "f"
i@y take/pad 2@6 7 8 → 6 7 4@6 7 8 → 6 7 8 0 -4@6 7 8 → 0 6 7 8
s@i substr "abcdef"@2 → "cdef" (s[offset])
r@s match rx/^[a-z]+$/"abc" → 1 rx/\s/"abc" → 0
r@s find group rx/([a-z])(.)/"&a+c" → "a+" "a" "+" (whole match, group(s))
f@y apply at (|)@1 2 → 2 1 (like |[1 2] → 2 1 or |1 2 or (|).,1 2)
d@y at key ..[a:6 7;b:8 9]"a" → 6 7 (1 2!"a""b")2 → "b"
t@i at row ..[a:6 7;b:8 9]0 → "a""b"!6 8
X@i at 7 8 9@2 → 9 7 8 9[2 0] → 9 7 7 8 9@-2 → 8
.s get global a:3;."a" → 3
.e get error .error"msg" → "msg"
.d values ."a""b"!1 2 → 1 2
.X self-dict ."a""b" → "a""b"!"a""b" .!3 → 0 1 2!0 1 2
s.I substr "abcdef"[2;3] → "cde" (s[offset;length])
r.y findN rx/[a-z]/["abc";2] → "a""b" rx/[a-z]/["abc";-1] → "a""b""c"
r.y findN group rx/[a-z](.)/["abcdef";2] → ("ab" "b";"cd" "d")
f.y apply (+).2 3 → 5 +[2;3] → 5
d.y deep at ..[a:6 7;b:8 9]["a";1] → 7 ..[f:1+]["f";2] → 3
t.y at row;key ..[a:6 7;b:8 9][1;"a"] → (,"a")!,7
X.y deep at (6 7;8 9)[0;1] → 7 (6 7;8 9)[;1] → 7 9
«X shift «8 9 → 9 0 «"a" "b" → "b" "" (ASCII keyword: shift x)
x«Y shift "a" "b"«1 2 3 → 3 "a" "b"
»X rshift »8 9 → 0 8 »"a" "b" → "" "a" (ASCII keyword: rshift x)
x»Y rshift "a" "b"»1 2 3 → "a" "b" 1
::[s;y] set global ::["a";3];a → 3 (brackets needed because :: is monadic)
@[d;y;f] amend @["a""b""c"!7 8 9;"a""b""b";10+] → "a""b""c"!17 28 9
@[X;i;f] amend @[7 8 9;0 1 1;10+] → 17 28 9
@[d;y;F;z] amend @["a""b""c"!7 8 9;"a";:;42] → "a""b""c"!42 8 9
@[X;i;F;z] amend @[7 8 9;1 2 0;+;10 20 -10] → -3 18 29
@[f;y;f] try at @[2+;"a";:] → error..[msg:s;stack:f;panic:f] (panic case)
where e..msg returns the panic error message (s)
e..stack returns the whole error stack trace (s)
e..panic repanics
@[2+;3;:] → 5 (no-panic case)
@[.;"a";42] → 42 (non-function panic case)
.[X;i;f] deep amend .[(6 7;8 9);0 1;-] → (6 -7;8 9)
.[X;i;F;z] deep amend .[(6 7;8 9);(0 1 0;1);+;10] → (6 27;8 19)
.[(6 7;8 9);(*;1);:;42] → (6 42;8 42)
.[s;i;f] amend var a:(6 7;8 9); .["a";0 1;-]; a → (6 -7;8 9) (global a)
(works similarly for other amend forms with . or @)
.[f;y;f] try same as @[f.;y;f]
————————————————————————————————————————————————————————————————————————————————
NAMED VERBS HELP
abs n abs value abs -3.0 -1.5 2.0 → 3.0 1.5 2.0
csv s csv read csv"a,b\n1,2" → ("a" "1";"b" "2")
csv A csv write csv("a" "b";1 2) → "a,1\nb,2\n"
error x error r:error"msg"; (@r;.r) → "e" "msg"
eval s comp/run a:5;eval"a+2" → 7
firsts X mark firsts firsts 0 0 2 3 0 2 3 4 → 1 0 1 1 0 0 0 1 (same as ¿X)
json x parse json json rq`{"a":true,"b":"text"}` → "a" "b"!0w "text"
json h → decoding function f such that f@i decodes up to
i JSON values (or an unlimited number if i<1)
nan n isNaN nan(0n;2;sqrt -1) → 1 0 1 nan 2 0i 3 → 0 1 0
ocount X occur-count ocount 3 4 5 3 4 4 7 → 0 0 0 1 1 2 0
panic s panic panic"msg" (for fatal programming-errors)
round n round2even round 1.2 1.7 2.5 3.5 → 1.0 2.0 2.0 4.0 (ties to even)
rx s comp. regex rx"[a-z]" (like rx/[a-z]/ but compiled at runtime)
sign n sign sign -3 -1 0 1.5 5 → -1.0 -1.0 0.0 1.0 1.0
uc x upper/ceil uc 1.5 → 2.0 uc"abπ" → "ABΠ"
s csv s csv read " "csv"a b\n1 2" → ("a" "1";"b" "2") (" " as separator)
s csv A csv write " "csv("a" "b";1 2) → "a 1\nb 2\n" (" " as separator)
x in s contained "bc" "ac"in"abcd" → 1 0 (same as x¿s)
x in Y member of 2 3 in 8 2 4 → 1 0 (same as x¿Y)
s json y write json ""json 1.5 2 → "[1.5,2]" (indent with s;disable with "")
S json y write json like s json y, but with (pfx;indent) for pretty-printing
n nan n fill NaNs 42.0 nan(1.5;sqrt -1) → 1.5 42.0 42 nan 2 0i → 2 42
i rotate Y rotate 2 rotate 7 8 9 → 9 7 8 -2 rotate 7 8 9 → 8 9 7
sub[r;s] regsub sub[rx/[a-z]/;"Z"] "aBc" → "ZBZ"
sub[r;f] regsub sub[rx/^./;uc]"abc" "πρσ" → "Abc" "Πρσ"
sub[s;s] replace sub["b";"B"] "abc" → "aBc"
sub[s;s;i] replaceN sub["a";"b";2] "aaa" → "bba" (stop after 2 times)
sub[S] replaceS sub["b" "d" "c" "e"] "abc" → "ade"
sub[S;S] replaceS sub["b" "c";"d" "e"] "abc" → "ade"
eval[s;loc;pfx] like eval s, but provide loc as location (usually a
path), and prefix pfx+"." for globals; does not eval
same location more than once
utf8 s is UTF-8 utf8 "aπc" → 1 utf8 "a\xff" → 0
i utf8 s take chars 2 utf8 "αβγ" "π" → "αβ" "π" -2 utf8 "αβγ" → "βγ"
s utf8 s to UTF-8 "b" utf8 "a\xff" → "ab" (replace invalid with "b")
FLOAT MATH VERBS HELP
cos n cosine cos 0.0 1.57 3.14 → 1.0 0.00… -0.99…
sin n sine sin -1.57 0.0 1.57 → -0.99… 0.0 0.99…
sqrt n square root sqrt 2.0 4.0 9.0 → 1.41… 2.0 3.0
x atan n arc-tangent -1.0 0.0 atan 0.0 1.0 → 3.14… 1.57… (x defaults to 1)
x exp n exponential 2.0 exp 3.0 → 8.0 (x defaults to e~2.718…)
x log n logarithm 2.0 log 8.0 → 3.0 (x defaults to e~2.718…)
————————————————————————————————————————————————————————————————————————————————
ADVERBS HELP
f'x each #'(4 5;6 7 8) → 2 3
S'x each substr "abcd""efgh"'1 2 → "bcd" "gh"
x F'y each 2 3#'4 5 → (4 4;5 5 5) {(x;y;z)}'[1;2 3;4] → (1 2 4;1 3 4)
x I'y case (6 7 8 9)0 1 0 1'"a""b""c""d" → 6 "b" 8 "d"
I S'I each substr "abcd""efgh"'[1 2;2] → "bc" "gh"
I A'I each at m:3$!9;p:!2 2;(m').p → 0 1 3 4
x F`y each left 1 2,`"a""b" → (1 "a" "b";2 "a" "b") (same as F[;y]'x)
x F´y each right 1 2,´"a""b" → (1 2 "a";1 2 "b") (same as F[x;]'y)
F/x fold +/!10 → 45
F\x scan +\!10 → 0 1 3 6 10 15 21 28 36 45
x F/y fold 5 6+/!4 → 11 12 {x+y-z}/[5;4 3;2 1] → 9
fold while */[10>;1;8#2] → 16 (see “fold while” in FAQ)
x F\y scan 5 6+\!4 → (5 6;6 7;8 9;11 12) {x+y-z}\[5;4 3;2 1] → 7 9
scan while *\[10>;1;8#2] → 2 4 8 16 (see “scan while” in FAQ)
i f/y do 3(2*)/4 → 32
i f\y dos 3(2*)\4 → 4 8 16 32
f f/y while (100>)(2*)/4 → 128
f f\y whiles (100>)(2*)\4 → 4 8 16 32 64 128
f/x converge {1+1.0%x}/1 → 1.618033988749895 {-x}/1 → -1
f\x converges (-2!)\10 → 10 5 2 1 0 {-x}\1 → 1 -1
s/S join ","/"a" "b" "c" → "a,b,c"
s\s split ","\"a,b,c" → "a" "b" "c" ""\"aπc" → "a" "π" "c"
r\s split rx/[,;]/\"a,b;c,d" → "a" "b" "c" "d"
i s\s splitN (2)","\"a,b,c" → "a" "b,c"
i r\s splitN (3)rx/[,;]/\"a,b;c,d" → "a" "b" "c,d"
I/x decode 24 60 60/1 2 3 → 3723 2/1 1 0 → 6
I\x encode 24 60 60\3723 → 1 2 3 2\6 → 1 1 0
————————————————————————————————————————————————————————————————————————————————
TIME HELP
time cmd time command with current time
cmd time t time command with time t
time[cmd;t;fmt] time command with time t in given format
time[cmd;t;fmt;loc] time command with time t in given format and location
Time t should consist either of integers or strings in the given format ("unix"
is the default for integers and RFC3339 layout "2006-01-02T15:04:05Z07:00" is
the default for strings), with optional location (default is "UTC"). See FAQ
for information on layouts, locations, and date calculations. Supported values
for cmd are as follows:
cmd (s) fmt result (type)
------- --- -------------
"clock" hour, minute, second (I)
"date" yes year, month, day (I)
"day" day number (i)
"hour" 0-23 hour (i)
"minute" 0-59 minute (i)
"month" 0-12 month (i)
"second" 0-59 second (i)
"unix" yes unix epoch time (i)
"unixmicro" yes unix (microsecond version) (i)
"unixmilli" yes unix (millisecond version) (i)
"unixnano" yes unix (nanosecond version) (i)
"week" year, week (I)
"weekday" 0-6 weekday starting from Sunday (i)
"year" year (i)
"yearday" 1-365/6 year day (i)
format (s) yes format time using given layout (s)
————————————————————————————————————————————————————————————————————————————————
RUNTIME HELP
rt.get s return runtime information named by s:
"!" names of globals (S)
"kw" names of verbal keywords (S)
"loc" current eval location (s)
"os" operating system (s) (Go’s runtime.GOOS)
"pfx" current eval prefix for globals (s)
"v" interpreter’s version (s)
rt.get["@";y] dict with internal info about y (for debug purposes only)
rt.go d call each key f on corresponding value y as in f@y but on a
separate goroutine with forked execution context; modifications
of globals aren’t shared with parent context
returns the collected results in order
rt.log x like :[x] but logs string representation of x (same as \x)
rt.rank x return the rank of x (default arity)
rt.seed i set non-secure pseudo-rand seed to i (for repeatability in ?)
rt.sleep i pause current goroutine for at least duration i (ns)
returns monotonic time (ns since startup)
(no pause for negative or zero duration)
rt.time[s;i] eval s for i times (default 1), return average time (ns)
rt.time[f;y;i] call f. y for i times (default 1), return average time (ns)
————————————————————————————————————————————————————————————————————————————————
IO/OS HELP (core "os" extension)
abspath s return an absolute representation of path or joined path elements
bufio h return new buffered handle
chdir s change current working directory to s
close h flush any buffered data, then close handle h
dirfs s return a read-only file system value fs, rooted at directory s,
usable as left argument in glob, import, open, read, stat
fs subfs dir returns the subtree rooted at fs’ dir
env s return value of environment variable s, or an error if unset
return a dict representing the whole environment if s~""
flush h flush any buffered data for buffered handle h
glob s return file names matching glob pattern(s) (ignores stat errors)
import s read/eval wrapper roughly equivalent to eval[src;path;pfx] where:
s with extension s without extension
---------------- ---------------------------------
pfx~basename s pfx~sub["/";"."]s
path~s path~s+".goal"
src~read s src~(dirfs env"GOALLIB")read path
mkdir s create new directory named s (parent must already exist)
open s open path s for reading, returning a handle h
print x print"Hello, world!\n" (uses implicit $x for ~(@x)in"sSe")
read h read from handle h until EOF or an error occurs
read s read file named s into string lines:=-read"/path/to/file"
or dict ..[dir:I;name:S] if s is a directory
remove s remove the named file or empty directory
run s run command s or S (with arguments) run"pwd" run"ls" "-l"
inherits stdin and stderr, returns its standard output or an error
dict ..[msg:s;code:i;out:s]
say x same as print, but appends a newline say!5
shell s same as run, but through "/bin/sh" (unix systems only) shell"ls -l"
stat x returns dict ..[dir:i;mtime:i;size:i] (for filehandle h or path s)
s copy fs copy file system fs into new directory named s
x copy y copy from handle or named file y into handle or named file x
returns number of copied bytes or an error
x env s set environment variable x to s
x env 0 unset environment variable x, or clear environment if x~""
x import s same as import s, but using prefix x for globals
x open y open path s with mode x in "r" "w" "a" (file read/write/append)
or string s or init size i with "sr" "sw" (string read/write)
or pipe from or to command s or S with "pr" "pw" (pipe read/write)
or async command s or S with "c" (close to wait)
or "file" or "mem" (r;w) pipe handles with "p"
returns handle h accepting the following calls:
h..mode handle’s mode (s) (available for all modes)
h..name file’s name (s) (modes "r" "w" "a")
h..dir whether file is dir (i) (mode "r")
h..sync file sync (i or e) (modes "w" "a")
h..s get string (s) (modes "sr" "sw")
h..kill kill process (i or e) (modes "pr" "pw" "c")
h..pid process PID (i) (modes "pr" "pw" "c")
open and run also accept x as a dict: see FAQ for advanced usage
x print y print y to handle/path x "/path/to/file"print"content"
i read h read i bytes from reader h or until EOF, or an error occurs
s read h read from reader h until 1-byte s, EOF, or an error occurs
x rename y rename (move) old path x (s) to new path y (s)
x run s same as run s but with input string or lines x as stdin
x say y same as print, but appends a newline
copy[x;y;i] same as copy[x;y] but until it copies i bytes, or an error occurs
ARGS command-line arguments, starting with script name
STDIN standard input filehandle (mode "r")
STDOUT standard output filehandle (mode "w")
STDERR standard error filehandle (mode "w")
————————————————————————————————————————————————————————————————————————————————
EXTRA FLOAT MATH HELP (default "math" extension)
MONADS (with "math." prefix): acos, acosh, asin, asinh, atanh, cbrt, cosh, erf,
erfc, erfcinv, erfinv, exp2, expm1, gamma, log2, log10, log1p, logb, sinh,
tan, tanh, trunc
DYADS: math.jn, math.yn (defaulting to order-zero for monadic case)
math.mmax[i;I|N] i-item moving maximums (|\ for i first items)
math.mmin[i;I|N] i-item moving minimums (&\ for i first items)
math.mmu[N;N] matrix multiplication or dot product
(works on floats but currently converts any integers if
necessary; experimental)
————————————————————————————————————————————————————————————————————————————————
MAPS HELP (default "maps" extension, experimental)
map.clear m clear all entries in m and return the emptied m
map.clear[m;y] clear entry in m corresponding to key y and return m
map.dict m return a copy of the map as a dict
map.len m return the number of entries in the map
map.new d return a new map with initial key/value pairs given by d
keys can be strings or numbers
map.set[m;y;z] set key y in m to value z and return m
map.set[m;d] set keys !d in m to values .d and return m
m y get value corresponding to key y (error if key is not found)
m..s[…] evaluates to (m..s)[…] (like with dicts)
————————————————————————————————————————————————————————————————————————————————
CHANS HELP (default "chans" extension, experimental)
chan.new i return a new bidirectional channel with capacity for i elements
chan.len c return number of queued elements in channel buffer
chan.cap c return channel buffer capacity
chan.recv c receive value on channel c
chan.send[c;y] send y on channel c
chan.after i return new channel receiving monotonic time after duration at
least i (ns)
chan.tick i return new channel receiving monotonic time at regular ticks
of period given by duration i (ns)
chan.notify c intercept and relay to channel c signals SIGHUP, SIGINT and
SIGTERM as error values with the signal’s name as message
chan.select[case…]
Select operation where each case is provided as an argument sequence:
"r";c receive value on channel c
"s";c;y send y on channel c
"_" default case (for non-blocking select)
Returns index of chosen case and, if that was a receive operation, the
value received (or an error when receiving from a closed channel)
————————————————————————————————————————————————————————————————————————————————
BASE64 HELP (default "encoding/base64" extension)
base64.enc s encode string in standard base64 encoding
base64.urlenc s encode string in alternate url base64 encoding (no padding)
base64.dec s decode string in standard base64 encoding
base64.urldec s decode string in alternate url base64 encoding (no padding)
Decoding may return an error value dict with the partially decoded data (key
"dec") along with the error message (key "msg").
————————————————————————————————————————————————————————————————————————————————
ZIP HELP (extra "archive/zip" extension)
zip.open s open zip file at given path s and return a file system value
zip.write[s;fs] write file system value fs to new zip file named s
————————————————————————————————————————————————————————————————————————————————
NETWORKING HELP (extra "net" extension, experimental)
net.dial[network;addr[;timeout]]
Connect given address on the named network with optional timeout (ns).
Returns connection handle h that supports read, writes, close, and the
following calls:
h..localAddr local address (s)
h..remoteAddr remote address (s)
h..deadline[i[;s]] set read "r" and/or write "w" deadline
(monotonic time)
See FAQ for details on network and address syntax.
net.listen[network;addr]
Return listener l on the given network address that supports close and
accepts calls:
l..network network (s)
l..addr address (s)
l..accept wait and return connection handle (h)
————————————————————————————————————————————————————————————————————————————————
HTTP HELP (extra "net/http" extension, experimental)
http.server d
Return http.server configured with dict d options:
"addr" (s) TCP address to listen on
"handler" (http.f|f) handler value or function
"log" (h) writer handle for access log
The http handler takes response writer and request arguments. It can be a
dict of pattern:handler pairs. See FAQ for pattern syntax and rules.
Request values are handles that support read for the body, and accept the
following ..field calls:
method (s) url (s) scheme (s) path (s) query (d) header (d)
contentLength (i) host (s) form (d) remoteAddr (s) pathValue[s] (s)
Response writer values are handles that support body writes, and accept the
following calls:
h..header copy of header as dict (d)
h..header[d] update headers with key/values in dict d
h..header[i] write headers with status code i (default: 200)
h..error[s;i] replies with given message and error code
h..notFound replies with an HTTP 404 not found error
The returned server srv accepts the following calls:
srv..serve listen and serve on d..addr
srv..serve[cert;key] listen and serve on d..addr using TLS
srv..serve[net.l[;cert;key]]
same but accept connections on listener net.l
srv..shutdown attempt to gracefully stop the server
srv..shutdown[i] same but with given timeout (ns) before forceful
server close (default: 10s)
http.fs x server handler for directory (s) or file system x
http.fs[fs;s] server handler for file named s in file system fs
http.maxbytes[handler;i] derived handler that makes request reads return an
error beyond a limit of i bytes
http.redirect[url;code] redirect handler to url (s) with 3xx code (i)
http.strip[handler;pfx] derived handler that strips path prefix pfx (s) from
request URL; replies with 404 for non-matching
prefixes
http.timeout[handler;i;s] derived handler that runs within duration i (ns) or
responds with 503 and optional message s, and makes
writes by handler return an error
http.client d
Return an http client configured with dict d options:
"timeout" (i) time limit for requests (ns)
"rateLimit" (i) time interval to wait for a tick before requests (ns)
The returned client cl accepts calls of the following form:
cl..method[url[;opts]]
Methods can be written lowercase. The url should be a string.
The opts dict accepts the following options:
"body" (s|h) raw body of the request
"header" (d) headers (dict of s:s|S pairs)
Response values are handles that support read for the body, and should
always be close-d after use. They accept the following ..field calls:
status (s) code (i) contentLength (i) request (h) header (d)