18.10.2013 Views

A Forth Implementation of LISP

A Forth Implementation of LISP

A Forth Implementation of LISP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Proceedings <strong>of</strong> the 1987 Rochester <strong>Forth</strong> Conference<br />

A Fort Implementtion <strong>of</strong><br />

Tom Hand<br />

Department 01 computer Science<br />

Florida Institute 01 Technology<br />

Melbourne. Florida<br />

liSP<br />

Thlipaper ducrlbei a <strong>Forth</strong> <strong>Implementation</strong> <strong>of</strong> the language <strong>LISP</strong>.<br />

After dlicuiilng varloui aipecti <strong>of</strong> thli <strong>Implementation</strong>, a table <strong>of</strong><br />

the Implemented functloni II preiented.<br />

INTRODUCTION<br />

The <strong>LISP</strong> language wai Invented by John McCarthy <strong>of</strong> MIT In 1967. <strong>LISP</strong> II<br />

the moit popular language <strong>of</strong> Artificial<br />

Intellgence In the United Stat... It II the<br />

ucond oldut high -level language In current uie.<br />

Thli <strong>Implementation</strong> I1 baud on Franz <strong>LISP</strong> and wai totally written In TT<strong>Forth</strong><br />

on a Motoria 88000 mlcroproceiior. TT<strong>Forth</strong> I1 a token-threaded <strong>Forth</strong> that wai<br />

writen by H. S. Lee at Florida Initltute <strong>of</strong> Technology.<br />

IMPLEMENTATION<br />

Ai In <strong>Forth</strong>, both data and programi are treatid In thi iami way by <strong>LISP</strong>.<br />

The bailc data itructuri In USP II a liit. <strong>LISP</strong> contalni an evaluation proceii<br />

that tranilat.. oni i-expreiilon (ihort for iymbollc expre..lon) Into another<br />

i-expre..lon.<br />

1- ixpreulon<br />

<strong>LISP</strong><br />

Evaluator<br />

1- expreulon -<br />

141


142 The Journal <strong>of</strong> <strong>Forth</strong> Application and Research Volume 5 Number 1<br />

For simplicity; this implementation requires that tokens in the <strong>LISP</strong> SDurce<br />

code be encloud within blank..<br />

The primitive data objecti <strong>of</strong> <strong>LISP</strong> are called atomi; they are either number.<br />

or symbols. The basic data itructures are linked lists and propert lists. Atoms<br />

and li.t. are handled differently. Atom. have structure that i. quite .imilar to<br />

<strong>Forth</strong>; they are words but they are not directly accessible by the inner interpreter.<br />

The structure <strong>of</strong> an atom i. ilustrated by the following figure:<br />

link field<br />

name field<br />

code field<br />

type field<br />

value field<br />

propert field<br />

function definition field<br />

Type chicking is performed at run-time because <strong>LISP</strong> requires dynamic<br />

type checking. Any number <strong>of</strong> properties can be auigned to a symbol with<br />

these propertiu having arbitrary typu.<br />

Lists are repruented .. binary trees. For example, the list<br />

((a b) c (d))<br />

is represented as the following binary tree:<br />

f "r<br />

r<br />

c<br />

a b d


Proceedings <strong>of</strong> the 1987 Rochester <strong>Forth</strong> Conference<br />

It is always the case that the left node points to the current element <strong>of</strong> the list<br />

while the second node points to the remainder <strong>of</strong> the list.<br />

Standard <strong>LISP</strong> functions have been implemented 81 <strong>Forth</strong> word.. On the<br />

other hand, user defined functions are represented as binary trees In a manner<br />

similar to that done by most <strong>LISP</strong>s. Forward references are handled by maintaining<br />

a list <strong>of</strong> undefined symbols along with the addrelSes that correspond<br />

to each such symbol.<br />

A. mentioned earlier, the ba.ic operation in <strong>LISP</strong> is called evaluation. For<br />

a list to be evaluated, its flnt argument muit be a function. If such a function<br />

is detected, the remaining argument. <strong>of</strong> the Ii.t are each evaluated and finally<br />

the function itself Is evaluated.<br />

Because data structures are dynamically created and deleted, tree nodes<br />

require continual allocation and deallocatlon. Efficient memory allocation<br />

requires that garbage collection be performed to reclaim any unused nodes.<br />

A first fit algorithm decide. which memory is allocated from the free pool.<br />

Garbage collection Is performed as data structures change dynammically.<br />

INSTALLED <strong>LISP</strong> FUNCTIONS<br />

A reasonable subset <strong>of</strong> <strong>LISP</strong> functions from Franz <strong>LISP</strong> have been<br />

implemented in the current prototype. They are listed below:<br />

List Function.:<br />

car<br />

nthelem<br />

append<br />

rplaca<br />

length<br />

Comparator Functioni:<br />

and<br />

atom<br />

iymbolp<br />

equal<br />

greaterp<br />

mlnusp<br />

oddp<br />

)0 =:<br />

Data Structure Functions:<br />

setq<br />

get<br />

cdr<br />

nthcdr<br />

list<br />

rplacd<br />

reverse<br />

or<br />

null<br />

ii stp<br />

neg<br />

leup<br />

plusp<br />

=<br />

putprop<br />

plist<br />

lut<br />

con.<br />

nconc<br />

.aaoc<br />

not<br />

numberp<br />

eq<br />

nequal<br />

zerop<br />

evenp<br />

c: =<br />

defprop<br />

Evaluation Control Functions:<br />

quote eval funcal<br />

143


144 The Journal <strong>of</strong> <strong>Forth</strong> Application and Research Volume 5 Number 1<br />

+/<br />

Arithmetic Function.:<br />

mod 1+ ab.<br />

Input/Output Functions:<br />

print read<br />

msg<br />

defun def<br />

putd<br />

cond<br />

prog go<br />

n<br />

Function Definition Functions:<br />

Flow <strong>of</strong> Control Functions:<br />

CONCLUSIONS<br />

*<br />

1-<br />

load<br />

getd<br />

while<br />

return<br />

Thi. version <strong>of</strong> <strong>LISP</strong> wat tucceufully implemented a. an initial<br />

prototype. Currently, two other enhanced versions are under development<br />

that take advantage <strong>of</strong> <strong>Forth</strong>'. exten.lbilty.<br />

REFERENCES<br />

1. Brodie, L., Starting <strong>Forth</strong>, Prentlce-Hall, 1981.<br />

2. Lee, H., TTFORTH: A Token Threaded <strong>Forth</strong>, Florida In.titute <strong>of</strong><br />

Technology, 1985.<br />

3. McCarthy, J., <strong>LISP</strong> 1.5 Programmer's Manual, MIT Pre.., 1965.<br />

4. Wilenaky, R., <strong>LISP</strong>craft, W. W. Norton & Company, 1985.<br />

5. Winston & Horn, <strong>LISP</strong>, Addlson Wealey, 1984.<br />

6. Vino Q., FLlSP: A <strong>LISP</strong> Embedded in the <strong>Forth</strong> Environment, Florida<br />

In.tiute <strong>of</strong> Technology, 1986.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!