12 ms·
Basically no programming language is an infix-only-notation language. Most programming languages are using mixed notation: prefix, infix and possibly postfix. I
by lispm 2y ago
Basically no programming language is an infix-only-notation language. Most programming languages are using mixed notation: prefix, infix and possibly postfix. In most languages function calls are prefix. For a subset of functions there are infix operators: a + b, instead of +(a,b). For control flow many programming languages use a more elaborate syntax.
The usual mathematical notation is two-dimensional. Fractions are written a / b and
a
-
b
Also think of square roots and all kinds of other mathematical notation.
When I verbalize a * (b + c) as a natural language expression then it is:
Multiply a with the sum of b and c.
The operators are prefix.
In German:
Multipliziere a mit der Summe aus b und c.
in Lisp:
(* a (+ b c))
or
(* a
(+ b c))
or
(* a
(+ b
c))
or
(* a (+ b
c))
or
(*
a
(+
b
c))
The latter, more random layout, will not be used by Lisp programmers, because it does not follow the usual layout rules. But it is possible, since the layout of the lists is not significant in Lisp.
A pretty printer in Lisp is a function, which takes an expression and writes it in some layout. Thus Lisp can generated 2d-layouts of expressions. Most Lisp-supporting editors can indent or even layout Lisp expressions. This helps Lisp developers using a common layout of code, supported by the tools.