[racket-dev] Square-bracket-sensitive macros in Scribble sandboxes

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Nov 20 23:19:35 EST 2012

The day after I wrote this message I wrote such a macro myself -- because it was natural to dispatch on the shape of parentheses. But I will never have to scribble about this one; it just generates HTML for my course. 

But I agree that keywords are much better for this purpose. They wouldn't have worked in my case. My syntax comes from a string and I use it both ways. 

-- Matthias





On Nov 20, 2012, at 9:05 PM, Neil Toronto wrote:

> (Probably. Why are we whispering?)
> 
> Anyway, it occurred to me that I need to provide a more robust way to generate code for literal arrays anyway. Keywords are more easily preserved by macros than syntax properties:
> 
>  (array (array-row 0 1 2 3))
> 
> I think that'll let me use Eli's sneaky eval:alts to display (array [0 1 2 3]) but evaluate (array (array-row 0 1 2 3)).
> 
> Neil ⊥
> 
> On 11/18/2012 08:12 PM, Matthias Felleisen wrote:
>> 
>> (Perhaps this suggests a problem with making a macro depend on the shape of parens around a sub-expression.)
>> 
>> 
>> 
>> 
>> On Nov 18, 2012, at 10:01 PM, Neil Toronto wrote:
>> 
>>> I'm writing the documentation for math/array, and the examples all fail. Here's a simple one:
>>> 
>>>  @examples[#:eval untyped-eval
>>>                   (array [0 1 2 3])]
>>> 
>>> The evaluator raises this error:
>>> 
>>>  application: not a procedure;
>>>   expected a procedure that can be applied to arguments
>>>    given: 0
>>>    arguments...:
>>>     1
>>>     2
>>>     3
>>> 
>>> The problem here is that the `array' macro is sensitive to square brackets, but Scribble doesn't preserve the 'paren-shape syntax property. (Either that, or `examples' only sends lists to the evaluator, not syntax.) So (array [0 1 2 3]) gets evaluated as (array (0 1 2 3)), which looks like a zero-dimensional array containing (0 1 2 3), which is an application of the value `0'. Bad.
>>> 
>>> I know this can work just fine; for example, this does the expected thing in the REPL:
>>> 
>>>  > (eval #'(require math))
>>>  > (eval #'(array [0 1 2 3]))
>>>  (array [0 1 2 3])
>>> 
>>> Is there a way to get Scribble to behave like I expect?
>>> 
>>> Neil ⊥
>>> _________________________
>>> Racket Developers list:
>>> http://lists.racket-lang.org/dev
>> 
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4373 bytes
Desc: not available
URL: <http://lists.racket-lang.org/dev/archive/attachments/20121120/8eea3404/attachment.p7s>

Posted on the dev mailing list.