Beginner's J questions, vol. 3
Author Message
Beginner's J questions, vol. 3

J version 6.2.

1.  I want to have a constant index vector in a function without having
to write it out in full:

f =. (desired constant)&=

but I can't find any way to do it except (] 0 1 2&[).  In particular,
I can't find a way to do it using i..  The 0: to 9: verbs seem useful,
but they peter out at 9:.

2.  Is there any way to determine the rank of a (user-defined) verb?

Henry Rich

Sun, 23 Mar 1997 04:44:08 GMT
Beginner's J questions, vol. 3
Henry Rich:
. 1.  I want to have a constant index vector in a function without having
. to write it out in full:

. f =. (desired constant)&=

. but I can't find any way to do it except (] 0 1 2&[).  In
. particular, I can't find a way to do it using i..  The 0: to 9:
. verbs seem useful, but they peter out at 9:.

You can make an arbitrary datum a function by giving it a rank.  For
example, 23"_, or 45 67 98"_

. 2.  Is there any way to determine the rank of a (user-defined) verb?

Well, this is a bit ugly, but it seems to work:
verbrank =. '>2{5!:2<''t''[.t=.-"x.':1

--
Raul D. Miller           n =: p*q             NB. 9<##:##:n [.large prime p, q

NB.  public e, n, y
x -: n&|&(*&y)^:d 1  NB. 1=(d*e)+.p*&<:q

Sun, 23 Mar 1997 10:08:34 GMT
Beginner's J questions, vol. 3

Quote:

>. 2.  Is there any way to determine the rank of a (user-defined) verb?

You can use the undocumented feature of b. for this :

dyad =. +/"(0 2)
(myfunction b. 0)
1 0 2

-e

Sun, 23 Mar 1997 13:38:50 GMT
Beginner's J questions, vol. 3

Quote:
> 1.  I want to have a constant index vector in a function without having
> to write it out in full:
> f =. (desired constant)&=
> but I can't find any way to do it except (] 0 1 2&[).  In particular,
> I  can't find a way to do it using i..  The 0: to 9: verbs seem useful,
> but they peter out at 9:.

In J 7.0, which has no relevant difference from 6.2:

f =. (i.3)&=
f
+-------------------+-+-+
t0 1 2 3 4 5 6 7 8 9t&t=t
+-------------------+-+-+

gave what seems to be the correct result. In fact, any expression
which gives a result will work:

(2+i.3}&=
+-------+-+-+
t 2 3 4 t&t=t
+-------+-+-+

Perhaps if you can show what you were trying, and what you got...
The "&" conjunction is one of the things that gives J its power
and there is a concept that has to be grasped.  Someone in your
state of not quite having that concept can provide insight to
those of us who would like to educate others.
Later...
---------------------------------------------------------------------
|\/| Randy A MacDonald       |"You just ASK them?"

BSc(Math) UNBF '83      | APL: If you can say it, it's done.
Natural Born APL'er     |
------------------------------------------------------------{ gnat }-

Mon, 24 Mar 1997 04:18:06 GMT
Beginner's J questions, vol. 3

Quote:

>In fact, any expression which gives a result will work:

> {example: f =. (i.3)&=)

>Perhaps if you can show what you were trying...

You went to the heart of my error.  I thought that constants could
appear in a tacit definition only if they were bonded to a function,
i. e. i.&3.  Evidently that is not so.

Pursuing this topic, I tried:

xx =. (i. yy)&=
yy =. 3
xx i. 3
domain error
xx =. (i. yy)&=
xx i. 3
1 1 1

So it seems that the evaluation of  i. yy   is performed at definition
time, not execution time.  Does it have something to do with nouns'
appearing in the definition?  Apparently so:

aa =. bb
bb =. 3:
aa 0
3
cc =. dd
dd =. 3
cc
+--+
|dd|
+--+
cc 0
domain error
cc =. dd
cc
3
cc 0
syntax error

It appears that, if the interpreter knows something is a noun, it
substitutes it; otherwise it assumes it is an undefined verb and hopes
for the best, generating a domain error if the assumption proves
incorrect.  Some confirmation of this comes from

undefinedname b. 0
_ _ _

indicating that   undefinedname  has the ranks associated with a verb.

Is this true, and if so, could it have been gleaned from the Dictionary?

Henry Rich

Mon, 24 Mar 1997 20:21:47 GMT
Beginner's J questions, vol. 3
Henry Rich:
. It appears that, if the interpreter knows something is a noun, it
. substitutes it; otherwise it assumes it is an undefined verb and
. hopes for the best, generating a domain error if the assumption
. proves incorrect.  Some confirmation of this comes from
.    undefinedname b. 0
. _ _ _
. indicating that   undefinedname  has the ranks associated with a verb.
.
. Is this true, and if so, could it have been gleaned from the Dictionary?

As near as I can tell from reading one of my copies of the Dictionary
(focusing on the section PARSING & EXECUTION), this behavior is
implementation specific and not a defined part of the language.

Last time I checked (J7), the rules were:

Nouns, adverbs and conjunctions were call by value.  Verbs were call
by name with a few exceptions (f. comes to mind).

Raul D. Miller           n =: p*q             NB. 9<##:##:n [.large prime p, q

NB.  public e, n, y
x -: n&|&(*&y)^:d 1  NB. 1=(d*e)+.p*&<:q

Mon, 24 Mar 1997 20:50:41 GMT

 Page 1 of 1 [ 6 post ]

Relevant Pages