3 ms·
Do user functions and if statements vectorize? In J, user-written verbs have rank _ _ _ (infinite for both unary and binary cases) by default, but you can rera
by kd0amg 12y ago
Do user functions and if statements vectorize?
In J, user-written verbs have rank _ _ _ (infinite for both unary and binary cases) by default, but you can rerank them with the " operator just like any built-in verb.
Why do I see so few user functions being used? I would expect application code to consist mostly of specific functions but instead I see line after line of unbroken primitive operators.
Lots of purpose-specific functions can be built using composition forms on built-in verbs. The resistance to naming sub-pieces of these compositions is largely a cultural thing but still a point of dispute within the community -- some are very much in favor of giving descriptive names to intermediate results.
- tailrecursion 12y agoI imagine that making user functions would require leaving the one-symbol-one-function spelling system that J programmers are accustomed to, and that spelling system is part of the appeal. Also, if the idiomatic form with primitives is shorter than the name, it's tough to consider the name an improvement. :) Thanks for your response.
- kd0amg 12y agoYeah, some things are so common and small as to not merit their own name except in a tutorial. It might be fun to try using those to construct really garden-pathy code. Stick the fork `+/%#` (average when used on its own) somewhere in a train, but use the dyadic case, or position it so that parsing splits it up.
- klibertp 12y agoI found that it quickly becomes a mess with tens of parens when you try to do this. Parsing rules of J are complex and the same sequence of symbols can be parsed in a couple of different ways depending on the context - it's good to keep expressions very short to avoid this.