3 ms·
What would getopt look like in APL (also K, J, what have you)? I couldn't find any examples. Similarly, I'd like to see some examples of handling multiple I/O
by clarry 6y ago
What would getopt look like in APL (also K, J, what have you)? I couldn't find any examples. Similarly, I'd like to see some examples of handling multiple I/O endpoints (sockets, stdio, files?) asynchronously (or should I say without blocking) using whatever mechanism works best in APL.
- srazzaque 6y agoIt's literally 4 characters in Q. .z.x But in reality you'd probably use: .Q.opt (which is 6 characters!) Update: reference to .Q.opt See https://code.kx.com/q/ref/dotz/#zx-raw-command-line https://code.kx.com/q/ref/dotz/#zx-raw-command-line
- clarry 6y agoUhh.. no, that's just argv. Getopt is something you'd use to actually parse flags and arguments out of argv. EDIT: Ok, .Q.opt looks a little better, although it's still not close to getopt (where -abc would be shorthand for three flags, -a -b -c; but other flags might be defined to take (possibly optional) arguments). Is it a built-in implemented in whatever K/Q is written in? How would you implement .Q.opt in K if it were not built in? http://man.openbsd.org/getopt.3 http://man.openbsd.org/getopt.3 http://cvsweb.openbsd.org/src/lib/libc/stdlib/getopt_long.c?rev=1.31&content-type=text/x-cvsweb-markup http://cvsweb.openbsd.org/src/lib/libc/stdlib/getopt_long.c?...
- srazzaque 6y agoApologies - updated.
- srazzaque 6y agoYep you're right, it's definitely not doing as much as getopt, though it's the same general use case. It's output is a dictionary representing your command line arguments, which you'd then use in your program to act accordingly. It's implemented in K and comes standard with the distrubution. If you've got a KDB+/Q distribution you can view the actual function definition by executing it without an argument: q).Q.opt k){[o]x::$[#i:&o like"-[^0-9]*";i[0]#o;o];((`$1_*:)'o)!1_'o:i_o} Disclaimer: I cannot read K, and I'd consider myself a beginner in Q, so the above is completely alien to me. But what that does, in words: any "-single-dash-params" is treated as an option. It splits your 'argv' by those options. Everything between the options become the 'values' for the prior most recently preceding option. If you've got a no-arg option, it just becomes a member in the dictionary without a corresponding value: $ q -opt1 foo bar -opt2 baz -opt3 q).Q.opt .z.x opt1| ("foo";"bar") opt2| ,"baz" opt3| () EDIT: formatting.
- Rampoina 6y agoI would also like to know if there's examples of more real time applications in APL. Any GUI programming? Interactive simulations? etc.
- doublec 6y agoTangentstorm’s videos about J have some nice GUI examples. For example https://youtu.be/uL-70fMTVnw https://youtu.be/uL-70fMTVnw
- Rampoina 6y agoPretty cool thanks, this one covers interactivity https://invidio.us/watch?v=CzK2SazvCxM https://invidio.us/watch?v=CzK2SazvCxM (it's a little sprite editor) Do you know if GNU APL offers the facilities to do stuff like that?