[comp.lang.scheme] How can you do things like ?X ->

pierce@golfer.Dayton.NCR.COM (03/24/88)

Sometimes it is very useful to hide some underlying implementation details
when writing systems such as inference engines. Since Scheme doesn't have
ability to handle read macros then is it possible to do 
something like the following in a differnet way ?

       where "x" is a variable and "?" is a read macro and the "?" read macro
       reads the next character, which is "x" and transforms "?X" into
       the following list structure   (*var* x) . This representation 
       is useful to the underlying code and the "?x" is useful to 
       a user to designate unifiable variables in a backward or forward chaining
       rule.
Any and all responses are appreciated.

thanks in advance,

Gene Pierce 
--

Pavel.pa@XEROX.COM (03/25/88)

You preprocess the input from the user, checking each symbol for a
first-character of "?" and transforming all such uses into the list you
mentioned.  Alternatively, you write a parser/scanner for your input language
that has nothing to do with the Scheme function READ.

I prefer the latter idea myself.  To my mind, READ's only legitimate purpose is
the reading of real Scheme programs and data.

	Pavel

gjc@BUCSF.BU.EDU (George J. Carrette) (03/25/88)

(1) if you are implementing your own read/eval/print loop for a random
    language you can write your own read, or use that CGOLREAD that
    someone on this list may have already ported to scheme.
(1.5) you may be able to get away with a read/mung/eval/print loop.
      Just mung the result of read before you pass it along.
      I teach just this technique to transform ?x into the result of
      (make-variable :name 'x) (common lisp, sigh...) in a problem
      set on pattern matching and pattern compilation.
(2) If you have evaluation macros, you can always have them mung
    the passed-in-structure without mercy, e.g. using the technique (1.5)

(assert (append ?x () ?x))
(assert (append ?x (?a . ?y) (?a . ?y))
        (append ?x ?y ?y))

(3) If you dont have evaluation macros, big deal, just quote the arguments,
    (assert '(append ?x () ?x))
    as long as can call EVAL or COMPILE yourself there is no loss of
    generality. 

(4) In drastic situations use strings,

(fortran "FUNCTION F(X,Y)
          F = X*Y+SIN(X)
          RETURN
          END")

Note that FORTRAN 77 uses 'FOO BAR' for strings, so this actually works
ok, without having to escape-quote internal double quotes.

-gjc