[plt-scheme] read-syntax/recursive in reader problem

From: Jos Koot (jos.koot at telefonica.net)
Date: Sun Dec 21 09:47:01 EST 2008

Hi Matthew,
I'll try that out quickly. Thanks very much for the clear and quick 
response.
By saying that I should "produce syntax objects with no lexical information" 
you probably solved another problem too, I was strubbling with (in casu 
identifiers becoming associated with other imports than intended)
Thanks again, Jos.

----- Original Message ----- 
From: "Matthew Flatt" <mflatt at cs.utah.edu>
To: "Jos Koot" <jos.koot at telefonica.net>
Cc: <plt-scheme at list.cs.brown.edu>
Sent: Sunday, December 21, 2008 3:07 PM
Subject: Re: [plt-scheme] read-syntax/recursive in reader problem


> At Sun, 21 Dec 2008 14:56:15 +0100, "Jos Koot" wrote:
>> Please help me with the following problem extracted from a larger piece 
>> of
>> code.
>> I have in .../collects/problem/lang the following two files:
>>
>> ;file reader.ss
>> (module reader syntax/module-reader scheme
>>  #:wrapper1
>>  (lambda (t)
>>   (parameterize ((current-readtable readtable))
>>    (t)))
>>
>>  (define read-braces
>>   (case-lambda
>>    ((ch port src line col pos)
>>   #`(lambda #,@(read-syntax/recursive 'problem port #\{)))
>>    ((ch port)
>>     (cons 'lambda (read/recursive port #\{)))))
>>
>>  (define readtable
>>   (make-readtable #f #\{
>>   'terminating-macro read-braces)))
>>
>> and
>>
>> ;file test.ss
>> #lang problem
>> ({x x} 1 2 3) ; to be read as ((lambda x x) 1 2 3)
>> ; mark the two braces.
>>
>> When I try to run test.ss it keeps eating memory in the compilation phase
>> until memory limits are exceeded (700Mb) DrScheme's run icon remains 
>> standing
>> still. I guess the reader is getting into an infinite regression, but I 
>> fail
>> to see how to avoid that problem.
>
> You're right that parsing #\{ again just re-invokes your reader.
>
> To say that you mean to parse #\{ as with the default reader, just add
> an extra #f argument to your `read[-syntax]/recursive' calls:
>
> (define read-braces
>  (case-lambda
>   ((ch port src line col pos)
>  #`(lambda #,@(read-syntax/recursive 'problem port #\{ #f)))
>   ((ch port)
>    (cons 'lambda (read/recursive port #\{ #f)))))
>
> Also, the syntax case is't quite right. When you use `quasisyntax',
> then the `lambda' ends up with lexical information, but a reader should
> produce syntax objects with no lexical information. I recommend using
> `datym->syntax', instead:
>
> (define read-braces
>  (case-lambda
>   ((ch port src line col pos)
>    (datum->syntax #f `(lambda
>                         . ,(read-syntax/recursive 'problem port #\{ #f)))
>   ((ch port)
>    (cons 'lambda (read/recursive port #\{ #f)))))
>
> 



Posted on the users mailing list.