X

#### Xah Lee

Functional Notations

Xah Lee, 2006-03-15

Let me summarize: The LISP notation, is a functional notation, and is

not a so-called pre-fix notation or algebraic notation.

Algebraic notations have the concept of operators, meaning, symbols

placed around arguments. In algebraic in-fix notation, different

symbols have different stickiness levels defined for them. e.g.

â€œ3+2*5>7â€ means â€œ(3+(2*5))>7â€. The stickiness of operator

symbols are normally called â€œOperator Precedenceâ€. It is done by

giving a order specification for the symbols, or equivalently, give

each symbol a integer index, so that for example if we have

â€œaâŠ—bâŠ™câ€, we can unambiguously understand itto mean one of

â€œ(aâŠ—b)âŠ™câ€ or â€œaâŠ—(bâŠ™c)â€.

In a algebraic post-fix notation known as Polish Notation, there needs

not to have the concept of Operator Precedence. For example, the in-fix

notation â€œ(3+(2*5))>7â€ is written as â€œ3 2 5 * + 7 >â€, where the

operation simply evaluates from left to right. Similarly, for a pre-fix

notation syntax, the evaluation goes from right to left, as in â€œ> 7+

* 5 2 3â€.

While functional notations, do not employ the concept of Operators,

because there is no operators. Everything is a syntactically a

â€œfunctionâ€, written as f(a,b,c...). For example, the same

expression above is written as â€œ>( +(3, *(2,5)), 7)â€ or

â€œgreaterThan( plus(3, times(2,5)), 7)â€.

For lisps in particular, their fully functional notation is

historically termed sexp (short for S-Expression, where S stands for

Symbolic). It is sometimes known as Fully Parenthesized Notation. For

example, in lisp it would be (f a b c ...). In the above example it is:

â€œ(> (+ 3 (* 2 5)) 7)â€.

The common concepts of â€œpre-fix, post-fix, in-fixâ€ are notions in

algebraic notations only. Because in Full Functional Notation, there is

no concept of where one places the â€œoperatorâ€ or function. There is

always just a single position given with explicitly enclosed arguments.

Another way to see that lisp notation are not â€œpreâ€ anything, is by

realizing that the â€œheadâ€ f in (f a b c) can be defined to be

placed anywhere. e.g. (a b c f) or even (a f b c), and it's still not

pre- or in- or post- anything. For example, in the language

Mathematica, f(a b c) would be written as f[a,b,c] where the argument

enclosure symbols is the square bracket instead of parenthesis, and

argument separator is comma instead of space, and the function symbol

(or head) is placed in outside and in front of the argument enclosure

symbols.

The reason for the misconception that lisp notations are â€œpre-fixâ€

is because the head appears before the enclosed arguments. Such

â€œpre-fixâ€ has no signifance in Full Functional Notation systems and

can only engender confusion in the Algebraic Pre-fix Notation systems

where the term has significance.

2000-02-21

The common name for the lisp way is Fully Parenthesized Notation. This

syntax is the most straightforward to represent a tree, but it's not

the only choice. For example, one could have Fully Parenthesized

Notation by simply moving the semantics of the first element to the

last. You write (arg1 arg2 ... f) instead of the usual (f arg1 arg2).

Like wise, you can essentially move f anywhere and still make sense. In

Mathematica, they put the f in front of the paren, and use square

brackets instead. e.g. f[a,b,c], Sin[3], Map[f,list] ... etc. The f in

front of parent makes better conventional sense until f is itself a

list which then we'll see things like f[a,b][c, g[3,h]] etc. It's worse

when there are arbitrary nesting of heads.

A pre-fix notation in Mathematica is represented as â€œf@argâ€.

Essentially, a pre-fix notation in this context limits it to uses for

function that has only one argument. More example: â€œf@a@b@câ€ is

equivalent to â€œf[a[b[c]]]â€ or in lispy â€œ(f (a (b c)))â€. A

post-fix notation is similar. In Mathematica it is, e.g.

â€œc//b//a//fâ€. For example â€œList[1,2,3]//Sinâ€ is syntactically

equivalent to â€œSin[List[1,2,3]]â€ or â€œSin@List[1,2,3]â€. (and

they are semantically equivalent to â€œMap[Sin, List[1,2,3]]â€in

Mathematica) For in-fix notation, the function symbol is placed between

its arguments. In Mathematica, the generic form for in-fix notation is

by sandwiching the tilde symbol around the function name. e.g.

â€œJoin[List[1,2],List[3,4]]â€ can be written as â€œList[1,2] ~Join~

List[3,4]â€.

In general, when we say C is a in-fix notation language, we don't mean

it's strictly in-fix but the situation is one-size-fits-all for

convenience. Things like â€œi++â€, â€œ++iâ€, â€œfor(;â€, 0x123,

â€œsprint(...%s...,...)â€, ... are syntax whimsies. (that is, a ad hoc

syntax soup)

In Mathematica for example, there is quite a lot syntax sugars beside

the above mentioned systimatic constructs. For instance, Plus[a,b,c]

can be written in the following ways: â€œ(a+b)+câ€ or â€œa+b+câ€ or

â€œ(a+b)~Plus~câ€

The gist being that certain functions such as Plus is assigned a

special symbol '+' with a particular syntax form to emulate the

irregular and inefficient but nevertheless well-understood conventional

notation. For another example: Times[a,b] can be also written as

â€œa*bâ€ or just â€œa bâ€. Mathematica also have C language's

convention of â€œi++â€, â€œ++iâ€, â€œi+=1â€ for examples.

As a side note, the Perl mongers are proud of their slogan of There Are

More Than One Way To Do It in their gazillion ad hoc syntax sugars but

unaware that in functional languages (such as Mathematica, Haskell,

Lisp) that there are consistent and generalized constructs that can

generate far far more syntax variations than the ad hoc prefixed Perl

both in theory AND in practice. (in lisps, their power syntax variation

comes in the guise of macros.) And, more importantly, Perlers clamor

about Perl's â€œexpressivenessâ€ more or less on the useless syntax

level but don't realize that semantic expression is what's really

important.

----

This post is archived at:

http://xahlee.org/UnixResource_dir/writ/notations.html

Xah

(e-mail address removed)

âˆ‘ http://xahlee.org/