Deutsch English Français Italiano |
<vc23eb$10ri2$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "B. Pym" <Nobody447095@here-nor-there.org> Newsgroups: comp.lang.lisp,comp.lang.scheme Subject: Re: Python syntax in Lisp and Scheme Date: Fri, 13 Sep 2024 19:22:53 -0000 (UTC) Organization: A noiseless patient Spider Lines: 58 Message-ID: <vc23eb$10ri2$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Injection-Date: Fri, 13 Sep 2024 21:22:53 +0200 (CEST) Injection-Info: dont-email.me; posting-host="b23a757b35dd03cbd4947edb1cfbe6d8"; logging-data="1076802"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX194+YHi2/nMzAzxEeH+bOgi" User-Agent: XanaNews/1.18.1.6 Cancel-Lock: sha1:nqcNMQiVGskEHIXpBLKY3OSnczU= Bytes: 2490 Pascal Costanza wrote: > What about dealing with an arbitrary number of filters? > > (defmacro predicate-collect (list &body predicates) > (let ((collectors (mapcar (lambda (predicate) > (declare (ignore predicate)) > (gensym "COLLECT")) > predicates)) > (collect-t (gensym "COLLECT"))) > `(with-collectors (,@collectors ,collect-t) > (dolist (l ,list) > (cond ,@(mapcar (lambda (predicate collector) > `((funcall ,predicate l) (,collector l))) > predicates collectors) > (t (,collect-t l))))))) > > An example: > > > (predicate-collect '(-5 -4 -3 -2 -1 0 1 2 3 4 5) > (function evenp) > (lambda (n) (< n 0)) > (lambda (n) (> n 3))) > (-4 -2 0 2 4) > (-5 -3 -1) > (5) > (1 3) > > > I use the list collector macros by Tim Bradshaw here - see > http://www.tfeb.org/lisp/hax.html#COLLECTING Gauche Scheme (define (multi-partition the-list . predicates) (if (null? predicates) (list the-list) (receive (yes no) (partition (car predicates) the-list) (cons yes (apply multi-partition no (cdr predicates)))))) (multi-partition '(-5 -4 -3 -2 -1 0 1 2 3 4 5) even? (is < 0) (is > 3)) ((-4 -2 0 2 4) (-5 -3 -1) (5) (1 3)) Given: (define-syntax is (syntax-rules () [(is x) (lambda (y) (equal? y x))] [(is compare x) (lambda (y) (compare y x))] [(is key compare x) (lambda (y) (compare (key y) x))]))