[plt-scheme] paren-shape bug?

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Tue Apr 28 19:22:10 EDT 2009

On Apr 28, 2009, at 6:03 PM, Dimitris Vyzovitis wrote:

> On Tue, 28 Apr 2009, Ryan Culpepper wrote:
>> Beware: if you write macros whose bodies contain square brackets,  
>> those square brackets will turn to round parentheses if you compile  
>> the file. You might want to replace 'syntax' (and 'quasisyntax', et  
>> al) in your language with a version that explicitly preserves those  
>> properties.
> Actually, this is something that has been bugging me for a while  
> with compiled code, but I don't know the right way to fix it.
> The straightforward syntax walk with syntax/quasisyntax wrapper  
> macros doesn't work:
> 1) it results in syntax that still loses properties depending on how  
> you
>   structure it [perhaps that was the bug hitting me in the past, but I
>   hadn't isolated it]
> 2) it incurs quadratic expansion overhead, because syntax wraps are no
>   longer lazy!

I think it's not actually quadratic, because the depth of your syntax  
walk is bounded by the depth that square brackets occur in the  
template. But yes, it's unpleasant. I'm surprised that it still loses  
properties. Exactly how are you doing it?

> I can think of two solutions that work to some extend, but both are  
> problematic.
> 1) quasisyntax and explicitly unsyntax and syntax-property wrap.
>   This is very ugly and it doesn't scale to complex macros.
> 2) Use a reader macro that wraps properties into special purpose  
> macros
>   that force the property when expanded.
> In principle (2) works, but it has a subtle problem: it changes  
> paren semantics in macros and you can no longer use []/{} as visual  
> sugar any more.
> Any ideas on how to fix this problem? Ideally the compiler wouldn't  
> dump the properties as it currently does, but I don't know how  
> feasible this is.

It could also be fixed at the level of 'syntax-case', 'syntax' etc.  
They could store the shape separately from the pattern. You could  
generalize that to storing other properties, too. The code is in  
scheme/private/stxclass and scheme/private/sc, though; I don't see a  
good way to change or reuse it from outside.


Posted on the users mailing list.