Arc Forumnew | comments | leaders | submitlogin
1 point by absz 6019 days ago | link | parent

You need to initialize v to nil so that it exists. The with binding creates a v that can be set. But you're right, there doesn't seem to be a reason you need the gensym.


2 points by skenney26 6019 days ago | link

Thanks for the help absz. I'm creating a variety of iterators for a graphics app and I just want to make sure they're being written correctly.

I still don't quite understand why v needs to be initialized. For example, the following definition seems to work fine:

  (mac for (v init max . body)
    (w/uniq gm
     `(let ,gm (+ ,max 1)
        (loop (set ,v ,init) (< ,v ,gm) (set ,v (+ ,v 1))
          ,@body))))

-----

2 points by absz 6019 days ago | link

The problem is that if you define it this way, then your v is no longer lexical; instead, it's in the global namespace. Thus, writing (for ref 0 n (frob ref)) would overwrite the global ref procedure, which is not what you want.

-----

1 point by skenney26 6019 days ago | link

Ah, it finally makes sense. Thanks again.

-----