Arc Forumnew | comments | leaders | submitlogin
4 points by rntz 5663 days ago | link | parent

IIRC, Scheme handles nested quasiquoting differently than Common Lisp - expands the unquotes in a different order or some such. I've been meaning to figure out precisely how they differ at some point, but I suspect that merely taking code involving nested quasiquoting from lisp and transplanting it to Arc will not work; Arc code involving quasiquoting translates down fairly directly to Scheme.

Arc doesn't report an error because the second argument to unquote gets tossed out during compilation:

    arc> :a
    > (ac '`(foo (unquote bar baz)) '())
    (quasiquote (foo (unquote _bar)))
(In case you're unfamiliar with what just happened: ':a at the arc interpreter drops you into scheme, at which point you can access the internals of arc's compiler. (ac code env) compiles the Arc code 'code to scheme, where 'env is a list of locally-bound identifiers in scope.)

This is actually a fairly common "bug" in arc's compiler. The same thing happens with coerce:

    arc> (coerce 2 'int (prn "this is ignored"))
    this is ignored
    2
This is because 'coerce underneath (well, unless you're using my programmable coercion hack, which fixes the above) is just one big function of the form (lambda (x type . args) ...), and unless args is used, it's ignored. args is used, for example, in (coerce "f" 'int 16), in which 16 stands for the base in which "f" is to be read as an integer.


1 point by fallintothis 5663 days ago | link

Scheme handles nested quasiquoting differently than Common Lisp - expands the unquotes in a different order or some such.

Well, if we're to believe a single statement in an Alan Bawden paper from 1999: "I am not aware of the existence of a correct optimizing quasiquotation expander for Scheme. (None of the Scheme implementations that I tested implement nested splicing correctly.)" -- http://repository.readscheme.org/ftp/papers/pepm99/bawden.pd...

The entire semantic reasoning is what I'm hung up on: does it seem right that ,,@(...) isn't supposed to work? Not that I'm necessarily advocating one rationale over another, just that I've simply not heard any such rationale. (My Google-fu is upsettingly weak here.)

Arc doesn't report an error because the second argument to unquote gets tossed out during compilation

Ah, duh. Makes sense. I had tried combing through the compiler, but was rather aimless. Thanks.

This is actually a fairly common "bug" in arc's compiler.

I'd probably call it a bug in the case of 'coerce, since the arguments (being passed directly to a Scheme function) all get evaluated -- if the third argument was truly ignored (in the "compiled away" sense), then it shouldn't even do anything. Plus, this behavior also reaches functions like 'outfile and (to an extent) 'writec.

Granted, maybe it's wise to go against "protecting" the programmer and assume that they know what they're doing; maybe I'd happen to want to assign a variable in the same statement as an 'outfile, I don't know.

-----

2 points by CatDancer 5663 days ago | link

does it seem right that ,,@(...) isn't supposed to work?

Doing some googling, I see that this bug was reported against plt scheme in 2002: http://www.cs.brown.edu/pipermail/plt-scheme/2002-June/00004...

R6RS takes the approach of allowing (unquote 1 2 3). Section 11.17 of the standard has this example:

  (let ((name 'foo))
    `((unquote name name name)))
          => (foo foo foo)

-----

1 point by fallintothis 5663 days ago | link

Good find, thanks. Now it at least makes sense to call this a bug (well, others have at any rate), though not specifically in Arc.

-----