PDA

View Full Version : IDEA: LISP Interpreter



ygfperson
08-12-2002, 11:18 PM
i've written a tutorial on lisp for the uninformed.
http://www.flashdaddee.com/Tutorials/yfperson.html
it's a fairly simple scripting language. here's an example:

code:
(defun func1 (x)
(- x 4)
(+ x 3) )
(func1 (- (+ 3 5) (/ 3 7)))


3 + 5 = 8, 3 / 7 = 3/7
8 - 3/7 = 7 4/7
func1 is a user-defined function which adds 3 to whatever x is. the value returned is 10 4/7 (or whatever that is in decimal).
the last statement in a user-defined function is the value that is returned. func1 ignores (- x 4) because it doesn't really do anything.

lisp is named lisp because of its list variables and built in lisp manipulation functions. because implementing that would take too much time, list manipulation is not required.

here is what's required in the lisp interpreter (if voted for):


it needs to work with nested lisp expressions, where a single expression is bounded by two parentheses. each expression returns some value
you need to create some predefined functions like +, -, *, /, etc...
you know, the simple stuff.
each program needs to be able to define functions like i showed above (using the defun statement). hint: unlike C functions, which does type-checking and other complicated stuff, the defun command should be more like the C #define command.
so, in other words:


(defun func1 (x) (+ x 3))
(func1 7)
this should become:


(+ 7 3)

which is easy to evaluate.
each program should check the number of parentheses to help make sure there aren't any typos. this could be as simple as counting the number of '(', then counting the number of ')', and seeing if the numbers match

one last thing, not LISP-related:
if the search/replace program is voted for, you cannot use the string classes with it. that would just be too easy :D

ygfperson
08-12-2002, 11:25 PM
cshot seconds

Nick
08-16-2002, 10:45 PM
If your intrested in lisp like languages one cool book I've found is
http://mitpress.mit.edu/sicp/full-text/book/book.html
I havn't had enough time to read the whole thing (or halve)
though (:

Cshot
08-18-2002, 07:22 PM
cshot seconds
I won't be able to participate now as summer is now ending and I will be very busy :(

However I'd still like to see people tackle this.

ygfperson
09-13-2002, 08:48 PM
bump