@ngn It's mercifully brief :) -- but I don't yet know enough about k internals to be able to comment meaningfully -- it would be nice to see some mocked up but concrete examples, or a set of steps listing what would need to be done.
It's super cool that you guys are cooperating on this, btw -- a common way to do this will benefit all.
there are a few questions around it - how to handle multiple int types (64bit, 32bit, 16bit, etc) and the conversions among them
and i expect in practice KA() and KR() would turn out more convenient with a const char* first argument
and i think it would be useful to have something like k("code",x,y..) even though that's accessible through "eval": K1('.',"code") and "apply": K2('@',func,arg)
@xpqz you'd need a wrapper that accepts arguments of type K and returns a result of type K, then put it in k's namespace with KA(Ks("f"),KR(f,2,"<f>")) // i think we have to simplify this
Ks("f") means make a k symbol from a c string
KR(func,valence,displayName) makes a k function from a c function
KA(name,value) is assignment, like :
the wrapper function would have to test the types of the arguments, maybe signal an error if they are not right, extract the actual ints from them with iK(x) and iK(y), do whatever f() is supposed to do, then create a k object for the result with Ki(value) and return it
@ngn Ok, think I understand how to wrap a function from that. This embeds a k-terp in c, and runs the wrapped function through it with K1('.',s);. Can I call the add function from the k-repl, too?
Your example would be how I'd use the xeus c-kernel to do k-in-jupyter 'properly'.
@xpqz note that we are still designing this and it may change. for instance, i'll try to persuade ktye to add something like Kfunc("f",f,nargs) instead of KA(Ks("f"),KR(f,nargs,displayName))
the repl - i'm not sure, maybe we should expose a repl() function in the api or somehow work towards implementing 2:
for now it's "c embeds k" only
@xpqz of course, in a published api comments are good
@ngn plenty of usecases for this -- but the reverse is the "killer app" for me at least -- being able to have pcre/db-of-choice/crypto/libcurl etc at your fingertips in k itself.
@ktye parse will accept a string or list of strings as the right argument; format currently does not vectorize since there's ambiguity- some pattern types produce a list value
to parse a (simple) csv or fixed record file you can basically do "table KEYS dict FORMAT parse "\n" split X"
where table is a monad that makes a table from a dict-of-list, dict is like dyadic l!l in k6, and split breaks a string by a string delimiter
there are several ways to have patterns that read a string until a delimiter
currently the patterns do not have any notion of "repeat this subpattern until the string is exhausted" or whatever; a given pattern always produces a specific number of result values
this is useful for symmetry, and means that it's possible to yield appropriate null values if the pattern doesn't match. (it is also possible to detect that the pattern failed, if that's what you want)
as for formatting a table into a single string there are multiple ways to do it but the cleanest approaches do care somewhat about the structure of the table. Here's an example:
"\n" fuse extract "%6s%6c%2i" format name,price,amt from t by index
I've also thought about giving parse a mode where you supply a PEG grammar on the left side as an alternative to the pattern strings, but that may be too much complexity