[plt-scheme] Re: How to use a custom procedure as read?

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Mon Sep 29 23:18:20 EDT 2008

Ali wrote:
> On Sep 30, 2:30 am, Chongkai Zhu <c... at cs.utah.edu> wrote:
>> Ali wrote:
>>> Hi,
>>> I'm sorry to ask this question, since it has been asked before, but I
>>> could not make any sense of it at all.
>>> My query is fairly simple, and after an hour or two of searching and
>>> trial and error, I hope I can get the answer an easier way here!
>>> Looked in the reference, this seems to be what I want, but all I'm not
>>> sure exactly how to use it.
>>> http://docs.plt-scheme.org/syntax/reader-helpers.html#(part._module-r...)
>>> <http://docs.plt-scheme.org/syntax/reader-helpers.html#%28part._module...>
>>> Read this and seemed to make sense, but not sure how to apply it to my
>>> problem.
>>> http://www.htus.org/Book/Staging/how-to-use-modules/
>>> I believe the answer is in here, but again, I haven't been able to get
>>> it working.
>>> http://groups.google.com/group/plt-scheme/browse_thread/thread/8aabfc...
>>> <http://groups.google.com/group/plt-scheme/browse_thread/thread/8aabfc...>
>>> Problem:
>>> I've got a Scheme procedure which I would like to temporarily use as
>>> the read procedure, eg.
>>> (swap-the-reader-in)
>>> ... code using custom reader ...
>>> (swap-the-reader-out)
>>> ... normal reader again ...
>>> My MzScheme version is 372. I'd be really grateful for an example of
>>> how to temporarily use a custom procedure as the reader function.
>>> Thanks, Al
>> You should put `code using custom reader' in a separate module that use
>> your own reader, and rest code in other (normal) modules. Hope you can
>> figure out the rest on your own by reading the docs.
>> Chongkai
>> _________________________________________________
>>   For list-related administrative tasks:
>>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> Thanks. Do I have to write the code in a module? I'd much rather be
> able to swap in and out of the custom reader mode as with above.

Yes, you do have to write the code in a module. Then you can set the 
reader for that module.

> I'm sure that I can figure it out from the docs, but couldn't say how
> long it will take, and I really don't enjoy spending hours upon hours
> on a seemingly small problem.
> Now I know its equally annoying for you to receive an email from a
> mere newb who just_doesn't_get_it, but in my humble opinion there is
> one too few simple examples of how to do this in MzScheme and it would
> be really really nice if someone can post it.
> Heck, if someone equally as dumb as me has the same problem later on,
> it will already have a bow on it with this thread.
> Can I re-iterate: I have looked for the answer. The problem is that my
> attempts have led to excitement when I thought I had it, and lots and
> lots of despair after each fail.
> All I need is a tiny code example of how to change the reader to a
> procedure called "custom-reader".
> (set! read custom-reader)
> was my first thought, but didn't work. Really hope someone can help on
> this while I still have hair.

No, it doesn't work this way.


Posted on the users mailing list.