the k tree

https://app.element.io/#/room/#ngnk:matrix.org
644d ago – ngn
71

export all events for this room

Starred posts

ngn
Sep 8, 2021 17:39
@xpqz the keys can be a list of anything you like
Sep 3, 2021 06:05
this is probably the most cursed k thing i've seen
ngn
Aug 26, 2021 18:55
@coltim if f has arity>1 and it matches the number of args passed to f/ then f/ applies f by feeding back the previous result as the first arg and "zipping" the rest of the args
Aug 6, 2021 16:25
wonderful! attempting to exercise some restraint, I've limited them to things present in at least one other K implementation:
https://ngn.bitbucket.io/k/#eJyFVMFuGjEQve9XvNIegkK6y0JCwjZV7pV6zSFCkfEO4OK1LdubsFJ/qr/QL+t4CUmbogQJ8I498968ed48q5WMyhrhO9TeurwmTZEQH0lss+s3PhmgcI+Uj+uvfTJWyofIYU/S+jqMeBFbbxC9ahqq+8MZJzpPgQyfNHNspyPYbyNsZ/y9SrvR7qsJwwcircljS90IbaA5b2OPeY/dMy5v5w9CtwQnlMejipsUwy7LMuGXKvrU3+NGRQpOSOK6CBw0dXizx32bu/lJCUyAKXAOXPQcMAMugSuMC4zHw+NdcVC23nNQd3Mcinxh2iVu+OEG05TIja1ajZX1c0hbE4RWa9NwWs6xRsSozJpbacSWzrRiiZ23P6gf3FH+e9LjqhreldVkkXQaM+Tkf5av4PvWpDWBQcjIbi/lqjU91t+wWXaYjTIrZVRUdEx
ngn
Jul 18, 2021 05:39
@chrispsn i'm proud of the _( ) macro defined as {return({ });}. i use it for the bodies of functions to avoid an explicit return. the last expression is automatically returned.
Jul 16, 2021 00:39
this is what I had: https://ngn.bitbucket.io/k/#eJxdUsty0zAU3fsrFBNaO4lHSUuh2CEP3u/3O00dNxGJWkd2bTmR2+ApG6bAdFtmYBgeQ2HLiu5Y0D/JF/QTuLIZOsPGks4599zjKzVNtXn23PkLFy9dvnL12vUbN2/dvnP33v0HDx89fvJUVRxTdVa6PfKsP1ila+6Qef56EPJoNBbxhqowUy1X5uZPLJw8tXhaVbTpizembqpLTMUIr3qUoTHlA8TI2KWMhIr2+7vkkbqEMPfWCKMbRNEOP+7+BLiDyibCfkAZVxTtYF83jyPcoyO5B7pysI8wZSMShFAz3doFbFNMDPEcYWcl9NyIEzRy3ChlvwGZb1Wqx2LLawmrELdLFTu2NFGL9YmJNTET68VcpQg+wojb4BE4rJ+Vmmltx00atrC0htDzOdjkOjz2pRAW0jM4dSHYW6kF07JuiGoZyJD2WTSE/NNXX3UzqSHskjA0+MBhBlmPHDdl0uiNaho97EpoD8RVhPsBcTgJ/tPvZfqa1PdIVvAJCs4gzDyO/um2ZZjsj3ToUiHGYhE+CwXAYtnL9wNP0
Jul 11, 2021 02:09
@tosh k5/k6 explicitly switched the argument order. It's actually a very good choice, since most of the time in practice the divisor is a fixed number and the dividend is a more complex expression. This ordering reduces the number of parens and makes programs flow more nicely
ngn
Jul 9, 2021 13:44
for instance now #'() is !0 but {#x}'() is () because the interpreter is not clever enough to figure out that {#x} always returns ints
ngn
Jul 4, 2021 20:53
started a wiki page on grammar
Jul 4, 2021 06:34
@Razetime github.com/JohnEarnest/ok/blob/gh-pages/docs/Programming.md and github.com/JohnEarnest/ok/blob/gh-pages/docs/Trees.md may be of general interest. My blog also has a few articles demonstrating/discussing algorithms in (o)K: beyondloom.com/blog/index.html
Jun 30, 2021 04:49
how the fuck does that work
Jun 26, 2021 17:05
Jun 26, 2021 08:57
ngn
Jun 23, 2021 12:26
"K4 is a much simpler and smaller language than APL" - definitely, any dialect of k vs apl

"programs come out simpler" - yes, fewer concepts to learn. fewer historical traps to fall into. a culture of rigorously boiling things down to their bare essence instead of piling up language features and refusing to fix old mistakes for "backwards compatibility"

"and shorter" - depends, maybe. in my experience k programs typically golf down to about 1/4 *more* characters than apl, which is what you would expect if you take into account the number of valid input characters or primitives available i
Jun 23, 2021 11:44
apl has multidimensional arrays, ranks, etc. k only vectors and atoms. apl operators have a dyadic version, which k does not. e.g. x f op g y. op takes f and g to create a new verb, that now takes x and y as arguments.
besides the basic language, both apl(e.g. dyalog) and k4/q have extensions.
Jun 23, 2021 09:34
@Razetime have you seen ktye.github.io/j.html ? see the examples at the bottom. they use wasm to js/canvas. the "plant" example also has a mouse click callback.
Jun 22, 2021 22:21
improving expressiveness often pays for itself
Apr 24, 2019 13:31
the birth of a new language, how exciting
2
Jun 18, 2021 22:04
the idea of being able to separate values from their hierarchical structure is very powerful
Jun 18, 2021 21:40
Recursive algorithms typically mean recursive data: nibbling at things in tiny bites, lots of interpretive overhead, and horrific cache coherency. Just as vector languages eschew explicit loops, explicit recursion should be viewed as boilerplate. Abstract recursion is better whenever you can get away with it
Apr 12, 2019 20:38
Mar 30, 2019 01:04
I really tried to capture a bit of the "why" behind the more unusual features in the K toolkit. where/grade/group/encode/decode are sort of the crown jewels of array programming
2
Mar 30, 2019 00:39
it's lonely at the top-bottom
2
May 25, 2021 02:20
Mar 10, 2021 08:20
@ngn to increase adoption for ngn/k i suggest: 1. split into main and libk, 2. allow custom implementations for os interface, your syscalls as one example. 3. allow external functions to use k types and assign to k variables (as funcs) no need for built ins, maybe a new native function type. 4. things like http server should be a stand alone implementation using libk (no stdin/out with text). 5. ffi is not necessary anymore.
Feb 11, 2021 07:53
there is http://effbiae.com/parserclub/ which contains versions in c and k. of course it's not a fully working system, but shows the principle. nsl.com has many more about parsing k, but i never understood these (or didn't try enough to).
i have one file (used for learning) here: github.com/ktye/i/blob/master/_/i3/w/p.go
ngn
Jan 25, 2021 12:46
@chrispsn in a nutshell: i believe that the strange "rank-sensitive" definition of ? was motivated by a desire to have @ and ? work as mutual inverses, to the greatest extent possible
ngn
Jan 15, 2021 20:27
for instance if you index a cube (3d array) with cube[i;j;k] where i j k are int lists, you should get a (smaller) cube as result
Jan 11, 2021 21:33
had another idea for an overload: str?sym, which would do string search (returning the index of the first match)
Dec 20, 2020 02:47
Using them as bitmasks, either to flag nulls or to do the SIMD/data oriented control flow thing is interesting (e.g. AVX512 has a separate set of mask registers; the result of comparisons are stored there, and pretty much any instruction can be passed a mask register to change which lanes it operates on)
Nov 7, 2020 00:58
I just wrote an assembler for fun 8 years ago and things got extremely out of hand
ngn
Oct 31, 2020 18:20
you could also do something like . x@=x-!#x
Aug 24, 2020 21:36
@chrispsn it makes some sense if you look at the binary representation: control codes start with 000, numbers and symbols with 001 (numbers at 0011), caps with 010, small with 011. there are some more questionable choices with the gap filling (eg: the symbols between Z and a, or after z), but in general it has a quite clear structure
Aug 11, 2020 17:03
@chrispsn I was reasonably pleased with the size of speciak-K's recursive-descent parser. the tokenizer still has an ugly hack for minus disambiguation and depends on fairly rich regular expressions. There are many ways to make tokenization simpler, but less compact in JS.
May 19, 2020 16:45
"open source q" -> http://www.timestored.com/jq/
running on the jvm .. interesting
May 18, 2020 21:25
@cannadayr iKe has its own drawing interface. Your code generates a list of tuples which describe either drawing filled polygons or bitmaps, which can be constructed in any way you wish. The implementation happens to be built on top of the HTML5 Canvas element. You can see documentation for iKe here: github.com/JohnEarnest/ok/tree/gh-pages/ike#output
May 4, 2020 19:30
specifically, oK draws totally unnecessary internal distinctions between verbs and adverbs, and the parser is really ugly. amend/dmend are also quite weird but they would be quite hard to fix because so much relies on them.
May 4, 2020 19:20
@coltim I think dyalog's dfns represent absorbing one of the best features of K that APL was sorely lacking: first-class anonymous functions. Old-style APL procedure definitions were hideous and clearly not-fully-baked
May 4, 2020 19:08
I think K sometimes suffers from a very rigid set of primitives for dealing with the outside world. Older versions of K had lots of trouble working with files that were not shaped like a CSV or fixed-field table, and even modern K interpreters rarely expose a pleasant interface to raw TCP/UDP sockets. I think K would be more suitable for attacking "messy" problems if it had better data parsing/formatting capabilities
May 1, 2020 19:04
I think that if a programming language is to be considered a language- a means of expression- locked-down proprietary implementations are unacceptable. I'm deeply frustrated by the fact that so many of the leading APLs are commercial products.
Apr 20, 2020 17:22
maybe it would be nice for !scalar to use the prototype of the argument- (!0x3)~0x000102 (!3.0)~0 1 2.0 etc
Apr 13, 2020 09:00
k tech tree... may not finish but as a thought experiment am interested in how far one can get with k-strings (mostly) alone. feel free to contribute. much gratitude to ngn's open-source ngn/k code gist.github.com/chrispsn/b1020918a83a28ab8b4442d8aff8d1b4
ngn
Apr 7, 2020 17:10
when i have a while loop like this: a:..;r:{condition}{body}/initial (pre-k7 syntax) where condition and body make use of a, and i want to wrap it in { }, the best way i found is this: {.. (a;r):({[a;x]condition}.){[a;x]body}//(a;initial) ..}
ngn
Mar 29, 2020 19:22
@ktye ?x is {x@&(!#x)=x?x} now
Mar 28, 2020 15:13
ktye's "spacey verb" proposal can be generalized by adding the "transform" syntax category.

there are two transform functions: raise { and lower }. i call them "elevators", and their purpose is to raise or lower the syntax category of their operand.

elevators have higher type than adverbs, and they bind tightly to the right:

}/

turns / into a verb.

{}/

turns / the verb of / into an adverb.

{/

is a no-op, as is

}3

you can find a 2x2 parser for k with transforms here:

http://nsl.com/k/ski/p.k
Mar 28, 2020 07:47
@beagle3 i made the following suggestion:
"spacy verbs" add 1 thing and remove 4 from k

(space)(')(1 char) is parsed as a verb.
the name comes from "space-each".

think of % as a special case of '%

1) io verbs need no special case any more
'0 instead of 0:

2) extensions such `p@ are true verbs now, dyadic cases are possible
'p"1+2"

3) built-ins could be replaced by it (unlikely)

4) user extensions (c/k.lib) could add function pointers: 0-9 a-z A-Z
monadic/dyadic
1 2 'u+!10
Mar 21, 2020 13:56
a new paper from john earnest: beyondloom.com/blog/strings.html