Thanks!

Interesting  use of the dual/under operator &. Although I had studied the
form, this usage didnot occur to me!

As an extension question:

p1 =: i. &. (p:^:_1)     NB. primes strictly less than number

so,
p1 37
2 3 5 7 11 13 17 19 23 29 31

In the generated list, I want the number included if it is prime. What would
that extension be using &. ?
Or, does that need compelete verb definition?

Regards,
Yuva




On 9/21/06, Henry Rich <[EMAIL PROTECTED]> wrote:

The easiest way to explain the results is that you have
to put parentheses around the value when you substitute
for a name.

This is like mathematics, where if

y   is   2+x

y*2  is (2+x)*2    not  2+x*2

So, if
pl =. p: i. (p:^:_1)

then
p1 n

is like

  (p: i. (p:^:_1)) n

which is not what you want.  (It is a hook, which
you can read about in the references.  It is equivalent
to (p: n) i. (p:^:_1 n)  ).

To get what you want, you can write
p1 =: verb : 'p: i. (p:^:_1) y'

or

p1 =: p: @: i. @: (p:^:_1)

(read about @: to understand this)

or

p1 =: i.&.(p:^:_1)

(read about &.)


You should know that names ARE NOT replaced by their
parenthesized values when a sentence is executed.  That's
just a convenient fiction.  The actual details
are in the references.

Henry Rich


> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> Yuvaraj Athur Raghuvir
> Sent: Wednesday, September 20, 2006 7:52 PM
> To: Programming forum
> Subject: [Jprogramming] Explicit to Tacit - newbie question
>
> Hello,
>
> J is fascinating. Am learning slowly....
>
> In the following why does pl not work?
>
>    n =. 30
>    p:^:_1 n
> 10
>    p: i. p:^:_1 n             NB. list of primes less than n
> 2 3 5 7 11 13 17 19 23 29
>    pl =. p: i. p: ^: _1
>    pl n                          NB. Does not work!
> 1
>    p: i. (p: ^: _1) 30
> 2 3 5 7 11 13 17 19 23 29
>    pl =. p: i. (p:^:_1)      NB. Is it a paranthesis problem?
>    5!:5 < 'pl'                  NB. J removes the paranthesis
> anyways...
> p: i. p:^:_1
>
>
> Regards,
> Yuva
> ----------------------------------------------------------------------
> For information about J forums see
> http://www.jsoftware.com/forums.htm

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

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

Reply via email to