Jump to content
  • Advertisement
Sign in to follow this  
aaron_ds

Lisp Interpreter

This topic is 4857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I just got my lisp interpreter assignment done, but I don't know what to test it with. I have cons, car, cdr, quote append, nullp, atomp, listp, integerp, mumber, reverse, +, -, *, \, and, or, not, setq, defun, cond implemented. If any of these are non-standard names, it is because thats what the assignment required. I works just fine with a simple factorial function:
(defun factorial (N) 
    (cond ((= N 1) 1)
          ('t (* N(factorial (- N 1))))))

What would really push the interpreter to its limit that takes advantage of these simple functions?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Tic-Tac-Toe is a good and easy way to stress your interpreter a little.

Share this post


Link to post
Share on other sites
Quote:
Original post by Roboguy
Why are you quoting t? It is normally self-evaluating.


Ahh, good point and a simple change. I'm really a newbie when it comes to lisp.

Tic-Tac-Toe, ekk! That does sound challenging, as well as a great place to start, thank you.

Ratings++ for all.

Share this post


Link to post
Share on other sites
Is it imperative? Have you implemented any functional features (lambdas, higher-order functions, etc)? If so, is it a Lisp-1 or Lisp-2 (a Lisp-2 has separate namespaces for functions and variables, and to use functions as data you have to prefix them with something (in Common Lisp, it's #'), a Lisp-1 has both in the same namespace).

Also. I could be wrong, but your post seems to imply that you think Lisp is a single language. It isn't (currently, the most commonly used Lisps are Scheme and Common Lisp (Scheme is a Lisp-1, Common LIsp is a Lisp-2). A lot of times, just "Lisp" refers to Common Lisp, though). Just wanted to point that out.

If you don't mind a fairly complicated project, a simple term-reducer might be a good test.

Share this post


Link to post
Share on other sites
Ahh yes Roboguy, I was having a discussion with a few classmates earlier today about Common Lisp and Scheme. Unfortunatly the assignment was rather vague and was little more than a list of functions that our interpreter was required to implement. In fact, no formal language definition was given to us. Example interpreter code was given to us from this book, but I found their K&R style C syntax to be ugly decided to write it from scratch using C++. I used the CLISP 2.35 implementation as a reference and went from there. What I have is really only a very small subset of *some* lisp-like language.

Share this post


Link to post
Share on other sites
Quote:
Original post by aaron_ds
Ahh yes Roboguy, I was having a discussion with a few classmates earlier today about Common Lisp and Scheme. Unfortunatly the assignment was rather vague and was little more than a list of functions that our interpreter was required to implement. In fact, no formal language definition was given to us. Example interpreter code was given to us from this book, but I found their K&R style C syntax to be ugly decided to write it from scratch using C++. I used the CLISP 2.35 implementation as a reference and went from there. What I have is really only a very small subset of *some* lisp-like language.


The Lisp it seems to resemble the most is Common Lisp. What about my other questions (particularly the functional one and the namespace one)?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by aaron_ds
from this book,


Heh, that's the book I cut my teeth on. I didn't think anyone would actually still use this book anymore ;-)

Share this post


Link to post
Share on other sites
Quote:
Original post by Roboguy
The Lisp it seems to resemble the most is Common Lisp. What about my other questions (particularly the functional one and the namespace one)?


I havn't implemented lambdas or higher-order functions. From what I found looking them up breifly, I can easily integrate them into my current setup.

I'm using (basically) two namespaces one for functions and one for variables. I further divided these into builtin functions, user defined functions, global variables and a stack for function argument values when using user-defined functions.

We were more or less told to go out and write a "Lisp Interpreter", some of the students didn't fare well. :-\

Share this post


Link to post
Share on other sites
Quote:
Original post by aaron_ds
Quote:
Original post by Roboguy
The Lisp it seems to resemble the most is Common Lisp. What about my other questions (particularly the functional one and the namespace one)?


I havn't implemented lambdas or higher-order functions. From what I found looking them up breifly, I can easily integrate them into my current setup.

I'm using (basically) two namespaces one for functions and one for variables. I further divided these into builtin functions, user defined functions, global variables and a stack for function argument values when using user-defined functions.

We were more or less told to go out and write a "Lisp Interpreter", some of the students didn't fare well. :-\


I would recommend you implement them, they are very handy (along with some functions like map and fold). Also, I'm not sure you understand completely what I mean by Lisp-1 and Lisp-2, it really only applies to languages that have higher-order functions. Basically, in Common Lisp (a Lisp-2) to call a variable which happens to be a function, you have to prefix it with a #' and use the funcall operator:

(funcall #'f arg1 arg2 ...)

While in Scheme (a Lisp-1) it would look like:

(f arg1 arg2)


I'm personally a Lisp-1 fan.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!