Lisp as a Scripting Language

Started by
10 comments, last by Extrarius 21 years, 1 month ago
I need a scripting language, and after looking at many languages used for that purpose, I''ve decided none of them fit my needs so I want to make my own. Since the Lisp revolution here on GameDev, I''ve found that I like Lisp. Unfortunately, I''m not a Lisp guru, so I don''t think I could write a game engine in it. Thus, I''d like to create a Lisp interpreter for my engine which will be written in C++. I''ve looked around on the net (using google and visiting many, many links from lisp.org), but I can''t find any information on how to write such an interpreter. Lisp is easy enough to create a tree from, but I''m not sure how to handle the untyped variables, and how to handle lists in lists, etc. I would prefer to support as much of the Common Lisp standard as possible. I''ve found the source code for a few interpreters, but generally they are very messy C that is difficult to understand. Does anybody know of any good papers, sites, books, etc or have any pointers or advice on writing a Lisp interpreter?
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Advertisement
Didn''t you buy "Essentials of Programming Languages"? If so, the samples are (relatively) easy to adapt to C++. Admittedly the language they develop isn''t Lisp, but it is semantically similar (some would argue a Lisp dialect). I know from experience that it''s similar enough to write a Scheme interpreter from it. Then again, I worked off of the first edition of the book. Your milage may vary with the second edition.
I guess I''ll start reading it then. I''d been too busy learning and playing with Lisp to spend time on ''more serious'' stuff until now =-) Lisp is a lot of fun, especially with so many awesome projects created in it, and a lot of them open source.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
I don''t understand.

Why don''t you just use a Lisp package, call your C++ code, and do a callback to your Lisp code? In other words, let Lisp carry the program, with C++ reserved for whatever thing it is that you want C++ to be reserved for.
_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
quote:Original post by bishop_pass
I don''t understand.

Why don''t you just use a Lisp package, call your C++ code, and do a callback to your Lisp code? In other words, let Lisp carry the program, with C++ reserved for whatever thing it is that you want C++ to be reserved for.


I''m much stronger with C++, and I don''t know how to do that kind of thing in Lisp. Also, I feel implementing a Lisp interpreter in C++ will improve my understanding of Lisp.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
quote:Original post by Extrarius
I''m much stronger with C++, and I don''t know how to do that kind of thing in Lisp. Also, I feel implementing a Lisp interpreter in C++ will improve my understanding of Lisp.

I think your time would be better spent researching what I suggested, and yield a better product. Lisp can compile itself into machine code. Will your implementation do that? Also, there''s a lot of other things in a good quality Lisp implementation in addition to compilation: p-lists, gc, symbol tables, bignums, complex numbers, ratios, etc.
_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
Another reason is that every Lisp compiler I''ve found is only free for personal use, and I already own a C++ compiler I can use for commercial use. A commercial License for the Lisp compilers I''ve looked at costs more than I can afford.

Also, if I use Lisp as the base language, I''ll have 3 parts instead of only 2 - C++, Lisp with full access to the engine, and Lisp without access to the engine. I need the latter because the point of the scripting engine is to allow anybody to easily make some modifications without exposing the entire engine to them. If I use C++ as the base, I eliminate the middle layer of Lisp. I might lose some speed because I''m interpreting Lisp, but maybe not as there are libraries that making creating machine code easy, which I could use to compile my Lisp code. I probably won''t go that route though, because part of the reason I want an interpreter is so that I have more control over when and how the code runs.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
I thought Corman Lisp was only $250. And you don''t need to pay for it until you''re ready to distribute.

As for the other arguments, I believe they aren''t valid arguments, but excuses to not research the techniques I discussed, instead favoring the idea of writing your own interpreter. While there is nothing wrong with doing that, I believe in the end the better product would be the result of what I am suggesting.
_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
$250 is a lot of money for a poor college student.

You''re right that they aren''t very strong arguments, but I really don''t have any good reasons for wanting to write an interpreter other than doing it. For now, that is my real goal. My next goal in line is to make an engine, and it will ''need'' a scripting langauge so it makes sense to use the one I''ve already spent time to finish. I really don''t want to spend the time it will take for me to get good with Lisp before starting my engine. By writing an interpreter first, and then using it only lightly as a scripting language I''ll be able to get more comftorable with it and then I might use it in my next project or two... Maybe the final engine will be entirely in Lisp, but for now my goal is to gently ease into it.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
My experience is that, as far as implementation goes, the simplest scripting languages are Forth-derivatives (stack-based, postfix notation). Granted its not quite Lisp, but it''ll help you get there.

[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement