Unlicensed-7-PDF249-250_lips leangue programming

advertisement
An
for
Auxiliary
Language
More
Natural
Expression
- the
A-Language
William Henneman
Information International,
Inc.
Although LISP is one of the most powerful tools available
t o the research worker i n many fields of programming, the format
of
the input
language
(s-expression)
so
is LISP
awkwardstem
to use
awkward
that many
errors
i n programming for
--
dir
from ectlg
the fact that S-expressions
are the only allowable form of
input.
The inherent diyficulty of producing correctly working
S-expressions is tacitly recognized by anyone who uses M-expressions i n place of them, when not communicating direct13 w i t h the
computer.
The most striking example of this difficulty is the extreme
number of parentheses used i n writing S-expressions.
Thus, the
function of nfirstatomn is defined in M-expression notation as
firstatom 1x1 =
[nul1
[XI
+NIL;
[xIl+car
T+firstatom
[car
atom [car
The corresponding S-expression
[XI ;
[x]]].
is
DEFINE ( ((FIPSTATOM (LAMBDA (x) (COND
( (ATOM(CARx))
(CAR x))
(T (F~TAToM(CAR XI
I1 111)
This simple function has 26 parentheses,
and a long compli-
cated program nould have many more.
This proliferation of
parentheses makes it very difficult t o write such co2plicated
programs without an error i n placement or pairing of parentheses.
Indeed, i n some quarters, "LISPn is considered t o be an acronym
for "Lots of Irritating Single Parentheses".
The worst feature of this plethora of parentheses is the fact
that a localized error in parenthesization can cause global errors i n the LISP system,
For example, an unpaired right parenthesis on any l h e
can couse reading of the input to terminate
a t that line, An unpaired l e f t parenthesis can cause most of
the prograin to be unexecuted.
Another inconvenience associated mith S-expression is the
fact that Polish notation is mandatory.
Now it is harder t o read
Polish notation tIian infix notation, if only because ne were al1
taught infix notation i n school.
In logic and i n other programming systems, it is worthwhile t o pay the price of readability
f o r prefix notation since one is rewarded by having the need for
parentheses eliminated; i n LISP, we are actually punished
contrast between the E;I-expression a V b
A c
and the corresponding S-expression
(OR A (AND B c)) illustrates this point,
-- the
The names of the most basic functions have no mnenonic value
t o the programmer a t the level a t
hi ch he wishes t o think when
he is programming.
This feature is worst for beginners,
of
course, but a l 1 LISP programmers must at one time be beginners,
and why make l i f e harder for them than it need be?
A 1 1 this points toward the need for a more n a t u r d input
language; this language is called the A-Language, and is described i n succeeding paragraphs,
The A-Language is a language which allows expressions to be
written as a mixture of M-expressions,
A-expressions,
and Sexpressions.
The reader is presumed to be familiar with S-expressions and Id-expressions.
A-expressions
A s an example,
are basically similar t o Algol
the expression
statements.
(DEFINE FIRSTGTOM (IN) (6) (FISTATOM I N X)
(IF X IS EILPTY THEN NIL ELSE IF FIRST OF X IS
ATOblIC THEN FIST OF X ELSE FIRSTATûM E?FIMT OF x))
is the A-expression equivalent of the function defined above.
This example is explained i n detail below,
The f i r s t
element of
this A-expression
is
the aord DEFIIE,
Download