The way you did it with the fork was instructive to me, R.E., really nice to see all the different approaches!
It's still not a "filter" verb on its own, though, as specified (left arg - boolean verb, right arg - list to filter) On Tue, 2010-08-24 at 13:58 +0200, R.E. Boss wrote: > filter=:# > (prime filter ]) >:i.9 NB. prime stumbles on 0 > 2 3 5 7 > (filter~ prime) >:i.9 > 2 3 5 7 > > > R.E. Boss > > > > -----Oorspronkelijk bericht----- > > Van: [email protected] [mailto:programming- > > [email protected]] Namens Alex Gian > > Verzonden: dinsdag 24 augustus 2010 13:22 > > Aan: Programming forum > > Onderwerp: Re: [Jprogramming] Implementing a tacit "filter" function > > > > Thanks Bill! > > > > > I guess a pattern of "filter" is > > > (#~ filter) y > > > where filter is a monad verb that return 0 or 1 > > > For your case, it would (untested) > > > (#~ odd) i.9 > > > > odd=: 2&| > > (#~ odd) i.9 > > 1 3 5 7 > > > > Yes, great, the hook works as expected, and as per Chris's example > > Where I'm stuck is in making the filter verb _itself_ > > filter =: (#~ [) > > doesn't work, neither > > filter =: (#~ [) ] > > > > I guess what I'm trying to say, is that as much as I like the challenge > > of Chris's elegant example, I think a far more readable entry point for > > a beginner would be > > filter =: ...whatever... > > prime =: 1&=...@#@q: > > prime filter i.9 > > 2 3 5 7 > > > > which of course would also allow nice, useful bindings like > > prime&filter, odd&filter, etc. > > I also note that "prime" in the boolean function given above, probably > > won't work with our pattern for "filter", due to reasons of rank, but > > I'm not sure, I'm leaving that for later. > > > > > > > > > > ---------------------------------------------------------------------- > > 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
