[plt-scheme] Quasiquote and #hash(...)

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Thu Apr 15 12:09:38 EDT 2010

On Thu, Apr 15, 2010 at 12:03 PM, Sam Phillips <samdphillips at gmail.com> wrote:
> I was playing with quasiquote and hashes this morning and came across this:
>
>> (define k 'key)
>> (define v 'val)
>> `#hash((,k . ,v))
> #hash((,k . val))
>
> Is this a bug or intended behavior?
>
> Cheers,
> Sam

This is the intended behavior, as documented with quasiquote:

http://docs.plt-scheme.org/reference/quasiquote.html?q=quasiquote&q=the%20reader#%28form._%28%28lib._scheme/private/letstx-scheme..ss%29._quasiquote%29%29

The #hash form constructs an actual hash table in the resulting syntax
object.  In order to use sensible keys in that hash table, they aren't
stored as syntax -- #hash((1 . 2) (3 . 4)) uses the integers 1 and 3
as keys, for instance, not syntax objects representing the expressions
1 and 3.  The downside is that, not being syntax, they're not
compilable to expressions.  Therefore you can't meaningfully unquote
inside them.

--Carl


Posted on the users mailing list.