Arc Forumnew | comments | leaders | submitlogin
Confusing Macro Error
2 points by mec 6108 days ago | 6 comments
There are a lot of functions that take (first . last) as arguments so to play around with a few ideas I wanted to make a macro to expand to this, but I'm getting a confusing error message that I don't understand:

  arc> (mac myfn body 
         `(fn (frst . rest) ,@ body))
  Error: "map: expects type <proper list> as 2nd argument, given: (frst . rest); other arguments were: #<procedure:...arc1\\arc1\\ac.scm:209:14>"


4 points by vsingh 6108 days ago | link

That looks like a bug to me. This works fine:

    (mac myfn body
        `(fn ,(cons 'frst 'rest) ,@body))

-----

1 point by mec 6108 days ago | link

Thanks! That fix also allowed me to get (_ . __) to work for [] as well which was giving the same error. Now, time to play around with multivar anonymous functions.\

Edit: Well never mind then, that change doesn't work in brackets.scm either so back to just playing with the macro.

-----

4 points by pg 6108 days ago | link

The problem may be the space after the @.

-----

5 points by cadaver 6108 days ago | link

The '(frst . rest)' signals an error before compilation reaches the ,@.

The problem is, I think, that ac-qq1 doesn't expect to encounter an improper list. So, with arc1 you can't use a dot in a quasiquote to denote an improper list.

However, as vsingh pointed out, an unescaped cons operation will get you an improper list in a quasiquote where a dot doesn't.

This seems like a bug indeed, and it is easy to fix, simply replace this in ac-qq1:

  ((pair? x)
   (map (lambda (x) (ac-qq1 level x env)) x)))
with this:

  ((pair? x)
   (cons (ac-qq1 level (car x) env) (ac-qq1 level (cdr x) env)))

-----

1 point by mec 6107 days ago | link

Very nice fix, with that I can finally do

  (define (read-square-brackets ch port src line col pos)
    `(fn (_ . __)
       ,(read/recursive port #\[ #f)))

-----

2 points by mec 6107 days ago | link

The space was a typo when writing the post, not in the code.

-----