Loopiness

Liste des GroupesRevenir à cl scheme 
Sujet : Loopiness
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.scheme
Date : 26. Sep 2024, 22:13:00
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vd4ior$cfmj$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
  (loop for x in things
        when (foo-p x) collect x into foos
        when (bar-p x) collect x into bars
        when (and (foo-p x) (bar-p x)) collect x into both
        finally (return (values foos bars both)))

It's shorter in Gauche Scheme.

(define things '(0 3 -5 4 9 -7 6 8))

(let@ (() odds posi both)
  (dolist (x things)
    (when (odd? x) (push! odds x))
    (when (positive? x) (push! posi x)
      (when (odd? x) (push! both x))))
  (values odds posi both))

(-7 9 -5 3)
(8 6 9 4 3)
(9 3)

Given:

(define-macro let@
  (lambda (lets . exprs)
    (let ((lets lets)
          (let-pairs '()))
      (if (list? lets)
        (while (pair? lets)
          (let ((x (pop! lets)))
            (cond
              ((not (symbol? x))
               (while (pair? lets)
                 (push! let-pairs (list (pop! lets) x))))
              ((null? lets) (push! let-pairs (list x 0)))
              (#t (push! let-pairs (list x (pop! lets)))))))
        (set! let-pairs `((,lets 0))))
      `(let* ,(reverse let-pairs)
         ,@exprs))))

Date Sujet#  Auteur
26 Sep 24 * Loopiness2B. Pym
27 Sep 24 `- Re: Loopiness1Kaz Kylheku

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal