« first day (732 days earlier)      last day (803 days later) » 

2:26 AM
Hi, new to the K room, usually in APL orchard
Is there a way to define a recursive function within limited scope like this:
primes:{f:{$[(y<z)&p[x;y];f[x,y;y+2;z];(y<z);f[x;y+2;z];x]}; f[2 3;5;x]}
when running this code, I get value error f
 
where is z coming from?
I think that might be causing it
nvm
 
no this works without f, and if f is called primes instead
primes:{$[(y<z)&p[x;y];primes[x,y;y+2;z];(y<z);primes[x;y+2;z];x]}
I should say, it works, but only below a certain threshold input value
primes[2 3; 5; 100]
for instance works just fine
primes[2 3;5;60086] I get another error 'stk
which I can only assume means I'm blowing the stack
so how do I avoid the stack overflow here?
 
what is p in these examples
 
p:{&/~0=x!\:y}
y not divisible against each x
this is NGN k
btw
in kona I get "valence error"
not sure what that means
 
it's worth noting that no K interpreter I am aware of performs tail-call elimination. Recursive procedures are generally not idiomatic.
 
2:37 AM
oh, the ! is reversed
 
in general, a valence error means you are applying the wrong number of arguments (probably too many) to a function
 
I'm familiar with the limit adverb applied to fibonacci
but not sure how to apply that to this case
@JohnE not very lispy
 
K is not lisp
your original example appears to work in oK; seems like this could be a difference in how ngn/k handles lexical scope (or doesn't)
 
there was a conversation about that in the apl orchard the other day
@JohnE @ngn is this what you were discussing with @dzaima about lexical scope?
 
traditionally K interpreters have either not had lexical scope at all or they only supported a single layer of closure.
 
2:42 AM
{f:{:[x>0; x+f x-1;0]}; f x}10
19
kona doesn't either
 
I don't think arthur has ever bothered with full lexical closure. I have it in oK because it was barely any extra work when I'm implementing it in a managed language
 
I've tested this with f at the root scope, and it works just fine
you're the OK implementer?
 
that's me
 
noice
is there a way to interact with node libraries from OK?
can I start a server, make a request, write / read from various IO?
 
not out of the box. The oK interpreter itself has no IO at all. It would be possible to create a "frontend" for it which exposed features like that.
 
2:46 AM
what about the inverse?
 
invoking oK from node? That's essentially what the built in CLI repl provides
 
so theoretically, I could do my business in node, and make calls to ok ?
set up sockets, read and pipe the data to k functions?
 
if you really, really wanted to run your code on the second-slowest k interpreter in the world
 
what's the slowest
 
is slow for k slow for standard JS?
what are your benchmarks for OK vs JS
 
2:50 AM
the slowest is probably internet-janitor.itch.io/applejak
assuming you consider it a K interpreter at all
 
oh cool
 
@JohnE what I'm interested in is actual work. which means I need data, and that data has to come from somewhere. Dyalog's IO is usable if inelegant, I can at least write small wrappers around my problems, but its liscenced so I'm probably not going to use it for real work. Same with any production K, so that leaves the F/OSS and other OSS implementations, I could use J perhaps
but compared to K or APL J is... inelegant?
so, which of the APLs provides what Dyalog does? .... none
so, what open source K's provide FFI for C, or some other means of external communication? .... mmmmmmmmmmmmmm, I'm trying to find out
 
oK is implemented in JS and could be expected to run at least hundreds to thousands of times slower that whatever JS engine is being used to run it. Amazingly, even so, it is fast enough to run various interesting graphical demos and so forth. I consider oK a good tool for learning, and it is free software, but I wouldn't consider it robust or fast enough for any meaningful industrial application.
 
it seems like KONA at least provides reasonable file IO, some C capabilities if not easy to find (in the user group)
but KONA also seems to be "missing?" primitives I'd expect from something like APL
like, is there even a sliding window reductioN?
I can't find it if its there
the documentation is also extremely unclear as to how to do certain things
but its looking like KONA is my only solution, or contributing to NGN K
 
imo the most productive things to come out of oK are 1) people seem to like the documentation, 2) iKe proved that K can be applied to graphics programming, and 3) oK has been used by various people as a reference when writing better open-source K implementations like ngn/k
 
2:57 AM
I've seen ngn's table of K's
are there others worth looking at?
 
I believe ngn/k is presently the most actively maintained and performant open source K
 
I reached out to Kx some 3 years ago to see if an older veresion could be procured for research, and the answer was emphatically NO
@JohnE "performant" on golfing problems that don't interact with external data sources? Or are there actual application benchmarks?
is KONA not performant?
are there benchmarks comparing KONA to ngn?
sorry to be hammering you... just this information feels like pulling teeth to find
I get that K users tend to be terse, implying abruptness, and the documentation (sometimes helpfully) reflects that, but getting fully formulated english sentences expressing fortitude of thought past the "abruptness" of the immediate point is difficult to find
And having this information up front will make it much easier to make a decision to jump ship to one impl or another for some language. What I don't like is constantly having to learn a new impl or language just to realize it doesn't do the thing I want/need to do
 
kona and ngn/k are two different dialects of the language. Kona is based on k2/3, while oK and ngn/k are based on k5/6. This is why their syntax varies in small ways and their collection of primitives and overloads varies. Kx's KDB+ is based on k4, which is yet another dialect. It takes a considerable amount of work to adapt benchmarks across these linguistic gulfs, and the only people working on open-source K stuff are volunteers and hobbyists
 
so you're saying "get some quotes".... but even then K4 is proprietary from what I've read. you can liscence Q but not K4
and shakti doesn't feel very array oriented
but then I haven't played with it for more than a few hours trying to just figure out the differences from what little I am able to do in K at present
but from what I recall i was able to pull data in from a mongo database at work in short order using Q
maybe I should just look at their actual pricing... but I can only imagine its meant for people making actual money, not for people wanting to build personal applications
or maybe I should just jump on the bandwagon of "everyone makes their own language" X(
 
3:14 AM
Kx has never made a meaningful investment in open-source and hobbyist applications, which I think is slowly dooming the language. Even a fantastic tool is at best a questionable engineering choice when compared to the dozens of high-quality free and open source languages it competes against.
Last I checked you can still get free evaluation copies of kdb+; you can escape from the q prompt to get to k4, but it's kind of annoying to use, since it kicks you back into q whenever you encounter an error.
 
There's a fortran on every platform for every purpose... CL is a fully competent and in some ways still cutting edge language, and yet I can't find an APL-family language equally capable of catering to modern programming
J is probably the best option
but I just literally can't even with J
I wrote a few little command line scripts with it a good few years back
but I just don't have any desire to write J
 
I don't find J very pleasant to read or write, but it does have a fleshed out ecosystem of libraries, bindings, and documentation
 
K at least achieves terseness and APL is elegant. J is... bats
 
doesn't hurt that the official J is open source, and people working on it don't need to be afraid of getting sued
 
3:17 AM
J has all the right ideas in all the wrong ways
3
 
This is depressing
 
it's kinda like F#: a kitchen-sink language full of ideas and experiments, some of which turn out to be footguns
 
there is no language I'd rather use than APL-family languages, but I can't find one worth using
outside of toy/golf situations
if I was running a business and had income from my applications I'd license Dyalog
 
sometimes I think about writing another K and getting the ecosystem-facing stuff right, like standard libraries and general purpose IO interfaces, but I just haven't had the energy for it at all these days
I've been dealing with some stuff
 
I could go off and do language research, and study other implementations and try to build my own, but that's delaying all the other stuff I want to be doing right now
I've done BEEN wanting to do since I started this dang-ol journey 4 years ago
 
3:21 AM
I've thought about trying to write a K inspired language that focused heavily on integration with existing libraries in python and other languages so it could act as a drop in replacement for current code, but with my lack of knowledge that's impossible
 
@rak1507 there's py integration and a swath of other language interop with shakti
but $$
 
yeah, exactly
$$$$
 
the model needed to change back when they were implementing J
 
very few people will shell out to replace perfectly working python code with maybe slightly faster k stuff
 
but then they made J
 
3:23 AM
the problem with piggybacking on another language is you pull in all that language's baggage and dependencies, and you don't really benefit your own ecosystem by focusing on passing the buck to e.g. python
 
I think the Clojure model has it right, you implement a LISP inside an environment that has everything you need to do business, and you keep the core of the language tightly controlled and restricted from adding things, relying more on providing library extensions to the core language
 
if it was moderately painless to transition, more people would do it, relying on something like pypi or npm is a terrible idea but it should at least be possible to use stuff in the short term
 
"short term"
 
well yeah realistically people would probably end up using that forever and making legacy code but I don't like to think about that
 
If I know the software industry, people find the first way that works and never change their approach unless management forces them
 
3:25 AM
think about how many languages have a crude wrapper for SDL2 or whatever and the documentation is basically "lol just read the C docs, hope you're intimately familiar with C as well as how our FFI system mangles the signatures of everything"
 
Julia has a useable C FFI
chat.stackexchange.com/transcript/message/57280860#57280860 This though, an implementation of an array language such that I can straight call external methods as if they were native function calls is the right way to handle a language implementation in current year
the .NET "bridge" in Dyalog is nice.... to have, if you're busy wanting to turn your APL into OOPL
but clojure doesn't force any kind of OOP, you import java libs the same way you import clojure libs, and you call them like clojure functions
 
the traditional approach for C interop from K is "use k.h, write some C functions that take and produce K objects, deal with whatever marshaling and memory management needs to happen on your own, and then you can load those functions from a DLL to get K-callable functions." ie you're on your own and constantly wishing to know more about the implementation of a black box.
 
I really think an array notation is best embedded into the syntax of another language, rather than a language unto itself
 
if you want things to be automatic and magical you have a serious round-peg-square-hole situation adapting the builtin types of a dynamic managed language to the type system of C
ah, the classic "what if k were like regexes" gambit
 
3:32 AM
a DSL called as a library from some general-purpose "real" language
 
I think more what I'm referring to is if mainstream languages would bother to learn the lessons of array languages and actually provide array notation, like how they all seemed to learn the lessons of LISP and FP between 07 and 2014
What I'm really after is a universal programming notation, rather than some kind of dogmatic stubbornness about what constitutes a "real language" or an "array language"
I wish the modern APL community was as much invested in making APL truly general purpose for todays environment, rather than spending so much time worrying about different kinds of functional composition there are
if APL was only DFNS, but it had scripting, it'd be infinitely more viable of a language
if they could stop spending so much time trying to decide on glyphs for this or that kind of function composition and implement real closures, real first class functions, and maybe NORMALISING their 80 years of bloat into a few interfaces, the language would be truly modern
and how is there still a debate around whether dicts are useful? Why is there no effort around a notation for trees or dictionaries? That seems like a more useful effort than a new function composition glyph that'll save 2 or 3 bytes on a golfing problem
¨ might be faux pas but it gets a lot of work done
 
 
9 hours later…
12:41 PM
@nathanrogers on that - most of my interest in bqn is seeing whether it's a better set of primitives than k
With the metric being the minimum of the product of character set count and average golf length across a standard set of problems
Double points if it results in fast(er) code
 
does k have any way to do ⍸⍣¯1 in APL
 
@rak1507 do you have an example?
 
f 1 3 5 -> 0 1 0 1 0 1, f 2 2 3 3 3 6 -> 0 0 2 3 0 0 1
it's the inverse of &
 
Oh right
Something like @[&1+|/x;x;1+]
Nothing built-in
Might need an 'over' with the first arg to ^ as the seed - can't test atm
 
1:01 PM
thanks
 
 
4 hours later…
ngn
4:34 PM
@nathanrogers yes, o is the function you're in, e.g. {$[x<2;1;x*o[x-1]]} /factorial
@JohnE it doesn't, because the original k doesn't. but i wish all ks had full lexical scope.
@nathanrogers "valence" = "arity" = sometimes "rank (of a function)"
@nathanrogers i showed you how to do i/o in k a couple of days ago. remember 0: ?
pretty sure apls other than dyalog had i/o too. i remember reading microapl's docs and the i/o squiggles were something like [←] and [→] (quad arrow)
⍇ ⍈
@nathanrogers do you have experience with ffi in any apl-like language? dyalog has ⎕na, old k-s had 2:. what do you think a good ffi should look like?
ngn/k doesn't use the standard c library, so the biggest challenge for me as implementer is writing dynamic loading from scratch
@nathanrogers what
 
5:15 PM
@ngn File IO yes
@ngn But if you continue reading I mentioned that it is licensed and so I must pay to use it for anything business related. Another thing I mentioned was that the interface for i/o needs to be normalized because so much of it is scattered to the wind with different libraries and difficult to find documentation
@ngn I built a GLFW/GLEW parser that reads in the headers and procedurally generates ⎕NA definitions
@ngn What? We were talking yesterday about how many of the things I've come to expect from other K's, APLs and even J that have no primitives. sure they can be defined, but much of how a language enables you to think is predicated upon what intuitions you can draw from language "primitives", whether those primitives are functions, arrays, lists, macros, blocks, or what-have-you.
 
ngn
@nathanrogers and "shakti doesn't feel very array oriented"??
 
have no primitives? huh?
 
what?
are we doing this again?
@rak1507 that isn't what I said and you know it
 
'We were talking yesterday about how many of the things I've come to expect from other K's, APLs and even J that have no primitives.'
 
ngn
14 hours ago, by nathan rogers
and shakti doesn't feel very array oriented
 
5:21 PM
that have no primitives
what does that mean
 
@ngn because like I said I only had a short time to play with it and I bumped into several mental bumps looking for primitives. The primitives that existmake it feel like the functions want you working with lists, and nested lists or list of lists
@rak1507 oh I see, that was a mental slur... I meant to say its missing primitives that I've come to expect, that's all
 
oh ok
 
@ngn but like I said, its just a first impression
I'm not a K wizard, so all that should be taken as though from the K-scrub that I am
I spent a good portion of the day tinkering with kona/ngn/shakti
so I was just making some first impression comparisons between the 3
 
ngn
i think if it can do 1 2+3, it's array-oriented
 
I think the degree to which you're encouraged to think in arrays of any dimension is variable, and thus lies on a specturm
I'm probably way off the mark, but my first impression was that shakti is less array oriented than other K's/APL/J
 
ngn
5:32 PM
@nathanrogers i agree "it's a spectrum" but disagree about k9 being less array-oriented than its brethren
@nathanrogers any specific examples?
 
where's sliding window?
no rotate?
# no longer reshapes, how do I specify matrices?
 
ngn
@nathanrogers sliding window and rotate are just specific patterns of indexing
 
Right
 
ngn
@nathanrogers shape# can be replaced with a sequence of cuts (n^)
 
" much of how a language enables you to think is predicated upon what intuitions you can draw from language "primitives", whether those primitives are functions, arrays, lists, macros, blocks, or what-have-you."
I can specify a function that defines indices of a "cycle" function, like 20⍴⍳4 or 20#!4 as well
but those are primitives because they're things you want to do all the time
I think an array oriented language, contrasted with perhaps a 1d list oriented language with nice formatting, is inordinately concerned with the "shape" of its data
and so being able to shape on the fly seems pretty important
but maybe that's a mental crutch
i don't know, its just my first impression
 
ngn
5:45 PM
in this particular case k9 trades for (in apl-speak)
idk, you may be right that reshape is more important
on the other hand, cut (n^) already deals with the common uses of reshape
there are many subtle trade-offs to be made in a limited set of primitives, such as k's
in apl or j they would just add a new one and get a bit fatter :)
 
nice graph
top kek
 
 
2 hours later…
ngn
7:36 PM
@Wezl x, y, and z are implicit parameter names, like in apl. but unlike apl's always-ambivalent dfns, k functions have fixed valence. mentioning z makes the function triadic. mentioning y (but not z) makes it dyadic.
 
@ngn what about more than 3 args?
 
mhm
 
ngn
@nathanrogers {[a;b;c;d;e;f;g;h] ..}
at most 8
 
so you have to specify the param list?
it isn't just implied to be x?
 
ngn
@nathanrogers for ≤3 args, you can use x y z without an explicit parameter list
for >3 you must use a parameter list
i don't think i ever needed more than 5
 
7:39 PM
good 2 know
 
7:53 PM
@ngn rest?
 
ngn
@nathanrogers you're asking if k supports rest (that json-over-http thing)?
 
data over http thing yeh. you can send/receive csv or text or xml
 
@nathanrogers you can always provide an explicit argument list, e.g. {[a;b]a+b}, but as @ngn said it's somewhat optional
 
ngn
@nathanrogers i haven't even integrated an http server yet
 
what needs to happen for that?
http server
 
7:57 PM
@nathanrogers you could destructure a list or dict input, something like {(a;b;c):x;a+b*c} or {x[`a]+x[`b]*x`c} but it's probably less idiomatic than explicit args
 
ngn
@nathanrogers what needs to happen is that i stop procrastinating and actually start coding :)
 
:O
well at least you're professional
I'm just an amcrastinator myself
 
ngn
writing an http server isn't hard
writing a fast one is hard
i think geo had published one somewhere..
ah, there. but no licence :(
 
ngn
8:21 PM
@nathanrogers do you think an http server should be part of the language interpreter or something external?
 
like a library you mean?
 
ngn
@nathanrogers more like a separate executable that spawns k when a request comes in, and redirects the request/response to k's stdin/stdout
 
I have no problem with needing to import server related functions. It'd be nice to have on hand
1. load k
2. start server

but
1. load k
2. import server
3. start server

isn't an imposition so long as its mentioned somewhere
@ngn any response to that question yesterday regarding \ ?
 
ngn
@nathanrogers what question? remind me
 
\ exits your k, but I type that by mistake quite a bit, and especially when I forget I'm in your k, not kona, where kona \ returns a list of all potential hellp commands
with a short descriptor
also how do I check for definitions?
 
ngn
8:25 PM
@nathanrogers i have no strong opinion on that. i just did what the original k did (at the time).
 
I find the meta-help list to be indespensible
 
ngn
@nathanrogers would it be better if it was \\ ?
 
I used that kona help menu to learn most everything
\\ is how to exit k4, shakti and kona
idk what k6 is/was
 
ngn
@nathanrogers ok, so be it, i'll change it to \\
 
what I and... somebody, I think rak was mentioning the other day about just a bit more information than just the names is useful
kona's menu is super helpful
 
ngn
8:28 PM
@nathanrogers there are many things that would be useful, but only a finite amount of (unprocrastinated) time. maybe you can help?
 
sure
how can I do that?
if I'm only an amcrastinator
 
whats an amcrastinator
 
ngn
@nathanrogers tell me what that information should be
 
  \
Backslash Commands:
\0        datatypes help
\+        verb help
\'        adverb help
\:        I/O verb help
\_        reserved word help
\.        assignment/amend, function, control flow help
\b [s|t]  show/set break mode (stop|trace|none)
\d [d|^]  change k directory (^=previous)
\e [n]    show/set error flag (0=off,1=on,2=exit)
\l f      load script f or f.k
\p [n]    show/set print precision (0=full)
\r [s]    show/set random seed (0=random)
\s f      step script f or f.k
\t [n]    show/set timer interval in msec (0=disable)
this is the meta help table
Verbs +-*%|&^!<>=~@?_,#$.:
Verbs work on all sensible types (ints, floats, strings, symbols, lists)
Dyadic or monadic is determined from context, default is dyadic
Add : after a verb to force the monadic form, + is plus, +: is flip
+ monadic flip. transpose a matrix (a depth-2 list)
+ dyadic plus. add numbers together
- monadic negate. invert sign
- dyadic minus. subtraction
* monadic first. first element from the list
* dyadic times. multiply two numbers
% monadic reciprocal. 1 over x
but I was thinking instead of the description perhaps just printing your unit test
demonstrating how the verb is used
something I can type in directly to see a result
like +/+2':!10 for a 2 chunk reduction because then I can take each part and play with it
if you have a table like
verb arity names unit-test(or some kind of example)
verb arity names unit-test
...
that'd be nifty
 
ngn
@nathanrogers it might be better to extract tests from the documentation, not the other way round. the existing unit tests were not meant for explaining what verbs do.
 
8:38 PM
ah
 
ngn
they were meant to catch my own silly mistakes
 
makes sense
unit tests often test fringe cases
 
ngn
if exit is \\, what should \ do? print help?
 
that's the meta help menu
it tells me what different \'s there here
9 mins ago, by nathan rogers
  \
Backslash Commands:
\0        datatypes help
\+        verb help
\'        adverb help
\:        I/O verb help
\_        reserved word help
\.        assignment/amend, function, control flow help
\b [s|t]  show/set break mode (stop|trace|none)
\d [d|^]  change k directory (^=previous)
\e [n]    show/set error flag (0=off,1=on,2=exit)
\l f      load script f or f.k
\p [n]    show/set print precision (0=full)
\r [s]    show/set random seed (0=random)
\s f      step script f or f.k
\t [n]    show/set timer interval in msec (0=disable)
 
does ngn/k support basic socket connections atm?
 
8:42 PM
like if I want to check the workspace I use \w (which isn't here for some reason?)
but \w shows me what names are defined
so it'd be nice to know how to do things like check my workspaces/namespace/definitions
because I don't know how to do that
 
ngn
@rak1507 only client sockets
 
@ngn this whole time I could have just used "\"?? ha
 
ngn
@coltim what did you use?
 
\\
re docs: it would be good to have something available outside of the tool as well (a la the oK Manual)
 
ngn
@coltim i'm not articulate enough to write that much english prose :)
 
8:51 PM
@ngn you could fork the oK manual and just change things that need changing
 
ngn
@dzaima hm.. that might work
 
@ngn I don't think all that much is required. Shakti has a really nice minimal version
 
@nathanrogers that is definitely a valuable resource but at least by k standards I dunno if it's "minimal" =P
 
this isn't a lot of write-up
@coltim I mean it is minimal in terms of examples and explanation. Which tends to be hard to find unless your particular problem has already been solved
This is something I'd be happy to contribute to, I'm much more of a writer, but I don't have the domain knowledge
 
@dzaima (even just cloning and replacing incorrect stuff with "todo" and opening contributions (^) would probably work well enough)
 
8:58 PM
@dzaima Yeah, I'd even just say create some kind of html template, and write some K files, which you read to slot in the text/code into your html template
 
ngn
ok, this evening i'll try to think of short examples for each primitive and describe it in my own words. then @nathanrogers or anyone who wants to improve it is welcome to do so
but i can't really multitask, so i'll log out from chat
 
alright cool
 
@ngn thanks. and I'm happy to do what I can. I just don't know how much help I'll be on the implementation/design/education front
 
9:38 PM
any non-regular syntax in K?
I don't suppose there are trains and such
 
@nathanrogers what do you mean by "non-regular"? $[cond;{true};{false}] has been described as a "special form" before (since it doesn't evaluate the {true} or {false} parts immediately) but I dunno if that's what you're referring to
 
I mean what I implied, trains? syntax sugar? etc?
 
@nathanrogers closest you'll get to syntax sugar would be assignment, which is syntax sugar for amend or something. Otherwise there's mostly only one way to do things in k
 
That's good
uniformity is nice
 
 
1 hour later…
ngn
11:06 PM
this is exhausting and it seems i haven't even described half of the cases yet
@nathanrogers as i mentioned in "the apl orchard", trains in k work as you intuitively assumed apl trains to work (but was wrong) before the odd-even rule was explained to you
1+*2% ←→ {1+*2%x}
there's no odd-even rule here. the last carriage of the train is applied to x (or to both x and y if it's dyadic), and all other carriages are applied on top of the result, following the usual rules for right-to-left expression evaluation.
compare that with apl trains, in which even-numbered carriages are applied to the argument(s) and odd-numbered are applied between the results (odd/even up to ⎕io)
 
11:27 PM
@ngn bruh, that's excellent
Thanks←⌊/⍬
ty:>/()
 
@ngn that's really great, definitely worth doing
 
@ngn star this @rak1507
 

« first day (732 days earlier)      last day (803 days later) »