Tray wrote:
> I'd be interested in knowing a tacit way to define the adverb, Across.
> Across =: 1 : '*./@(}: u }.)"_1'
> pytrpl =: 3 : '(#~ < Across) 2+ 4$. $. |: (=/ +/~) *: 2+i. 1-~ y'
Here's the easiest way:
Acx0 =: *./@(}: $: }.)"_1 :
but it requires more care in its use than Across does. Basically you can't
use Acx0 "inline", you have to provide it with an argument and assign the
derived verb to a name. Then you embed that name in the longer definition:
allLess =: < Acx0
pytrpl =: 3 : '(#~ allLess) 2+ 4$. $. |: (=/ +/~) *: 2+i. 1-~ y'
pytrpl 22
3 4 5
5 12 13
6 8 10
8 15 17
9 12 15
12 16 20
This is a consequence of the broad scope of $: . So maybe you'd prefer
this:
Acx1 =: (}:`) (`}.) (`:6) (*./@) ("_1)
pytrpl =: 3 : '(#~ < Acx1) 2+ 4$. $. |: (=/ +/~) *: 2+i. 1-~ y'
pytrpl 22
3 4 5
5 12 13
6 8 10
8 15 17
9 12 15
12 16 20
But that doesn't resemble the original. So, if we're going to make that
sacrifice anyway, why not get something back for it. FYI, (}. f"_1 }:)
is equivalent to 2 f/\ ] and the latter is optimized for several cases
(including f=:< ) :
http://www.jsoftware.com/help/release/infix2.htm
http://www.jsoftware.com/help/release/infix2a.htm
So, using this equivalence, we can rewrite Across tacitly thus:
Acx2 =: /\ (2&) (*./@:) ("_1)
pytrpl =: 3 : '(#~ < Acx1) 2+ 4$. $. |: (=/ +/~) *: 2+i. 1-~ y'
pytrpl 22
3 4 5
5 12 13
6 8 10
8 15 17
9 12 15
12 16 20
which I find clean. You may also be interested in a thread entitled "Tacit
Adverb Definitions", which has several tacit examples the adverb 1 : '{. u
{:' (similar to your request). The thread starts here:
http://www.jsoftware.com/pipermail/programming/2006-July/002618.html
And, while I haven't studied the rest of your problem or solution, it might
also have opportunities for modification or optimization. Here's another
thread on the topic:
http://www.jsoftware.com/pipermail/programming/2007-July/007428.html
> I notice that the phrase (#~ < Across) has an ambiguity Bruno Daniel
> criticized: whether this is a fork or a hook depends on whether
> Across is verb or adverb.
This is off the mark (or imprecise). Across can be an adverb, yet
#~<Across could still be a fork, e.g. when Across =: 1 : 'u 2 : ''v u ]''
' . Even when not a fork, it needn't be a hook, e.g. when Across =: 1
:'/' or even a verb at all, e.g. when Across =: 1 : ' u 2 :''@'' '
[1].
Names have the advantage that they encapsulate information. They also have
the drawback that they encapsulate information. This is not specific to J.
For example, in C++, what will
foo + bar
do?
In any case, the ambiguities that nameclass introduce were not Bruno's
complaint. Bruno's complaint was, given a train of (only) verbs, unless
you know the parity of the train and the number of its arguments, the
invocated valence each of its verbs is not discernable.
I actually wrote up a response with tips to help predict the invoked
valence, but didn't finish it. The fact is that J's syntax is highly
compressed and hence overloaded, so not amenable to static analysis. But
this is no worse a problem than polymorphism in, say, Java.
Without knowing the types and definitions of all the entities involved, you
cannot know what an executable statement DOES. J and Java have different
obstacles to this goal, and different opinions about what's relevant and
what's immutable, but the result is the same, so the differences don't
matter. You cannot know what a given executable statement does unless you
have the same information as the compiler.
-Dan
[1] Hmm, I'd never thought about the difference between / and 1 :'/'
before.
--
View this message in context:
http://www.nabble.com/Pythagorean-triples-tp14896594s24193p14922324.html
Sent from the J Programming mailing list archive at Nabble.com.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm