Disabling macro characters in certain macros/reader macros

Discussion of Common Lisp

Disabling macro characters in certain macros/reader macros

Postby Harnon » Thu Oct 30, 2008 8:42 pm

I have been wanting to do this for a long time, but i didn't believe it was possible. So here it goes!
I want to make a reader macro in which the entries are separated by commas. I don't want to separate by spaces
because the entries should allow spaces. While i could use another separation character, commas are the standard
and I would prefer to use them.
I want it to look like this:

{3,4,5,3,2}

I know that you can disable reader macro characters for a whole package, but what about for a specific reader macro? Notice, though, that i would also like other reader macros to be recognized inside of the curly braces, just not the comma.
Is this possible with a reader macro? What about for a regular macro, like which follows?

(deflet (int i=0,int d = 1, int dd = 2) ;;body here)

Thxs! :D
Harnon
 
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am

Re: Disabling macro characters in certain macros/reader macros

Postby Paul Donnelly » Thu Oct 30, 2008 9:57 pm

With reader macros, you can do whatever you like. Reader macros are somewhat misleadingly named—they're actually functions that read your code as text, then return a Lisp form. When implementing a reader macro you can, at your option, use READ for all or part of your parsing, or you can elect to parse in any other way you like. As long as you return valid Lisp code, all is well.
Paul Donnelly
 
Posts: 148
Joined: Wed Jul 30, 2008 11:26 pm

Re: Disabling macro characters in certain macros/reader macros

Postby qbg » Fri Oct 31, 2008 6:43 am

Couldn't you in your reader macro function make a copy of the current readtable, modify the characters you need, and then dynamically bind it to *readtable* so once your reader macro function exits, the readtable will be returned to what it was before?
qbg
 
Posts: 64
Joined: Mon Jun 30, 2008 1:05 pm
Location: Minnesota

Re: Disabling macro characters in certain macros/reader macros

Postby Harnon » Fri Oct 31, 2008 4:02 pm

Thxs :) for the replies. You're right, I realize now that the reader reads the code as text, not as lisp code, unless you use the read function on the stream. Also, you can change the readtable with the set-dispatch-macro-character function. I suppose i'll have to read it as a string and then parse and then use read funcytion on the areas where i want the reader macros to be available in the reader macro.
Harnon
 
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am


Return to Common Lisp

Who is online

Users browsing this forum: Bing [Bot] and 2 guests