Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > pt.comp.programacao > #281
| Path | csiph.com!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Patricia Ferreira <pferreira@example.com> |
| Newsgroups | pt.comp.programacao |
| Subject | Re: mais sobre loops em common lisp |
| Date | Sun, 10 Mar 2024 19:33:48 -0300 |
| Organization | A noiseless patient Spider |
| Lines | 65 |
| Message-ID | <878r2pogxf.fsf@example.com> (permalink) |
| References | <87frwxoh5l.fsf@example.com> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Info | dont-email.me; posting-host="3676b724aa3c0867a5e40ead515e7a4e"; logging-data="3368165"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/fNe7rYFQpZsmAwg7fK4xDZ9HybiOYRo=" |
| Cancel-Lock | sha1:eqjJiuZWNEXa6vg/wtwd1YYyu7Y= sha1:mGP1/w689i8bG+LjNTub6RjD0cA= |
| Xref | csiph.com pt.comp.programacao:281 |
Show key headers only | 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 | Next — Previous in thread | Next in thread | Find similar
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