home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
aijournl
/
1987_03
/
logo.mar
< prev
Wrap
Text File
|
1987-02-19
|
8KB
|
194 lines
Learn LOGO Before LISP
by Mike McMillan
March 1987 issue of AI EXPERT
Sidebars 1, 2, and 3
Sidebar 1
The following is a list of the LISP primitives, predicates,
functions and their Logo equivalents. Those functions that do not
have a Logo equivalent have been noted. Please remember that
most, if not all, of the LISP functions that are not duplicated
in Logo can be written in Logo. Logo is powerful enough to create
functions that behave like their LISP equivalents.
The LISP function is listed first, followed by the Logo
equivalent or N/A, meaning Logo does not have that function.
CAR - FIRST GET - GETPROP
CDR - BUTFIRST PUTPROP - PUTPROP
CXXXR - FIRST BUTFIRST...BUTFIRST REMPROP - REMPROP
LAST - LAST PLIST - PLIST
CONS - FPUT (FIRST PUT) ATOM - WORDP
APPEND - LPUT (LAST PUT) NULL - EMPTYP
LIST - LIST NUMBERP - NUMBERP
NCONC - N/A (NCONC IN EXPERLOGO) SYMBOLP - N/A
RPLACA - N/A (RPLACA IN EXPERLOGO) LISTP - LISTP
RPLACD - N/A (RPLACD IN EXPERLOGO) EQUAL - EQUALP
NREVERSE - N/A MEMBER - MEMBERP
ASSOC - N/A (FINDKEY IN EXPERLOGO) GREATERP - GREATERP
LENGTH - COUNT LESSP - LESSP
REVERSE - N/A(REVERSE IN EXPERLOGO)ZEROP - N/A
SUBST - N/A (SUBST IN EXPERLOGO) MINUSP - N/A
LCONC - N/A PLUSP - N/A
TCONC - N/A EVENP - N/A
SETQ - MAKE ODDP - N/A
SETF - N/A COND - IF
SET - N/A IF - IF
DEFUN - TO
This is not an exhaustive list; several of the more compli-cated
or lesser-used LISP functions have been left out. The
reader should see from this list, though, just how much of LISP
has been implemented in Logo.
Sidebar 2
Writing LISP Functions in Logo
Many of the LISP primitives and predicates that are not
duplicated in Logo can be written in Logo. Logo's power as a
symbolic computation language allows the programmer to do this.
For example, in LISP there is a powerful primitive called
ASSOC. ASSOC looks for a key that is part of an association list.
For example, if we set up the following association:
(SETQ 'JANE '((OCCUPATION STUDENT)
(MAJOR COMPUTER-SCIENCE)
(LANGUAGE LISP)))
ASSOC can retrieve the information we have set up.
Writing in LISP: (ASSOC 'LANGUAGE SALLY), the computer will
respond: (LANGUAGE LISP).
ASSOC is not defined in Logo. It is, however, very easy to
create. We set up the association by writing: MAKE "SALLY
[[OCCUPATION STUDENT] [MAJOR COMPUTER.SCIENCE] [LANGUAGE LISP]].
We define the ASSOC primitive as follows:
TO ASSOC :KEY :OBJECT
IF EMPTYP :OBJECT [OUTPUT "? STOP]
IF EQUALP FIRST FIRST :OBJECT :KEY [OUTPUT FIRST
:OBJECT STOP]
OUTPUT ASSOC :KEY BF :OBJECT
END
Our Logo ASSOC goes through the association list recur-
sively, checking each key to see if it matches the argument
given. If there is nothing in the association list, or if it
cannot find a match, ASSOC will output a question mark. When a
match is found, the key and the object are output and the proce-
dure stops.
ASSOC is a fairly complicated example. Several of the LISP
primitives that do not have Logo equivalents can be defined in
one or two lines of Logo code. For example, to define the Logo
version of LISP's ZEROP, we write:
TO MY-ZEROP: NUMBER
IF EQUALP :NUMBER "0 [OUTPUT "TRUE]
IF EQUALP LAST :NUMBER "0 [OUTPUT "TRUE] [OUTPUT
"FALSE]
END
The extensibility of Logo is helpful in the study of LISP. the
student trying to model LISP expressions in Logo will often need
to write LISP primitives and predicates in Logo in order to use
them. I found in my own study that writing a LISP function in
Logo gave me a deeper understanding of that function. It takes a
higher magnitude of understanding to write a function than it
does just to use the function.
Sidebar 3
ExperLogo - A LISP-like Logo
One version of Logo stands out from the others as being the most
LISP-like in its form and structure - ExperLogo from Exper-
Telligence. ExperLogo's LISPness is apparent in several dif-
ferent areas - from its rules of evaluation to its toolchest of
primitives and predicates.
The first noticeable LISP-like feature of ExperLogo is the way
it evaluates its expressions. In ExperLogo every expression is
evaluated, meaning that primitives and predicates will print
the results of their evaluation on the screen without the need
for a PRINT command. This element of first-classness is an im-
portant feature of LISP that is not found in most versions of
Logo.
For example, in most Logos to print the value of a variable the
variable has to be combined with a PRINT command, such as
PRINT :PEOPLE. In ExperLogo only the variable has to be written,
as in :PEOPLE, which is much like the way it would be done in
LISP - (PEOPLE).
ExperLogo is also more LISP-like in the way values are bound to
variables. In most Logos a value is bound to a variable by
writing MAKE "NAME "TOM. In ExperLogo you can write: MAKE NAME
TOM. In LISP it would be (SETQ NAME TOM).
Expressions that evaluate to true or false in ExperLogo
return values in the same manner as LISP, either T or NIL, which
is unlike most Logos, which return TRUE or FALSE.
Another area of ExperLogo that makes it so comparable to LISP
is its expanded list of LISP-like primitives and predicates. In
most versions of Logo there is not a primitive similar to
LISP's REVERSE, which takes the elements of a list and reverse
their order. ExperLogo has REVERSE.
In LISP the primitive SUBST is used to substitute a new ex-
pression for an old expression in some target expression, say a
list. Most versions of Logo do not have this powerful primitive;
ExperLogo does.
A very powerful primitive in LISP is ASSOC (discussed in
another sidebar). Most Logos do not have this primitive, though
it can be written in Logo. ExperLogo has this primitive under
another name - FINDKEY. FINDKEY works just like ASSOC; it takes a
key word (atom) and an expression as arguments and then finds the
element that goes with the key.
Here is a list of functions in ExperLogo which are not found in
other Logos but can be found in LISP: ELEMS, FINDKEY, NCONC,
NPUT, PAIRLIST, REMOVE, REVERSE, RPLACA, RPLACD, SORT, SORTKEY
and SUBST. Some of these functions do not duplicate their LISP
equivalent's name, but in following the Logo tradition are more
mnemonic, hence easier to remember and understand.
ExperLogo at this time is available only for the Macintosh, but
if you have a Mac and are looking for a Logo with a high
degree of LISP similarity, I would highly recommend looking at
this excellent Logo implementation.