Subject: [clisp-list] Possible problem with loop macro

From: Dan Stanger <[email-masked]>
Date: Sun Mar 17 19:26:03 2002

I am trying to port some code from cmucl to clisp, and I think I have
found a problem with the
loop macro.  In the following code the exit condition while op-fun seems
to occur after the
call to parse-cast-expression, which is what term-fun is bound to.
Is this syntax for the loop macro correct?  I think that when the macro
is expanded, it
produces a warning, indicating that for clauses should occur before the
loops main body.
I would appreciate any sugestions on this.  This is with clisp 2.27 on
linux.
Thanks,
Dan Stanger

(defmacro def-expr-expression (expr-fun term-fun op-list)
  (let ((op-alist (mapcar #'(lambda (op)
                              (cons (car op) (cadr op)))
                          op-list)))
    `(let ((op-alist ',op-alist))
       (defun ,expr-fun (lstream)
         (loop
          with result = (,term-fun lstream)
          for op = (look lstream)
          for op-fun = (cdr (assoc op op-alist))
          while op-fun
          for term = (progn
                       (consume lstream)
                       (,term-fun lstream))
          do (setq result (funcall op-fun *compiler-implementation*
                                   result term))
          finally (return result))))))

EVAL frame for form
(TAGBODY SYSTEM::BEGIN-LOOP
 (PROGN (PSETQ CPARSE::OP (CPARSE::LOOK CPARSE::LSTREAM))
  (PSETQ CPARSE::OP-FUN (CDR (ASSOC CPARSE::OP CPARSE::OP-ALIST)))
  (PSETQ CPARSE::TERM (PROGN (CPARSE::CONSUME CPARSE::LSTREAM)
(CPARSE::PARSE-CAST-EXPRESSION CPARSE::LSTREAM))))
 (PROGN (UNLESS CPARSE::OP-FUN (GO SYSTEM::END-LOOP))
  (SETQ CPARSE::RESULT (FUNCALL CPARSE::OP-FUN
CPARSE::*COMPILER-IMPLEMENTATION* CPARSE::RESULT CPARSE::TERM)))
 (GO SYSTEM::BEGIN-LOOP) SYSTEM::END-LOOP (RETURN-FROM NIL
CPARSE::RESULT))
1. Break [107]>

---

From: Sam Steingold <[email-masked]>
Date: Sun Mar 17 20:50:06 2002

> * In message <[email-masked]>
> * On the subject of "[clisp-list] Possible problem with loop macro"
> * Sent on Sun, 17 Mar 2002 20:27:12 -0700
> * Honorable Dan Stanger <[email-masked]> writes:
>
> Is this syntax for the loop macro correct?

no, you cannot have "for" after "while".
see the BNF in CLHS

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat7.2 GNU/Linux
Keep Jerusalem united! <http://www.onejerusalem.org/Petition.asp>
Read, think and remember! <http://www.iris.org.il> <http://www.memri.org/>
Don't ascribe to malice what can be adequately explained by stupidity.