LISP Macro vs WolframLang

By Xah Lee. Date: .

Reader Macro, vs WolframLang Short Syntax

now, all those LISP quote, backtick, dot, comma, comma at, are implemented by what's called “reader macros”.

a “Reader”, exists in all LISPs, in emacs lisp, common lisp, scheme lisp, clojure lisp. (also in WolframLang, called Read).

Reader is part of lisp compiler that is called as the first thing, to transform what user typed into a lisp list syntax (aka “real lisp syntax”).

Now in every language, what you typed, a valid source code, is called the lang's syntax. In lisp, the lisp fanatics, call lisp source code as “surface syntax”. After the lisp reader did the syntactical transformation, the lisp fanatics call that the real lisp syntax. This lisp idiocy generates lots of confusion.

you have hard-to-understand problem like this

(setq xxa (list 'a 'b))
(setq xxb (list 'a . ('b)))
(equal xxa xxb)
;; t
(equal (cons 'a 'b)
       '(a . b))
;; t

(equal (cons 'a 'b)
       (quote (a . b)))
;; t

(equal
 '(("a" . aa)
   ("b" . bb))
 (list
  (cons "a" 'aa)
  (cons "b" 'bb)))
;; t


(equal (cons 'a 'b)
        '('a . 'b))
;; nil

so but why is lisp no have some functional form for some of the “syntactic shortcuts” such as backtick or # or comma or comma at? well, simply put, bad design. Again, the lisp reader transform them, and if the end result has the form (f x y z etc) , then it's fine, lisp fanatics see no need to have a (f x y z etc) to stand for the short syntaxes.

this problem, gets deep. it is very hard-to-understand the effect of quote, etc or see exactly which are syntactical equivalences. The whole thing, is part of the complexity of evaluation.

by the way, the complexity of evaluation of WolframLang is not better. You have Hold, HoldForm, ReleaseHold, HoldAll, HoldAllComplete, Evaluate, Unevaluated, Activate, Inactivate, etc.

Evaluation

Lisp Macro

so far, we have not mentioned lisp macros. lisp macro is a lang feature that allow user to control evaluation, and effectively, create syntactical transformation ( but this syntactical transformation, is not powerful enough to get out of the nested parenthesis syntax).

builtin macros (such as if, while ), are called special forms in lisp.

[see also Fundamental Problems of Lisp]

Lisp Macros is Beginning of Term Rewriting System

in WolframLang, the whole language, entire evaluation strategy, can be considered as lisp macros. More properly called, term rewriting system.

In essence, how WolframLang works, is that source code is just a sequence of Symbols and operators. Evaluation is done by just continuously doing syntactical transformation, to end up with a different sequence of symbols, which we take as the result.

The syntactical transformation, follow by “transformation rules”, either builtin, or user defined. (this part is analogous to lisp macros). this syntactical transformation continues until no more rule applies. (that is, no pattern matches)