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

"Lisp" syntax differences



There's been a raging discussion on comp.lang.lisp about Lisp syntax. Dylan
was mentioned a number of times, not surprisingly.

It got me wondering: What, exactly, are the "hard" differences between Dylan
and Lisp syntax? By that I mean, for example, if you wanted to convert
between the two, what cannot be converted? Note that I'm just talking about
syntax differences. Assume that the appropriate definitions for such things
as "define method" ("define-method"?) were available in Lisp. Furthermore,
assume you cannot modify Lisp's reader and so forth.

I hope this doesn't sound like a naive question. I know that Dylan once had
a Lisp syntax (in fact I'm looking at the original Dylan book alongside the
DRM and CLTL as I write). However, I'm not well-versed in Lisp and it isn't
clear to me exactly how they differ. Once you do the obvious transformations
(e.g., "expression;" => "(expression)") what's left?

For example, here's a method from the original Dylan manual, page 81 [with
slight modifications for comparison]:

  (define-method newtons-sqrt (x)
     (bind-methods ((sqrt1 (guess)
                       (if (close-enough? guess)
                           guess
                           (sqrt1 (improve guess))))
                    (close-enough? (guess)
                       (< (abs (- (* guess guess) x)) .0001))
                    (improve (guess)
                       (/ (+ guess (/ x guess)) 2)))
            (sqrt1 1)))

Here's the same example from the DRM, page 82 (huh, interesting) [again with
slight modifications]:

  define method newtons-sqrt (x)
    local method sqrt1 (guess)
            if (close-enough?(guess))
              guess
            else
              sqrt1(improve(guess))
            end if
          end sqrt1,
          method close-enough? (guess)
            abs(guess * guess - x) < .0001
          end close-enough?,
          method improve (guess)
            (guess + (x / guess)) / 2
          end improve;
    sqrt1(1)
  end method newtons-sqrt;

I don't know how close the "Lisp syntax" version is to really being Lisp
syntax, but clearly it is very close to the Dylan "infix" syntax. It looks
like a complete and deterministic transformation to me.

By the way, if there's a complete and deterministic transformation between
Dylan and Lisp syntaxes, both could be supported. It occurs to me that a
Dylan parser could easily handle both and use Lisp syntax if it sees a "("
at top-level.

I'm sure all this was discussed when the syntax change was made to Dylan, of
course. I'm not proposing that this idea is novel.

What I'm thinking about, however, is not necessarily supporting both
syntaxes in a compiler, but abstracting the syntax out so that code could be
presented and edited in either syntax, but perhaps fed to the compiler using
just one of them, or something else entirely.

-- 
Chris Page
Mac OS Guy
Palm, Inc.

let mail-to = concatenate( "Chris Page <page", "@", "best.com>");





Follow-Ups: