Page 1 of 1

Disabling macro characters in certain macros/reader macros

Posted: Thu Oct 30, 2008 8:42 pm
by Harnon
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

Re: Disabling macro characters in certain macros/reader macros

Posted: Thu Oct 30, 2008 9:57 pm
by Paul Donnelly
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.

Re: Disabling macro characters in certain macros/reader macros

Posted: Fri Oct 31, 2008 6:43 am
by qbg
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?

Re: Disabling macro characters in certain macros/reader macros

Posted: Fri Oct 31, 2008 4:02 pm
by Harnon
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.