[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LOOP question



I agree that Lucid's behavior is more intuitive.  CMU Lisp also does
it this way:

(loop for i in '(1 2 3)
      for j = (1+ i)
      for k = (1- i)
      do (print (list j k))
      collect (* j k))
(2 0) (3 1) (4 2) (0 3 8)

instead of:
(loop for i in '(1 2 3)
      for j = (1+ i) for k = (1- i) 
      do (print (list j k))
      collect (* j k)) 
(2 0) (3 1) (4 2)
*** - argument to 1+ should be a number: NIL 
1. Break>

Can someone make an argument for keeping CLISP the way it is?
Anyway, here's a patch to change the behavior.  Let me know..

*** /a/marcus/loop.lsp	Sun Sep 10 03:38:55 1995
--- clisp/src/loop.lsp	Tue Sep 12 11:02:18 1995
***************
*** 590,599 ****
                                       (when step-function-var
                                         (push `(,step-function-var ,step-function-form) bindings)
                                       )
-                                      (push `(WHEN (ENDP ,var) (LOOP-FINISH)) stepbefore-code)
                                       (note-initialisation t nil
                                         'LET
!                                        (destructure pattern (if (eq preposition 'IN) `(CAR ,var) `,var))
                                         new-declspecs
                                       )
                                       (push
--- 590,602 ----
                                       (when step-function-var
                                         (push `(,step-function-var ,step-function-form) bindings)
                                       )
                                       (note-initialisation t nil
                                         'LET
!                                        (destructure pattern 
!                                          `(IF ,var
!                                            ,(if (eq preposition 'IN) `(CAR ,var) `,var)
!                                            (LOOP-FINISH)
!                                        )   )
                                         new-declspecs
                                       )
                                       (push
***************
*** 629,640 ****
                                         (index-var (gensym)))
                                     (push `(,vector-var ,vector-form) bindings)
                                     (push `(,index-var 0) bindings)
!                                    (push `(WHEN (>= ,index-var (LENGTH ,vector-var)) (LOOP-FINISH))
!                                          stepbefore-code
!                                    )
!                                    (note-initialisation t t
                                       'LET
!                                      (destructure pattern `(AREF ,vector-var ,index-var))
                                       new-declspecs
                                     )
                                     (push (list index-var `(1+ ,index-var)) stepafter)
--- 632,644 ----
                                         (index-var (gensym)))
                                     (push `(,vector-var ,vector-form) bindings)
                                     (push `(,index-var 0) bindings)
!                                    (note-initialisation t nil
                                       'LET
!                                      (destructure pattern
!                                        `(IF (>= ,index-var (LENGTH ,vector-var))
!                                          (LOOP-FINISH)
!                                          (AREF ,vector-var ,index-var)
!                                       ) )
                                       new-declspecs
                                     )
                                     (push (list index-var `(1+ ,index-var)) stepafter)