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

Re: Syntax Recognition



    It would be nice if T would recognize the longest possible syntax when
    scanning for syntax.  For instance, I currently have two macros:

        ?X  -->  (*var* . x)

    and

            (?- head) -->  a prolog form

    Unfortunately, the "?-" syntax doesn't work because the "?-" gets
    converted to "(*var* . x)" by the other syntax.  I think a better
    recognition algorithm would be to have the longest possible syntax
    recognized.

                                                -- Scott

If I understand you, I think your confusing readmacros with syntax.
If you've defined a readmacro for #\? that looks like this:

(lambda (stream char read-table)
  (ignore char read-table)
  `(*var* . ,(read stream)))

then you can hardly blame READ for converting "?-" into "(*var* . -)",
which is what I assume you meant to say.  The recognition of syntax,
e.g., (DEFINE-SYNTAX (?- ...)  ...), is done by STANDARD-COMPILER, which
runs after READ has finished.

You can probably get the effect you want by making #\? a more complicated
readmacro, like the dispatch readmacro for #\#, but with the capability
of actually constructing a symbol whose first character is #\?.

(lambda (stream char read-table)
  (ignore char read-table)
  (let* ((next-char (peekc stream))
         (next-form (read stream)))
    (if (alphabetic? next-char)                   ;hack
        `(*var* . ,next-form)
        (concatenate-symbol "?" next-form))))     ;ugh

This is pretty gross, especially since PRINT will put backslashes in front
of all such symbols; e.g., "\?-".   You probably don't want to do this
at all.  Leave #\? as a simple readmacro, and pick another name for
your Prolog macro.
-------