[comp.lang.lisp] LOOP for Common Lisp?

gb@vax135.UUCP (Gary Bishop) (06/08/87)

Is there a version of the LOOP iteration macro from MIT for common lisp?
If so, how can I get it.

Thanks,
G tin .)

dsouza@hplabsc.UUCP (Roy D'Souza) (06/10/87)

The HP LOOP macro is our proposed iteration macro for Common Lisp.
If you would like a copy of the sources and documentation, please
send me your e-mail address. (Your US Mail address will get you a
hardcopy of the manual)

Roy D'Souza
dsouza@hplabs.hp.com

Here are some examples of usage:

; The traditional WHILE loop (test at the beginning):
  (loop (:while (> x 0))
    (setf x (- x 1))
    (setf y (f y x)))

; The traditional REPEAT loop (test at the end):
  (loop
    (setf x (f x))
    (setf y (g y))
    (:until (p x y)))    

; Printing the elements of a list L:
  (loop
    (:in x (the list l))
    (print x))

; Producing a vector of squares:
  (loop (:with i :from 1 :to 10)
        (:vector (* i i)))

   ==> #(1 4 9 16 25 36 49 64 81 100)

; Counting the number of elements in a list L:
  (loop
    (:in x l)
    (:count))

; Given a list, produce a list of conses (element . index):
  (loop (:in x '(a b c d e f))
        (:with i)
        (:list (cons x i)))

   ==> ((a . 0) (b . 1) (c . 2) (d . 3) (e . 4) (f . 5))

; Given a list, produce two lists of conses, one
; (element . index), the other
; (index . element):

  (loop (:in x '(a b c d))
        (:with i)
        (:list (cons x i) :into list1)
        (:list (cons i x) :into list2)
        (:result (values list1 list2)))

  ==>  ((a . 0) (b . 1) (c . 2) (d . 3))
       ((0 . a) (1 . b) (2 . c) (3 . d))

; Produce a table of length and length-squared from an input list of lists:
  (loop (:in x '((a) (b c d)))
        (:var n (length x))
        (:list (list n (* n n))))

   ==> ((1 1) (3 9))

; Given a list of conses, split it apart to produce two lists:
  (loop (:in u '((a . 1) (b . 2) (c . 3)))
        (:list (car u) :into list1)
        (:list (cdr u) :into list2)
        (:result (values list1 list2)))

   ==> (a b c) (1 2 3)

; Counting elements in a list L using the style of DO:
  (loop
    (:for x l (cdr x))
    (:for j 0 (+ j 1))
    (:until (endp x))
    (:result j))

kscott@ucsfcgl.UUCP (06/10/87)

In article <1792@vax135.UUCP> gb@vax135.UUCP (Gary Bishop) writes:
>Is there a version of the LOOP iteration macro from MIT for common lisp?

If anyone can steer me to the LOOP macro, whether or not it comes from
MIT (No offense to MIT, I admire their work) I would appreciate it.

tsf@theory.cs.cmu.edu (Timothy Freeman) (06/10/87)

In article <10237@cgl.ucsf.EDU> kscott@cgl.ucsf.edu.UUCP (Kevin Scott) writes:
>If anyone can steer me to the LOOP macro, whether or not it comes from
>MIT (No offense to MIT, I admire their work) I would appreciate it.

There is a Common Lisp version available via anonymous ftp from
r20.texas.edu from the file <atp.schelter>sloop.lisp.  It's named
sloop instead of loop because there is already a macro named loop in
Common Lisp.

If you want this but can't fetch it, let me know and I'll mail you my copy.
-- 
Tim Freeman

Arpanet: tsf@theory.cs.cmu.edu
Uucp:    ...!seismo!theory.cs.cmu.edu!tsf