Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Concatenative K (nsl.com)
44 points by memorable on July 19, 2022 | hide | past | favorite | 6 comments


Jeremy Howard of fast.ai has started a little study group for array languages.

https://youtu.be/CGpR2ILao5M

https://forums.fast.ai/t/apl-array-programming/97188

APL, J, K, etc don’t seem to get wide traction but have a devoted niche.

After watching his first several videos, I started learning a little APL and J, using browser playgrounds:

APL: http://tryapl.org/

J: https://jsoftware.github.io/j-playground/bin/html2/#


Unrelated, but there's also an online playground for ngn/k (the only open-source implementation of K6 AFAIK):

https://ngn.codeberg.page/k/


When I designed the Klong language (http://t3x.org/klong/), the first version was a concatenative language. It still is internally! You can see the translated program when starting the interpreter with the debug (-d) option. While concatenative style is really cool, I preferred the brevity of K syntax in the end.


ck.k was my first attempt to design a concatenative language with array semantics.

much more interesting in my opinion is the XY language, here:

https://nsl.com/k/xy/xy.txt

XY contains the primitives of k + 9 core primitives, in terms of which all the stack operations of joy can be defined:

        ->      queue           [X^z Y] -> [X z]
        <-      stack           [X^z Y] -> [z Y]

        =>      cache           [X^z Y] -> [X Y^z]
        <=      uncache         [X Y^z] -> [X^z Y]

        /       use             [X^z Y] -> [X z,Y]
        \       mention         [X z^Y] -> [X^z Y]

        `       enclose         [X^z Y] -> [X^{z} Y]
                disclose        [X^{z} Y] -> [X^z Y]

        (       stack*          [X Y] -> [X^[X] Y]
        )       queue*          [X Y] -> [X^[Y] Y]
i've implemented the following modules:

        stack           the basic Joy stack words, e.g. 'dup'
        list            list manipulation words, e.g. 'cons'
        general         general operators, e.g. 'pred'
        predicates      predicates, e.g. 'false?'
        queue           queue manipulation words, e.g. 'clear'
        monads          keywords for K monads, e.g. 'where' for '&:'
        dot             K amend and dmend
        adverbs         XY definitions for K adverbs, e.g. 'each/'
        joy             XY definitions for Joy combinators, e.g. 'linrec'
        call            call with current/partial continuation
        io              input-output convenience words
        misc            miscellaneous


Doesn't work with ngn/k or kona, looks to be based on a really old version of k, but still, this is really cool. The underflow behavior looks interesting, but also like it might be annoying compared to just failing.


Here’s another although not written in K.

https://github.com/smabie/xs




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: