syzy??
syzy is a recreational tacit array programming language inspired by J, K and BQN.
Quickref
/ comment
1 2 3 / comment
+/not comment (no trailing ws)
1 3.4 42 / numbers (arbitrary precision floats)
nan inf /
a b c / symbols
'a' 'b' 'c' / chars (unicode codepoints)
+ / verb
" / adverb
} / conjunction (dyadic adverb)
+/ / verb + adverb (=sum)
+}1 / verb + conjunction + noun (=+1)
/ NB: verbs are parsed right-to-left, adverbs/conjunctions left-to-right
1+ / shortcut for +{1
1 2 3 /
a b c / arrays
'hey!' /
1 2,:3 3,:5 / strand (mixed array literal)
'a' / char
,'a' / 1-char string
,1 / 1-element array
!0 / empty array
() / empty array literal
-1 / negative num literal
- 1 / application of - negate to 1
-1 -2 -3 / array of negative nums
- 1 2 3 / application of - negate to an array of nums
:x+y / function literal
:1 / function that always yields 1
x:123 / bind name
sq:*;. /
fac:*/i.x / bind function
f:x+y /
f:-x / overload function by arity
f 5 / = -5
5 f 5 / = 10
*/i. / hook, same as */;i.
+/%# / fork, same as +/@:#%
: dyadic bind bind symbol x to y
+ monadic flip transpose a matrix
+. monadic square x ^ 2
+: monadic sin sin(x)
+ dyadic plus add numbers (or chars)
+. dyadic gcd compute gcd
- monadic negate negate numbers
-. monadic last last elt of x
- dyadic minus subtract numbers
* monadic first get first elt of array (head)
*. monadic tail get tail of array (i.e. all elts except first)
*: monadic double x * 2
* dyadic times multiply numbers
*. dyadic lcm compute lcm
*: dyadic replica replicate x y times, 0*:5 is 0 0 0 0 0
*.:dyadic make repeat each elt of x by corresponding number in y, 5*.:0 2 2 1 is 5 5 5 5 5
% monadic recip 1 / x
%. monadic sqrt compute square root
%: monadic halve x / 2
% dyadic divide divide numbers
%. dyadic root compute nth root
%: dyadic idivide integer division, 5%:2 is 2
! monadic enum [0, x)
!. monadic odom odometer, !.10 10 is 0 0,:0 1,: ... 1 0,:1 1,: ... 9 8,:9 9
! dyadic mod modulo of numbers
!. dyadic rem remainder of numbers
!: dyadic chunks split x into y-sized chunks, 'abcdefghi'!:3 is 'abc',:'def',:'ghi'
^ monadic shape get shape of an array
^. monadic nlog compute natural log
^: monadic permute generate permutations of x
^ dyadic pow raise number to a power
^. dyadic log compute log(y)/log(x)
^: dyadic bin bin search, 8 9 0^:1 3 5 7 9 is 3 4 -1
| monadic reverse reverse an array
|. monadic round round x
|: monadic depth find max depth, |:,,,1 is 3
| dyadic maxor get max of two numbers (for 0/1s is same as logical or)
|. dyadic rotate rotate array y times clockwise (-y for counterclockwise)
|: dyadic window yields all contiguous y-sized subarrays of x
& monadic where &0 0 1 0 1 0 is 2 4
&. monadic flatten flatten an array, shortcut for ,//. join fold converge
& dyadic minand get min of two numbers (logical and for 0/1s)
&. dyadic insert insert y between elts of x, 1 2 3&.0 is 1 0 2 0 3
= monadic group ='mississippi' is (,0),:1 4 7 10,:2 3 5 6,:8 9
=. monadic occurs count occurences of elts, =.'Hello World!' is 0 0 0 1 0 0 0 1 0 2 0 0
=: monadic assign assign unique index to each unique elt, =:'Hello World!' is 0 1 2 2 3 4 5 3 6 2 7 8
= dyadic equals yields 1 if x equals y, 0 otherwise
=. dyadic mask mask one array in another, 'abxyzabayxxyabxyk'=.'xy' is 0 0 1 1 0 0 0 0 0 0 2 2 0 0 3 3 0
=: dyadic match rank 0 version of = equals, 1 2=:1 2 yields 1
< monadic pred x - 1
<. monadic floor round x down
<: monadic ungrade indices of array sorted descending
<.:monadic unsort sort x descending
< dyadic less yields 1 if x < y, 0 otherwise
<. dyadic lesseq (x=y)|(x<y)
<: dyadic nudgel shift elts of x to the left filling gap with y
> monadic succ x + 1
>. monadic ceil round x up
>: monadic grade indices of array sorted ascending
>.:monadic sort sort x ascending
> dyadic greater yields 1 if x > y, 0 otherwise
>. dyadic greateq (x=y)|(x>y)
>: dyadic nudger shift elts of x to the right filling gap with y
# monadic length count of elts/rows in an array
#. monadic unbits #.1 0 1 is 5
#: monadic bits #:5 is 1 0 1
# dyadic take 1 2 3#2 is 1 2 1 2 3#-2 is 2 3
#. dyadic reshape change shape of x to y, 1#.3 3 is 1 1 1,:1 1 1,:1 1 1
#: dyadic buckets group x into buckets according to y, a b c d e#:0 -1 -1 2 0 yields (a,.e),:(),:(,0)
~ monadic not logical not, nil () 0 are not truthy, everything else is truthy
~. monadic atan atan(x)
~: monadic sign sign of x, -1 for negative, 0 for 0, 1 for positive
~ dyadic noteq ~(x=y)
~. dyadic atan2 atan2(x, y)
~: dyadic notmat rank 0 version of ~ noteq
_ monadic exp e^x
_. monadic nub mark unique elts, _.'abracadabra' is 1 1 1 0 1 0 1 0 0 0 0
_: monadic factors compute prime factors of x
_ dyadic drop 1 2 3_2 is (,3), 1 2 3_-2 is (,1)
_. dyadic cut 'abcdef'_.0 2 is 'ab',.'cdef'
? monadic unique distinct elts of x
? dyadic find find all indices of y in x
@ monadic abs |x|, absolute value of x
@ dyadic at get elt from array by index
@. monadic behead all elts of x except first
@. dyadic member 1 if x contains y, 0 otherwise
, monadic enlist puts x into 1-elt array
,. monadic enfile same as , enlist but with infinite rank, ,.1 2 3 is (,1),:(,2),:(,3)
, dyadic join concat arrays
,. dyadic pair puts x and y into an array
` monadic const yields function that always yields x
`. monadic symbol cast x to a symbol
` dyadic apply1 call x with argument y
`. dyadic apply2 call x with arguments from array y, (+)`.2 2 is 4
$ monadic string string repr of x
$. monadic shuffle shuffle an array
$: monadic do eval string x as expr
$.:monadic repr try repr x as doable string
$ dyadic cast cast x to the type of y
$. dyadic implode join x with delim y
$: dyadic format format template, 1 2 3 4$:'{0}+{1}*{-1}+_' is 1+2*4+1
[ monadic fact compute factorial
[: monadic prefix prefixes of x, [:1 2 3 is (),:(,1),:1 2,:1 2 3
[ dyadic left yields x
] monadic same yields x (i.e. identity)
]: monadic suffix suffixes of x, ]:1 2 3 is 1 2 3,:(2 3,:(,3),:()
] dyadic right yields y
a. dyadic band bitwise and
e. monadic eye identity matrix of size x
E. monadic exit exit with exit code x
f. monadic selfref ref to current function or rhs of : bind
f. dyadic selfref same as f. selfref, but dyadic
i. monadic iota [1, x]
i. dyadic range [x, y] (also works for chars, e.g. 'a'i.'z')
I. monadic read read file
I. dyadic write write file
o. dyadic bor bitwise or
p. monadic print print x
P. monadic println print x and then print \n
r. monadic deal pick random element of x
r. dyadic roll roll xdy (y is 0-based, so >xr.y for 1-based)
s. dyadic shl x<<y
S. dyadic shr x>>y
t. monadic type type of x: arr=0, verb=1, symbol=2, num=3, char=4, nil=5
x. monadic bnot bitwise not
x. dyadic xor xor numbers
y. monadic system exec system command (yields output)
y. dyadic system exec system command with input
f/ fold +/1 2 3 yields 6
xf/ foldwith 1+/1 2 3 yields 7
f/. converge _}1/.1 2 3 yields ()
xf/. eachright 1-/.1 2 3 yields 0 1 2
f/: span =}' '/:'x y z' yields (,'x'),:(,'y'),:(,'z')
x f/: repeat 5*}2/:1 yields 32
f\ scan +\1 2 3 yields 1 3 6
xf\ scanwith 1+\1 2 3 yields 1 2 4 7
f\. converges _}1\.1 2 3 yields 1 2 3,:2 3,:(,3),:()
xf\. eachleft 1-\.1 2 3 yields 0 -1 -2
f\:x eachrank #\:1 1#.2 3 yields 3 3, #\:inf1#.2 3 yields 1 1 1,:1 1 1,:1 1 1
xf\:Fy if 1(+\:+)2 yields 2
f" each >"1 2 3 yields 2 3 4
xf" merge 1 2 3,"a b c yields (1,.a),:(2,.b),:(3,.c)
f". eachprior -".1 2 2 3 5 6 yields 1 0 1 2 1
xf". eachwith 0-".1 2 2 3 5 6 yields 1 1 0 1 2 1
xf": stencil 3+/":!10 yields 3 6 9 12 15 18 21 24
f&: filter >}0&:-2i.2 yields 1 2
f?.x pick >}5?.((*}2),.<)"3 6 yields 6 5
f?:F while <}5?:> 0 yields 5
f`:F trap >`:(:x]err)"5,.a yields 5,.type
f;F atop */;i.5 yields 120
f;.x self *;.5 yields 25
xf;.y swap a,;.b yields b a
f;:F monaddyad -;:+5 yields -5, 1-;:+5 yields 6
f{x before -{1 5 yields -4
f}x after +}1 6 yields 7
lb.r bond same as l;r if l & r are verbs, l}r if only l is verb, r{l if only r is verb
f@:Fvx fork (fx)vFx
xf@:Fvy fork (fx)vFy
f{.Fx atopleft (Fx)fx
xf{.Fy atopleft (Fx)fy
f{:Fx atopboth (Fx)fFx
xf{:Fy atopboth (Fx)fFy
f}.Fx atopright xfFx
xf}.Fy atopright xfFy
f}:Fx together (xFx)fxFx
xf}:Fy together (xFy)fxFy
f[.Fx overleft (xFx)fx
xf[.Fy overleft (xFy)fy
f].Fx overright xfxFx
xf].Fy overright xfxFy
inverse of a function f is a function ~f that undoes the effect of f
f:.~f obverse insert inverse ~f for f
f-:x inverse ~fx
xf-:y inverse (~fx)~f~fx
f-.:Fx under ~FfFx
xf-.:Fx under ~F(Fx)f(Fx)
self-inverse: + - % | ~ ]
*/ _: +. %. * ,
_: */ %. +. , *
*: %: ^. _ <.: >.:
%: *: _ ^. >.: <.:
< > #. #: +;. %:
> < #: #. *;. %.
$: $.: <: >:
$.: $: >: <:
,;. *x!:%:#x ,.;. *
! >;|/ i. |/
>;|/ ! |/ i.
/ examples
/ arithmetic mean
avg:+/%#
/ geometric mean
gmean:avg-.:^.
/ compute factorial (analytic)
fac:*/i.
/ compute factorial (recursive)
facr:<.}1?.(*}.(f.<)),:(\`1)
/ compute nth fibonacci number (iterative)
fib:*x+\;|/:!2
/ filter zeroes from an array
rmz:@}.(&;~}0)
/ sort array ascending
sort:@}.>:
/ sort array descending
sort:@}.<:
/ check if a number is prime
isp:2=+/0=x!i.x
/ remove consecutive duplicates
rcd:x*.:1~:".x
/ check if given array is palindrome
ispal:|=:]
Downloads