[iterate-devel] Problem with DEFCLAUSE-DRIVER

Marco Antoniotti antoniotti.marco at disco.unimib.it
Fri Mar 14 15:39:01 UTC 2008


Hi

I am trying again to extend ENUMERATIONs with ITERATE.  Here is my try

;;;; -*- Mode: Lisp -*-

;;;; iterate-enumeration.lisp --
;;;; ITERATE extension for ENUMERATIONs.

(in-package "ITERATE")

(defclause-driver (FOR var OVER enum)
   (let ((e (gensym "ENUM-"))
         (kwd (if generate 'generate 'for))
         )
     `(progn
        (with ,e = ,enum)
        (,kwd ,var next (if (enum:has-more-elements-p ,e)  
(enum:next ,e) (terminate))))))

;;;; end of file -- iterate-enumeration.lisp --


However I get this error when I try it.

===========
CL-USER 31 > (iter (for x over (enum:range 3 8))
               (collect (1+ x)))

Error: Undefined operator WITH in form (WITH #:ENUM-7002 =  
(CL.EXTENSIONS.ENUMERATIONS:RANGE 3 8)).
   1 (continue) Try invoking WITH again.
   2 Return some values from the form (WITH #:ENUM-7002 =  
(CL.EXTENSIONS.ENUMERATIONS:RANGE 3 8)).
   3 Try invoking something other than WITH with the same arguments.
   4 Set the symbol-function of WITH to another function.
   5 Set the macro-function of WITH to another function.
   6 (abort) Return to level 0.
   7 Return to top loop level 0.

Type :b for backtrace, :c <option number> to proceed,  or :? for  
other options

===========

And I get the following, seemingly bogus macroexpansion.


===========

CL-USER 38 > (pprint (macroexpand-1 '(iter (for x over (enum:range 3 8))
                                        (collect (1+ x)))))

(LET* ((#:RESULT57 NIL) (#:END-POINTER58 NIL) (#:TEMP59 NIL))
   (BLOCK NIL
     (TAGBODY
      LOOP-TOP-NIL PROGN (WITH #:ENUM-7006 =  
(CL.EXTENSIONS.ENUMERATIONS:RANGE 3 8))
              (FOR
               X
               NEXT
               (IF (CL.EXTENSIONS.ENUMERATIONS:HAS-MORE-ELEMENTS-P  
#:ENUM-7006)
                   (CL.EXTENSIONS.ENUMERATIONS:NEXT #:ENUM-7006)
                 (TERMINATE)))
              (PROGN
                (SETQ #:TEMP59 (LIST (1+ X)))
                (SETQ #:END-POINTER58 (IF #:RESULT57 (SETF (CDR #:END- 
POINTER58) #:TEMP59) (SETQ #:RESULT57 #:TEMP59)))
                #:RESULT57)
              (GO LOOP-TOP-NIL))
     #:RESULT57))

===========
I feel there is a but either in the manual or in the code.  Which is  
which?

Cheers

--
Marco Antoniotti





More information about the iterate-devel mailing list