Use the dyad # ; for example:

   ((0=2&|) # ]) i.11
0 2 4 6 8 10
   ((0~:2&|) # ]) i.11
1 3 5 7 9

As well, # can take an integer vector left argument so that:

   3 1 4 0 1 1 # 'abcdef'
aaabccccef

And Gaussian integer left argument:

   3j1 1j2 4j1 0 1j1 1j1 # 'abcdef'
aaa b  cccc e f 

In the special case where x is a boolean vector and
you want to select from i.#x, the monad I. can be used:

   b=: 1 1 0 0 0 1 0 0 1
   b # i.#b
0 1 5 8
   I. b
0 1 5 8



----- Original Message -----
From: "Lau B. Jensen" <[email protected]>
Date: Wednesday, December 2, 2009 3:29
Subject: Re: [Jprogramming] newbie question
To: Programming forum <[email protected]>

> 
> 
> W.Ch Lin wrote:
> > Does J have filter function like clojure's ?
> > ---------------------------------------------------------------
> -------
> > For information about J forums see 
> http://www.jsoftware.com/forums.htm
> I definitely want to hear what the J crowd says, but just to be 
> sure, in 
> Clojure you could say
> 
> (filter #(zero? (rem % 2)) (range 1 11))
>  > 2 4 6 8 10
> 
> To pull out the even numbers. So filter takes a predicate and a 
> collection basically. I was thinking
> in J I'd to something like
> 
> ,.((|~ & 2) 1 + i. 10) ;, 1 + i.10
> +--------------------+
> |1 0 1 0 1 0 1 0 1 0 |
> +--------------------+
> |1 2 3 4 5 6 7 8 9 10|
> +--------------------+
> 
> Where as you can see all even values get a 0 return from (|~ & 
> 2), but 
> that leaves 2 questions
> 
> 1) Is that how you would do it with J at all?
> 2) Disregarding 1, how would you pick those 0 values out from 
> the 
> original list 1 + i.10 ?
> 
> Thanks
> Lau
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to