I know J fairly well but am only superficially acquainted with APL. I
recently learned that, at least in recent APL dialects, they have function
literals written between curly braces. If you only mention omega, you get a
monadic verb, if you use alpha and omega you get a dyadic verb, if you also
use alphaalpha, you get an adverb (I would guess omegaomega also exists).

This made me think: Why do we have to pick the left argument to explicit
definition, :,  in J? Wouldn't that rule work just as well?

Here's a crude implementation of a version of APL's {} in J, of course I
still need to use a string but this thing will keep track of which
arguments you mention in the string and decide based on that whether you
get back a monadic verb, a dyadic verb, an adverb or a conjunction:

fn =: 1 : '(2 2 1 1 4 3 3 {~ 1 i.~ (_1 <\ ''vnumxy'') e. ;: m) : m'

(Here I've made the decision that a source code string with no mention of
arguments gives you a constant monadic verb.)
A sample transcript to make clear how it is used:

    '*:y' fn
 3 : '*:y'
    'x*y' fn
 4 : 'x*y'
    'x' fn
 4 : (,'x')
    'u u x' fn
 1 : 'u u x'
    'y + u u x' fn
 1 : 'y + u u x'
    '(v y) + u u x' fn
 2 : '(v y) + u u x'

I have several questions about this but am generally interested in opinions
about this and related topics.

1. In APL's with this {} syntax, can you force a function whose source code
only mentions omega to be dyadic? I.e., in J I can do 3 : 'y*y', but also 4
: 'y*y'.

This might be a case for explicitly requesting what kind of operator you
want, but probably in the vast majority of cases this fn adverb gives you
what you want.

2. Beyond these what are the advantages and disadvantages of J's and APL's
{} way of dealing with explicit definition?

3. Why does J require you to specify the left argument to :? Is it for the
reason in question 1?

4. Is there a better name for this adverb than fn?

5. What would be a more robust rule for picking the type of the resulting
operator? I mean, presumably  'u * x i. u=. ~. y' (ignore the random
nonsense) is meant to be a dyadic verb even though it contains a u. I guess
one could only count references to u if u never occurs as the target of a
copula or something like that. (I don't think this problem arises in APL,
because I don't think assignments to alphalpha are allowed, but I might be
wrong.)

-- 
Omar Antolín Camarena
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to