[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: modifying the scheme reader in DrScheme



Title: Re: modifying the scheme reader in DrScheme
At 10:56 PM -0800 12/9/01, Michael Vanier wrote:
I have this idea for a minor syntactic extension to the scheme reader that
would allow me to use end tags in s-expressions e.g.

(define (bar x y)
  (if (< x y)
      (* 2 x)
         (* 2 y)
  .if) ; end tag for if
.define) ; end tag for define

The reader checks that the end tags match, and then discards them.

Is there any way to do something like this in DrScheme?  The support for
scheme dialects leads me to think that this should be possible, but I
suspect it's wizard-level programming.

Mike

Why do you need a reader macro for this?  Why not implement this as a simple macro that looks for these tags and discards them if found, ignores them if they're not there, and complains if they're wrong?

So, do a little dance to prevent your if from colliding with the native one, and do something like this:

(syntax-case stx (if .if)
  [(if test then else .if) (syntax real-if then else)]
  [(if test then else) (syntax real-if then else)])

The only disadvantage I can see is that .if is not a magic identifier, and can be used elsewhere as the programmer pleases, leading to some potentially unreadable code.

At the level of individual taste, I wouldn't much want to program this way.  But I tell you what I would be interested in.  Often, when I change a piece of code I mess up the parens in some way (most often forgetting a right-paren in an inserted-code situation.  What I would really go for is an editor binding that would check to see whether drscheme's indenter wants to change the indentation for any of the surrounding lines (that's a fuzzy measure, I know).  If the editor flags any lines as being improperly indented, it probably means that I messed up the parens.

Just a thought.

john