Arc Forumnew | comments | leaders | submitlogin
2 points by vincenz 6131 days ago | link | parent

I finally found the bug, the problem is that no matter how you pitch it, you have to go through 'eval' to get an actual tagged value, and since eval is done per top-form, you'll never get the first form (annotate 'mac id) to evaluate and form a macro-value to use on 1. Shame :|

While exploring this, I modified the code some more, notice that w.r.t. to the other suggestion I made to ac-call (which was completely backwards compatible), the ac-call here changes only by -1- letter.

    (define (ac-call fn args env)
      (let ((afn (ac fn env))
            (macfn (ac-macro? afn)))
        (cond (macfn
               (ac-mac-call macfn args env))
              ((and (pair? fn) (eqv? (car fn) 'fn))
               `(,afn ,@(map (lambda (x) (ac x env)) args)))
              ((= (length args) 0)
               `(ar-funcall0 ,afn ,@(map (lambda (x) (ac x env)) args)))
              ((= (length args) 1)
               `(ar-funcall1 ,afn ,@(map (lambda (x) (ac x env)) args)))
              ((= (length args) 2)
               `(ar-funcall2 , afn ,@(map (lambda (x) (ac x env)) args)))
              ((= (length args) 3)
               `(ar-funcall3 ,afn ,@(map (lambda (x) (ac x env)) args)))
              ((= (length args) 4)
               `(ar-funcall4 ,afn ,@(map (lambda (x) (ac x env)) args)))
              (#t
               `(ar-apply ,afn
                          (list ,@(map (lambda (x) (ac x env)) args)))))))
    
    ; returns #f or the macro function
    (define (ac-macro? fn)
      (let ((v
              (if (symbol? fn)
                (namespace-variable-value fn
                                          #t
                                          (lambda () #f))
                fn)))
        (if (and v
                 (ar-tagged? v)
                 (eq? (ar-type v) 'mac))
          (ar-rep v)
          #f)))