I have been looking at the Rosetta Code task entitled "List
Comprehension", here:
http://www.rosettacode.org/rosettacode/w/index.php?title=List_Comprehens
ion
<http://www.rosettacode.org/rosettacode/w/index.php?title=List_Comprehen
sion> 
 
J does not have any special syntax, so it cannot (I think) satisfy this
syntax-specific requirement. I can, however, build the list of
Pythagorean triples. Here's my solution:
 
   Across =: 1 : '*./@(}: u }.)"_1'
   pytrpl =: 3 : '(#~ < Across) 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
 
I'd be interested in knowing a tacit way to define the adverb, Across.
 
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. I used capitalization of initial letter to indicate
that it is an adverb, but some other naming convention might be better.
 
As for alternatives to pytrpl, what I'd find interesting are programs
that bring out the Pythagorean relationship. The heart of the program
listed here-- (=/ +/~) *: --seems rather buried.
 
The Haskell list comprehension syntax is attractive. It is notational,
and much like familiar set notation. If an analogous presentation can be
phrased in J, it's beyond my creative powers.

--
Tracy
 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to