Alex Gian wrote: > > [...] > Basically I want a pretty bog standard filter function, textbook h.o.p. > example as given in the Lisp family, but obviously in J tacit style, not > recursive. Say the left argument will be a boolean function and the > right arg the string to filter. > So, e.g. > > odd =: 2&| > > NB. This is OK > (odd i.9) # i.9 > 1 3 5 7 > > NB. but if I try to make "filter" a function, somehow along the lines > NB. This definitely does NOT work > filter =: ([]) # ] > odd filter i.9 > 1 0 0 1 1 1 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 > [...] >
Here's a tacit adverb solution: F =: (#~`)(`:5) 2&| F +-----+-------+ |+-+-+|+-+-+-+| ||#|~|||2|&|||| |+-+-+|+-+-+-+| +-----+-------+ 2&| F i.9 1 3 5 7 In short, filter F generates (#~ filter), it's a higher-order function. -- View this message in context: http://old.nabble.com/simple-polynomials-tp29486977s24193p29521532.html Sent from the J Programming mailing list archive at Nabble.com. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
