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

From: Neil Toronto (neil.toronto at gmail.com)
Date: Tue Nov 20 21:05:15 EST 2012

(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
>


Posted on the dev mailing list.