Arc Forumnew | comments | leaders | submitlogin
"." not allowed in quasiquote?
5 points by jimbokun 6128 days ago | 4 comments
arc> (fn (name . args) args) #<procedure> arc> ((fn (name . args) args) 'a 'b 'c) (b c) arc> `(fn (name . args) args) Error: "map: expects type <proper list> as 2nd argument, given: (name . args); other arguments were: #<procedure:...v352/arc0/ac.scm:167:14>"

It appears that the "." character breaks quasiquotation. An implication of this is that macros cannot define functions that take a variable number of arguments.

Is there a way around this? Thoughts on how to fix?

Thanks.



3 points by nex3 6128 days ago | link

Properly formatted:

  arc> (fn (name . args) args)
  #<procedure>
  arc> ((fn (name . args) args) 'a 'b 'c)
  (b c)
  arc> `(fn (name . args) args)
  Error: "map: expects type <proper list> as 2nd argument, given: (name . args); other arguments were: #<procedure:...v352/arc0/ac.scm:167:14>"
This does seem to be a bug, though.

-----

3 points by zackman 6127 days ago | link

Scheme's map doesn't handle improper lists, I guess. On line 167 of ac.scm, replace the following expression:

  (map (lambda (x) (ac-qq1 level x env)) x)
with

  (let loop ((x x) (acc '()))
    (cond ; inline map to handle improper lists
      ((null? x) (reverse acc)) ;properly terminated list
      ((pair? x) (loop (cdr x) (cons (ac-qq1 level (car x) env) acc)))
      (else (append (reverse acc) (ac-qq1 level x env)))))
I realise it looks stupid to write an inline map that handles improper lists. Is there a better way to do this?

-----

3 points by zackman 6127 days ago | link

This works around the bug for variable arguments, at least.

  arc> `(fn ,(cons 'name 'args) args)
  (fn (x . args) args)

-----

1 point by jimbokun 6127 days ago | link

Thanks! I think this will work best for me for now. But the suggested change to ac.scm is probably the best fix long term.

-----