Groups | Search | Server Info | Login | Register


Groups > pt.comp.programacao > #281

Re: mais sobre loops em common lisp

From Patricia Ferreira <pferreira@example.com>
Newsgroups pt.comp.programacao
Subject Re: mais sobre loops em common lisp
Date 2024-03-10 19:33 -0300
Organization A noiseless patient Spider
Message-ID <878r2pogxf.fsf@example.com> (permalink)
References <87frwxoh5l.fsf@example.com>

Show all headers | View raw


Patricia Ferreira <pferreira@example.com> writes:

> Eis uma alternativa a loop.  Em vez de escrever, por exemplo,
>
>   (loop for e in ls
>         when (> e 3)
>           collect e)
>
> podemos escrever
>
>   (iter (for e in ls)
>         (when (> e 3)
>           (collect e))).

Vamos comparar as expansĂ”es.  Praticamente idĂȘnticas.

ITER> (macroexpand '(loop for e in ls when (> e 3) collect e))
(BLOCK NIL
  (LET ((E NIL)
        (#:LOOP-LIST-339
         (SB-KERNEL:THE* (LIST :USE-ANNOTATIONS T :SOURCE-FORM LS) LS)))
    (DECLARE (IGNORABLE #:LOOP-LIST-339)
             (IGNORABLE E))
    (SB-LOOP::WITH-LOOP-LIST-COLLECTION-HEAD (#:LOOP-LIST-HEAD-340
                                              #:LOOP-LIST-TAIL-341)
      (TAGBODY
       SB-LOOP::NEXT-LOOP
        (WHEN (ENDP #:LOOP-LIST-339) (GO SB-LOOP::END-LOOP))
        (SB-LOOP::LOOP-DESETQ E (CAR #:LOOP-LIST-339))
        (SB-LOOP::LOOP-DESETQ #:LOOP-LIST-339 (CDR #:LOOP-LIST-339))
        (IF (> E 3)
            (SB-LOOP::LOOP-COLLECT-RPLACD
             (#:LOOP-LIST-HEAD-340 #:LOOP-LIST-TAIL-341) (LIST E)))
        (GO SB-LOOP::NEXT-LOOP)
       SB-LOOP::END-LOOP
        (RETURN-FROM NIL
          (SB-LOOP::LOOP-COLLECT-ANSWER #:LOOP-LIST-HEAD-340))))))
T

ITER> (macroexpand '(iterate (for e in ls) (when (> e 3) (collect e))))
(LET* ((#:LIST5 NIL) (E NIL) (#:RESULT4 NIL) (#:END-POINTER6 NIL) (#:TEMP7 NIL))
  (BLOCK NIL
    (BLOCK #:ITERATE342
      (TAGBODY
        (PROGN (SETQ #:LIST5 LS))
       LOOP-TOP-NIL
        (PROGN
         (IF (ENDP #:LIST5)
             (GO LOOP-END-NIL))
         (SETQ E (CAR #:LIST5))
         (SETQ #:LIST5 (CDR #:LIST5))
         (IF (> E 3)
             (PROGN
              (SETQ #:TEMP7 (LIST E))
              (SETQ #:END-POINTER6
                      (IF #:RESULT4
                          (SETF (CDR #:END-POINTER6) #:TEMP7)
                          (SETQ #:RESULT4 #:TEMP7)))
              #:RESULT4)))
        (PROGN)
        (GO LOOP-TOP-NIL)
       LOOP-END-NIL
        (PROGN))
      #:RESULT4)))
T

Back to pt.comp.programacao | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

mais sobre loops em common lisp Patricia Ferreira <pferreira@example.com> - 2024-03-10 19:28 -0300
  Re: mais sobre loops em common lisp Patricia Ferreira <pferreira@example.com> - 2024-03-10 19:33 -0300
  Re: mais sobre loops em common lisp Daniel Cerqueira <dan.list@lispclub.com> - 2024-03-11 19:42 +0000
    Re: mais sobre loops em common lisp Patricia Ferreira <pferreira@example.com> - 2024-03-11 20:36 -0300

csiph-web