WolframLang vs Lisp Syntax

By Xah Lee. Date: . Last updated: .

WolframLang syntax and lisp syntax are isomorphic. WolframLang syntax has this form in general: e0[e1, e2, e3] while lisp is (e0 e1 e2 e3)

Symbolic Expression

Here is a example of WolframLang syntax in FullForm.


Note the complete nested regularity F[…]. And the only character used are English alphabets, the square brackts, and comma. The whole language is just these character, corresponding to lisp's parenthesis and space.

Here is the same thing in lisp form. (called symbolic-expression (aka s-exp))

 (vectorAngle (list (Pattern a1 (Blank)) (Pattern a2 (Blank))))
 (let (list x y)
    (setq (list x y)
          (N (* (list a1 a2)
                (exp (sqrt (+ (exp a1 2) (exp a2 2))) -1))))
    (if (eq x 0)
        (if (equal (signum y) 1) (* Pi (exp 2 -1))
          (* (* -1 Pi) (exp 2 -1)))
      (if (eq y 0) (if (equal (signum x) 1) 0 Pi)
        (if (equal (signum y) 1) (acos x)
          (+ (* 2 Pi) (* -1 (acos x)))))))))

Meta Expression

Following is the same thing in WolframLang InputForm. (which is a syntax layer on top of the regular nested form. Such is known as meta-expression (aka m-exp) in lisp world, conceived by lisp inventor John McCarthy, but never caught on in lisp comunity.)

vectorAngle[{a1_, a2_}] := Module[{x, y},
    {x, y} = {a1, a2}/Sqrt[a1^2 + a2^2] // N;
    If[x == 0, If[Sign@y === 1, Pi/2, -Pi/2],
      If[y == 0, If[Sign@x === 1, 0, Pi],
        If[Sign@y === 1, ArcCos@x, 2 Pi - ArcCos@x]]]]

Note the vectorAngle[{a1_, a2_}] := …? That's your lisp macros, but in a advanced form, called pattern matching. The “a1_” and “a2_” are patterns, and the right-hand-side is the transformation spec. [see Intro to Wolfram Language Pattern Matching for Lisp Programers]

StandardForm (rendered display)

Following is the same thing rendered in WolframLang StandardForm.

Mathematica StandardForm 2021-06-06 N82XV
Expression rendered in WolframLang StandardForm.
Wolfram Language syntax 2021-06-05
Wolfram Language code, in InputForm, StandardForm, FullForm.
Wolfram Language StandardForm 2021-09-29
Expression rendered in WolframLang StandardForm.

See also: