Arc Forumnew | comments | leaders | submitlogin
"each" macro binds "self", is this a feature?
6 points by rincewind 6084 days ago | 4 comments
try this: (each _ '(a) (pr self))

Does calling self inside each make any sense? If not, it should be redefined using rfn with a gensym instead of afn.



2 points by Jesin 6084 days ago | link

Ugh, yes. We need to be careful about these sorts of mistakes. In general, no anaphoric macro calls should appear in the macex1 results for anything but an anaphoric macro.

-----

3 points by Jesin 6083 days ago | link

Here's the definition of each from arc.arc:

  (mac each (var expr . body)
    (w/uniq (gseq g)
      `(let ,gseq ,expr
         (if (alist ,gseq)
              ((afn (,g)
                 (when (acons ,g)
                   (let ,var (car ,g) ,@body)
                   (self (cdr ,g))))
               ,gseq)
             (isa ,gseq 'table)
              (maptable (fn (,g ,var) ,@body)
                        ,gseq)
              (for ,g 0 (- (len ,gseq) 1)
                (let ,var (,gseq ,g) ,@body))))))
This should have been:

  (mac each (var expr . body)
    (w/uniq (gseq g gf)
      `(let ,gseq ,expr
         (if (alist ,gseq)
              ((rfn ,gf (,g)
                 (when (acons ,g)
                   (let ,var (car ,g) ,@body)
                   (,gf (cdr ,g))))
               ,gseq)
             (isa ,gseq 'table)
              (maptable (fn (,g ,var) ,@body)
                        ,gseq)
              (for ,g 0 (- (len ,gseq) 1)
                (let ,var (,gseq ,g) ,@body))))))

-----

2 points by stefano 6083 days ago | link

Looks like a bug.

-----

2 points by tung 6083 days ago | link

I've stumbled into this too. I got around it by aliasing self outside of the each form, but yeah, it looks like a bug.

-----