[racket] ] Converting symbols to procedures?
Is it not as simple as "don't quote the list, use the procedure 'list'?"
Procedures are first class.
Welcome to DrRacket, version 6.0.1 [3m].
Language: racket [custom]; memory limit: 4096 MB.
> (define (filter* procs lst)
(define (fil ps l)
(if (empty? (rest ps))
(filter (first ps) l)
(fil (rest ps) (filter (first ps) l))))
(if (empty? procs)
(error 'filter* "Expected at least one procedure for filtering.")
(fil procs lst)))
> (define test-list (append (build-list 20 values)
(build-list 20 (λ(x) 'derp))))
> (define proc-list (list number? even? (λ(x) (zero? (modulo x 3)))))
> (displayln proc-list)
(#<procedure:number?> #<procedure:even?> #<procedure>)
> (filter* proc-list test-list)
'(0 6 12 18)
>
On Mon, Aug 11, 2014 at 12:05 PM, Kevin Forchione <lysseus at gmail.com> wrote:
> If I use apply on a list of procedures, the quoting of the list converts
> the procedures into symbols, which is not what I want to pass to the
> function supplied to apply (or to map for that matter). What’s the best way
> to handle this situation?
>
> -Kevin
>
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140811/7d1120fc/attachment.html>