That’s the only horrifying part. It gives up the ability to do this for functions taking more than two inputs. They should have used -6 for the bitwise version.
Otherwise, this technique of implementing functions as table lookups with their names being the table is brilliant. That’s self-documenting code. Imagine not having to learn what max means for IEEE floats, but just being able to read it from its function name.
In fact, you would not have to implement any function; you’re just write its name, and the compiler would implement it for you.
I also think they should infer from context whether (6 b.) takes three arguments and produces none, takes two arguments and produces one, takes one and produces two, or takes none and produces three. /s
It would be fun to try and hack the above in a set of C macros. Might lead to a good IOCCC entry (https://www.ioccc.org/)
Isn't this equivalent to placing the function code into its name, in other words, inlining the function? Looks cute for 2-bit programs, but I doubt it scales for 100-bit ones.
Or is it the numeric value that you fear? There is a fantastic use for this, that if you don’t know, you may want to think about for more than a few seconds.
Is it one of the things in the table towards the bottom of the J article? I have to admit, I'm struggling to read the syntax.
Erm, no. That table suggests using b. as a replacement for other (clearer) algorithms for performance reasons, rather than parameterisation.
What I mean by parameterisation is this: if you have a function that takes some arbitrary bitwise operation, instead of taking a lambda, you can pass the truth-table directly.
This idea is mentioned only briefly in the J article (More Info, ¶2):
2. Operand m may be an array, in which case each result cell will be the array of the results of the logical functions specified by m.
Maybe that is too-obvious to an array programmer and not-enough-obvious to someone who isn't, and so it is hard to properly consider the implications or applications of this.
Here's one: Parsing AND/OR operations from an expression (like an SQL expression). You could use a tree of operators and then walk the tree for every row you want to consider or you could store the compositions as a list and do a single reduction.
Is that enough for you to get the idea of what is going on here?
a = (o >> (x + 2y)) % 2
or something.I'd hoped it might involve adding/multiplying different operators together or something like that.
fbzrgvzrf jr jnag gb pbzcbfr bcrengvbaf