<div>Hi,<br clear="all"></div><div><br></div><div>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:</div>
<div>"We can now refer to parameters from, to, by, etc. which contain either the values for<br>the corresponding keyword, or nil if the keyword was not supplied. Implementing the right<br>code for these keywords is cumbersome but not difficult; it is left as an exercise."<br>
</div><div><br></div><div>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:</div><div><br>(defmacro-driver (FOR var IN-WHOLE-VECTOR v &sequence)<br>
"All the elements of a vector (disregards fill-pointer)"<br>
(let ((vect (gensym))<br> (end (gensym))<br> (index (gensym)) <br> (myfrm (gensym "myfrm"))<br> (kwd (if generate 'generate 'for)))<br>
`(progn<br> (with ,vect = ,v) <br> (with ,myfrm = ,from)<br> (with ,end = (array-dimension ,vect 0))<br>
(with ,index = -1)<br> (,kwd ,var next (progn (incf ,index)<br> (if (>= ,index ,end) (terminate))<br>
(format t "myfrm: ~a~%" ,myfrm)<br> (aref ,vect ,index))))))</div><div><br>
</div>
<div>I tried using the driver with: (a is an array of 10 elements)<br>(iter (for v in-whole-vector a from 5 below 8)<br> (print v))<br><br>I get the following error:<br></div><div> The variable FROM is unbound.<br>
[Condition of type UNBOUND-VARIABLE]<br><br>Restarts:<br> 0: [RETRY] Retry SLIME REPL evaluation request.<br> 1: [*ABORT] Return to SLIME's top level.<br> 2: [ABORT] Exit debugger, returning to top level.<br><br>Backtrace:<br>
0: ((DEFMACRO CLAUSE-FOR-IN-WHOLE-VECTOR-18) (CLAUSE-FOR-IN-WHOLE-VECTOR-18 :FOR V :IN-WHOLE-VECTOR A :FROM ...) #<unused argument>)<br> 1: (MACROEXPAND-1 (CLAUSE-FOR-IN-WHOLE-VECTOR-18 :FOR V :IN-WHOLE-VECTOR A :FROM ...) #<NULL-LEXENV>)<br>
2: (ITERATE::PROCESS-CLAUSE (FOR V IN-WHOLE-VECTOR A FROM 5 ...))<br> 3: (ITERATE::WALK (FOR V IN-WHOLE-VECTOR A FROM 5 ...))<br> 4: (ITERATE::WALK-LIST-NCONCING ((FOR V IN-WHOLE-VECTOR A FROM 5 ...) (PRINT V)) #<FUNCTION ITERATE::WALK> #<FUNCTION (LAMBDA #) {100407D489}>)<br>
5: (ITERATE::WALK-LIST ((FOR V IN-WHOLE-VECTOR A FROM 5 ...) (PRINT V)))<br> 6: ((DEFMACRO ITER) ..)<br><br></div><div>I am using ubuntu maverick, 10.10, SBCL 1.0.45 64 bit.</div><div><br></div><div>I tried the following:<br>
(with ,myfrm = from)<br><br> I get an error:<br>The variable FROM is unbound.<br> [Condition of type UNBOUND-VARIABLE]<br><br>Restarts:<br> 0: [RETRY] Retry SLIME REPL evaluation request.<br> 1: [*ABORT] Return to SLIME's top level.<br>
2: [ABORT] Exit debugger, returning to top level.<br><br>Backtrace:<br> 0: ((LAMBDA ()))<br> 1: (SB-INT:SIMPLE-EVAL-IN-LEXENV ..)<br> 2: (SWANK::EVAL-REGION "(iter (for v in-whole-vector a from 5 below 8)\n (print v))\n")<br>
3: ((LAMBDA ()))<br><br><br>2) (with ,myfrm = :from)<br>This does not throw any error, but just prints <br>myfrm: FROM<br>instead of the value given<br><br>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? <br>
<br>
<br></div><br>-- <br>Audentis fortuna juvat<br>