« first day (997 days earlier)      last day (538 days later) » 

6:33 AM
@coltim does that vectorize, e.g.parse/print tables?
 
 
2 hours later…
8:08 AM
With an extension api, I’d be tempted to look at PCRE - and maybe even sqlite3/duckdb
 
 
2 hours later…
ngn
9:53 AM
@xpqz what do you think of github.com/ktye/i/blob/master/kc ?
 
@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.
 
ngn
@xpqz that's not brief, this is brief :P
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)
 
10:09 AM
If I have a c function int f(int x, int y), how will this present on the k side? Indistinguishable from a f:{[x;y]...} defined in k?
 
ngn
@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
10:50 AM
 
11:12 AM
@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'.
@ngn I added some commentary for my own future sanity gist.github.com/xpqz/2105fb4144c35f4b982d7cce9e78a03f
I know you're not a fan of comments :) -- but I think this sort of stuff benefits from it, as it's the interface.
 
ngn
11:40 AM
@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.
extend, rather than embed.
 
12:24 PM
@ngn we could do that. but how would you assign to a symbol then? i'd like to enable the general case, too.
 
ngn
@ktye i'm not suggesting removing KA(), but replacing KR() with something more convenient.
i'd expect in almost 100% of uses of KR(), the result would be given a name
 
like that: void KR(const char *name, void *fp, arity int)
or some return value?
 
ngn
@ktye yep, like that
what does the R in KR() stand for?
ah, "register"
 
i'm open for a better name
 
12:42 PM
@ngn ngn.bitbucket.io/k/#r shows an error
 
@ngn updated
 
ngn
1:15 PM
@dzaima ah, i forgot to update the web interface after removing the args of kinit(). thanks!
fixed now
@ktye question about KL() - should it increment the items' refcounts?
@ktye what does KR() return?
 
@ngn if KL consumes, that means you can forget about the individual k values after the call. i would not increment in this case. is that ok?
 
ngn
@ktye sure
 
@ngn is "void" ok? i'll correct it.
 
ngn
@ktye yep, otherwise it's too likely that the user forget to unref() the result
@ktye thanks. my example looks cleaner now
it would be interesting to have the same example work with your implementation
 
1:36 PM
@ngn i'm still debugging the compiler. i don't have a running k.c yet.
 
ngn
2:12 PM
@ktye i think you documented the wrong function - i meant KL(), not LK(). but the question of refcounting is interesting about LK() too
 
@ngn ok. For LK() you consume the argument as usual. whatever that means to the type system. e.g. i only unref children, if the list rc drops to 0.
 
ngn
hm..
a simpler example: does this unref x? char a[NK(x)];CK(a,x);
 
i would say yes. if you need to keep it, do: CK(a,ref(x)).
you disagree?
 
ngn
no, just asking
@ktye ok, so after this code is the api user responsible for consuming the elements of a or not? - K a[NK(x)];LK(a,x);
..or it depends on the refcount of x, which isn't accessible to them?
 
i guess he hes to. he just exploded a list into n individual k-values.
 
ngn
2:25 PM
so, if x's refcount is >1, the implementation of LK() would have to ref each a[i] after copying
 
Maybe we could make LK also decompose dicts and tables in to key/values.
 
ngn
yeah, that makes sense
if x's refcount is exactly 1 (before decrementing it), LK() would have to copy x's content to a, and free x as if it has length 0
 
i understand LK as an explode. it returns all children of the list but throws the list container away.
 
ngn
@ktye what is NK() for a dict or table
 
same as the result of #x
or maybe 2?
yes, 2 is better i think.
 
ngn
2:37 PM
ok
 
i moved it to +/k.h
 
3:32 PM
@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
 
@JohnE even if hacky/ugly, would there be a way to use parse to split strings as well?
 
depends on what you mean by split strings
 
well, emulating the "\n" split X example
 
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
 

« first day (997 days earlier)      last day (538 days later) »