[iterate-devel] defclause-driver with &sequence

Venkatesan S svtesan at gmail.com
Sun Jan 23 11:14:00 UTC 2011


Hi,

I was trying to roll an iterate driver for iterating over dates and I am
stuck with a problem. When using defmacro-driver, I am unable to get the
value passed in from to and other sequence classes. I tried with the example
given in the manual (chapter "Rolling your own"), but hit the same problem.
The manual says:
"We can now refer to parameters from, to, by, etc. which contain either the
values for
the corresponding keyword, or nil if the keyword was not supplied.
Implementing the right
code for these keywords is cumbersome but not difficult; it is left as an
exercise."

But I guess I am one of the dumb few who failed the exercise :)) The
following is my attempt with the example given in the manual:

(defmacro-driver (FOR var IN-WHOLE-VECTOR v &sequence)
      "All the elements of a vector (disregards fill-pointer)"
      (let ((vect (gensym))
              (end (gensym))
              (index (gensym))
              (myfrm (gensym "myfrm"))
              (kwd (if generate 'generate 'for)))
              `(progn
                            (with ,vect = ,v)
                            (with ,myfrm = ,from)
                            (with ,end = (array-dimension ,vect 0))
                            (with ,index = -1)
                            (,kwd ,var next (progn (incf ,index)
                            (if (>= ,index ,end) (terminate))
                                          (format t "myfrm: ~a~%" ,myfrm)
                                          (aref ,vect ,index))))))

I tried using the driver with: (a is an array of 10 elements)
(iter (for v in-whole-vector a from 5 below 8)
                 (print v))

I get the following error:
 The variable FROM is unbound.
   [Condition of type UNBOUND-VARIABLE]

Restarts:
 0: [RETRY] Retry SLIME REPL evaluation request.
 1: [*ABORT] Return to SLIME's top level.
 2: [ABORT] Exit debugger, returning to top level.

Backtrace:
  0: ((DEFMACRO CLAUSE-FOR-IN-WHOLE-VECTOR-18)
(CLAUSE-FOR-IN-WHOLE-VECTOR-18 :FOR V :IN-WHOLE-VECTOR A :FROM ...) #<unused
argument>)
  1: (MACROEXPAND-1 (CLAUSE-FOR-IN-WHOLE-VECTOR-18 :FOR V :IN-WHOLE-VECTOR A
:FROM ...) #<NULL-LEXENV>)
  2: (ITERATE::PROCESS-CLAUSE (FOR V IN-WHOLE-VECTOR A FROM 5 ...))
  3: (ITERATE::WALK (FOR V IN-WHOLE-VECTOR A FROM 5 ...))
  4: (ITERATE::WALK-LIST-NCONCING ((FOR V IN-WHOLE-VECTOR A FROM 5 ...)
(PRINT V)) #<FUNCTION ITERATE::WALK> #<FUNCTION (LAMBDA #) {100407D489}>)
  5: (ITERATE::WALK-LIST ((FOR V IN-WHOLE-VECTOR A FROM 5 ...) (PRINT V)))
  6: ((DEFMACRO ITER) ..)

I am using ubuntu maverick, 10.10, SBCL 1.0.45 64 bit.

I tried the following:
(with ,myfrm = from)

 I get an error:
The variable FROM is unbound.
   [Condition of type UNBOUND-VARIABLE]

Restarts:
 0: [RETRY] Retry SLIME REPL evaluation request.
 1: [*ABORT] Return to SLIME's top level.
 2: [ABORT] Exit debugger, returning to top level.

Backtrace:
  0: ((LAMBDA ()))
  1: (SB-INT:SIMPLE-EVAL-IN-LEXENV ..)
  2: (SWANK::EVAL-REGION "(iter (for v in-whole-vector a from 5 below
8)\n                 (print v))\n")
  3: ((LAMBDA ()))


2) (with ,myfrm = :from)
This does not throw any error, but just prints
myfrm: FROM
instead of the value given

I want to use defclause-driver with the sequence keywords, I could not
figure out how to get the values passed in from, to and other such clauses.
Can anyone please provide some pointers?



-- 
Audentis fortuna juvat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/iterate-devel/attachments/20110123/c9fa51de/attachment.html>


More information about the iterate-devel mailing list