1
0
Fork
You've already forked gk
0
cosmopolitan version of cmh's gk vector language
  • C 99.3%
  • Shell 0.3%
  • Makefile 0.2%
  • Batchfile 0.2%
Find a file
2025年12月19日 09:34:53 -06:00
doc bugfixes 2025年12月18日 18:48:12 -10:00
etc ape 2025年12月19日 09:32:24 -06:00
k.core ape 2025年12月19日 09:32:24 -06:00
t bugfixes 2025年12月18日 18:48:12 -10:00
.gitignore ape 2025年12月19日 09:32:24 -06:00
aes256.c centralize memory management 2025年12月13日 13:28:49 -10:00
aes256.h v1 2025年12月07日 13:03:23 -10:00
av.c bugfixes 2025年12月18日 18:48:12 -10:00
av.h v1 2025年12月07日 13:03:23 -10:00
b.c make room for rx bits 2025年12月12日 23:56:24 -10:00
b.h v1 2025年12月07日 13:03:23 -10:00
dict.c variable lookup cache 2025年12月13日 20:44:03 -10:00
dict.h v1 2025年12月07日 13:03:23 -10:00
fe.c v1 2025年12月07日 13:03:23 -10:00
fe.h v1 2025年12月07日 13:03:23 -10:00
fn.c bugfixes 2025年12月18日 18:48:12 -10:00
fn.h v1 2025年12月07日 13:03:23 -10:00
h.c v1 2025年12月07日 13:03:23 -10:00
h.h v1 2025年12月07日 13:03:23 -10:00
io.c map flag 2025年12月12日 23:32:02 -10:00
io.h v1 2025年12月07日 13:03:23 -10:00
irecur.c irecur 2025年12月17日 20:18:22 -10:00
irecur.h v1 2025年12月07日 13:03:23 -10:00
k.c bugfixes 2025年12月18日 18:48:12 -10:00
k.h v1 2025年12月07日 13:03:23 -10:00
la.c v1 2025年12月07日 13:03:23 -10:00
la.h v1 2025年12月07日 13:03:23 -10:00
lex.c make room for rx bits 2025年12月12日 23:56:24 -10:00
lex.h v1 2025年12月07日 13:03:23 -10:00
LICENSE v1 2025年12月07日 13:03:23 -10:00
lzw.c centralize memory management 2025年12月13日 13:28:49 -10:00
lzw.h lzw 2024年08月07日 21:57:08 -10:00
main.c v1 2025年12月07日 13:03:23 -10:00
make.bat v1 2025年12月07日 13:07:44 -10:00
makefile ape 2025年12月19日 09:32:24 -06:00
md5.c v1 2025年12月07日 13:03:23 -10:00
md5.h v1 2025年12月07日 13:03:23 -10:00
ms.c centralize memory management 2025年12月13日 13:28:49 -10:00
ms.h v1 2025年12月07日 13:03:23 -10:00
p.c bugfixes 2025年12月18日 18:48:12 -10:00
p.h v1 2025年12月07日 13:03:23 -10:00
pnp.c v1 2025年12月07日 13:03:23 -10:00
pnp.h v1 2025年12月07日 13:03:23 -10:00
README.md README 2025年12月19日 09:34:53 -06:00
repl.c v1 2025年12月07日 13:03:23 -10:00
repl.h v1 2025年12月07日 13:03:23 -10:00
scope.c cleanup 2025年12月14日 00:12:53 -10:00
scope.h variable lookup cache 2025年12月13日 20:44:03 -10:00
sha1.c v1 2025年12月07日 13:03:23 -10:00
sha1.h v1 2025年12月07日 13:03:23 -10:00
sha2.c v1 2025年12月07日 13:03:23 -10:00
sha2.h v1 2025年12月07日 13:03:23 -10:00
systime.c v1 2025年12月07日 13:03:23 -10:00
systime.h v1 2025年12月07日 13:03:23 -10:00
timer.c v1 2025年12月07日 13:03:23 -10:00
timer.h fix warnings on mac 2024年01月19日 18:00:09 -10:00
unistd.h v1 2025年12月07日 13:03:23 -10:00
v.c bugfixes 2025年12月18日 18:48:12 -10:00

bleedsa/gk

a fork of cmh25/gk built to run under cosmopolitan libc.

v1 release notes

note: v1 is a full rewrite of gk. It has breaking changes from v0. The v0 branch remains available.

gk is an implementation of the k programming language, originally invented by Arthur Whitney.

It's loosely based on k3, but with some changes suggested by Stevan Apter.

Other notable open source implementations of k or k-like array languages.

build instructions

linux/mac:

etc/cosmo.sh
make
make test

gk differences from k3

verbs

The verbs are all like k3. However, there is no "force monadic" (ex: #:'). The valence of primitive verbs (including composition) is always determined from context. A few examples:

 #'(1 2;3 4 5)
2 3
 !'2 3 4
(0 1
 0 1 2
 0 1 2 3)
 *'("ab";"cd";"ef")
"ace"
 (%-)'1 2 3
-1 -0.5 -0.3333333

adverbs

The adverbs are similar to k3, but /: \: ': are gone. The only adverbs are / \ '. How they operate depends on the context and the valence of the modified verb. Here's a quick synopsis:

each f'x
each x f'y
each f'[x;y]
each f'[x;y;z]
scanm f\x
do n f\x
while b f\x
eachleft x f\y
eachleft f\[x;y]
scand f\x
scan f\[x;y;z]
overm f/x
do n f/x
while b f/x
eachright x f/y
eachright f/[x;y]
overd f/x
over f/[x;y;z]
eachprior ep[f;x]

slide

slide is an enhanced version of eachprior from k3 (aka eachpair).

_[n;f;a]

The first argument is a positive or negative integer. Its sign indicates the order the arguments are passed to the modified verb. Its absolute value indicates the number of steps the sliding window moves each time arguments are taken. The second argument is a verb. The third argument is a vector or list. These examples should make clear how it works:

 _[1;,;"abcd"]
("ab"
 "bc"
 "cd")
 _[-1;,;"abcd"]
("ba"
 "cb"
 "dc")
 _[2;,;"abcd"]
("ab"
 "cd")
 _[-2;,;"abcd"]
("ba"
 "dc")

The case of _[-1;f;a] in gk is equivalent to f': a in k3. gk also has a builtin for eachprior.

 ep[,]"asdf"
("sa"
 "ds"
 "fd")

no underscore in names

Underscores are not allowed in variable names. It makes things cleaner since there is no longer a need to have space around the drop/cut verb.

 a:1
 b:1 2 3
 a_b
2 3

Most of the reserved names from k3 are still there, but with the _ removed.

 draw[10;10]
7 2 7 6 6 3 6 2 5 8
 1 2 3 dv 2
1 3
 2 vs 5
1 0 1

Some single-letter names have changed.

k3 gk
--- ----
 _n nul
 _P .z.P
 _T .z.T
 _f .z.f
 _h .z.h
 _i .z.i
 _t .z.t

$ replaces : in cond

 $[0;`a;`b]
`b
 $[1;`a;`b]
`a