Sign in to follow this  
Roots

Lisp and Scheme, do you use them?

Recommended Posts

I know that the AI course at Purdue University uses Scheme, while the AI course at UT Austin uses Lisp. So out of curiousity I ask to you game developers, have any of you used either of these two languages in your AI routines? I remember hearing sometime ago that the only reason that Lisp and Scheme are broadly used by the academic AI community were strictly historical reasons (the fact that Lisp existed at the "right" time ) and not because either of these languages have an obvious benefit over others. What are your thoughts?

Share this post


Link to post
Share on other sites
I actually hear that people are starting to turn towards using Java or something similar like C# for AI.

Unfortunately, I really don't like the syntax of either Scheme or Lisp. I would rather use something else.

Share this post


Link to post
Share on other sites
While Lisp dialects (a Scheme dialect is also a Lisp dialect!) are definately a good thing, they are somewhat dificult to use effectively depending on what your trying to archive.

If you are writing *nix software then there are many well developed solutions available for you to embed in your application allowing you to write your ai code in Lisp. However, for other platforms all of the solutions I'm aware of are commercial and may be dificult to obtain if you do not own an American credit card!

NOTE: CLISP is available for windows and it is apparently compatable with VC, I was unable to understand their terminology and linking mechanism to accomplish this, however. If you do not use VC this might be easier to archieve.

As for AI ruitines, they can usually be written in any well engineered programming language, and since most gamecode will inevitably have to link to C code (perhaps even C++ code!) Lisp will be out of the realm for many budding hobbiest game developers for some time yet. A dialect of Scheme was used as a complete scripting solution for a commercial game, however! This may or may not have included their AI ruitines.

As for Lisp having advantages, this is most certainly true and has to do with the design philosophy of the language, and its ability to adapt to almost any programatic problem that is not hardware bound (newer implementations of Common Lisp avoid this by providing extensions for mnemonic operations, allowing assembler capabilites without even leaving the language itself!).

As I stated before however, AI is about the algorithms and not the languages, therefore you should pick the language that best suites the task. If your engine is in C++, since it is very hard to extend C++ with other languages it may be easiest to use C++ to write your ai code, if you were working in C however it may be more pertinent to use an embeded Scheme dialect since it will make the algorithms easier to write and test quickly and is very easy to embed on *nix platforms and some Win32 platforms (depends on the dialect you choose).

Share this post


Link to post
Share on other sites
I use scheme for my Othello program. This is because scheme lets me explore the problem more easily than most other languages. I can experiment with different ways to call my search routines for instance, without having to change anything in the actual code or go through an annoying compile cycle.

When the execution fails somehow the state is preserved so I can examine and change all data to help me find out where the bug is. For instance once when the search did not terminate I could just look at the stack which I saved moves on, to see that what the search was doing was just making and un-making pass moves. Very helpful. With C++ I would have had no way to tell why it was stuck.

Furthermore scheme lets me write more compact code in many cases. For instance, in other languages negamax is often used instead of minimax because it makes the code shorter, but in scheme the minimax version is just as short (I think mine is 9 or 10 lines), since you can use higher order functions to express the two cases (maximizing and minimizing).

Some reasons I like scheme:
+ it facilitates incremental bottom-up development
+ can be compiled to machine code or (java or scheme) byte code
+ it usually takes less code to achieve your goals
+ no crashes.
+ there are many independent open source implementations for different needs
+ the language is quite well-defined (formal semantics)
+ 100% portability

Some negative things about scheme:
- the standard library is too small
- no standard way to create new data types

edit: clarified a few points

[Edited by - Scientifish on September 22, 2004 6:43:40 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Roots
I remember hearing sometime ago that the only reason that Lisp and Scheme are broadly used by the academic AI community were strictly historical reasons (the fact that Lisp existed at the "right" time ) and not because either of these languages have an obvious benefit over others. What are your thoughts?

I remember hearing that about the popularity of C, C++, Java, C# and VB.

I've used MzScheme to embed scheme into a C++ game. I've used Corman Lisp with SDL/OGL to make some relatively simple applications.

Pick up a non-AI book on Lisp/Scheme and you'll probably "get" why people love (and hate) it.

Share this post


Link to post
Share on other sites
By the way, everything I love about Lua I learned first in Lisp or Scheme. Closures, dynamic typing, hash tables, coroutines, generators, the REPL loop. One thing Lua doesn't have is the wonderful syntax of Lisp and the benefits that it yields (code is data, functions that can easily parse and modify code)

Share this post


Link to post
Share on other sites
Well, there's a big difference between the university definition of AI, and what game developers mean when they discuss AI. For the former, I believe Scheme (or Lisp) is very useful, but it might be a bit messy for use in game development. (The problems you want to solve are simpler, and you want more performance, and finally, getting different languages to talk to each others is always tricky)

Share this post


Link to post
Share on other sites
Quote:
Original post by Spoonster
Well, there's a big difference between the university definition of AI, and what game developers mean when they discuss AI. For the former, I believe Scheme (or Lisp) is very useful, but it might be a bit messy for use in game development. (The problems you want to solve are simpler, and you want more performance, and finally, getting different languages to talk to each others is always tricky)

I'm aware of that.

I just find that some classmates of mine take professors' words as gospel, who, in turn, took their professors' words as gospel.

Not using a language because it's not popular or because a professor looks down upon it without informing yourself from other sources seems a folly to me.

This is offtrack.

Share this post


Link to post
Share on other sites
Quote:
Original post by Woodsman
Quote:
Original post by digitec devil
my professor said that current real A.I. projects are done in C++

Did he happen to mention why?


No he didn't, I didn't think(or perhaps care) to ask. But generally speaking he's in a group of professors I tend to trust when they talk about the real world.

Share this post


Link to post
Share on other sites
Quote:
Original post by Krysole
If you are writing *nix software then there are many well developed solutions available for you to embed in your application allowing you to write your ai code in Lisp. However, for other platforms all of the solutions I'm aware of are commercial and may be dificult to obtain if you do not own an American credit card!

I am not sure about common lisp, but for scheme there exist many open source implementations that compile fine on windows. For embedding in an application the big fat monster that is common lisp is probably a little too much anyway, a more minimal language like scheme is more suitable.

And I think whether using lisp is a good idea depends a lot on the problem you are trying to solve. 'AI' is such a broad field that you can not make blanket statements about it. If you want super-fast pathfinding you'd best use a low level language, but if you have a complex problem with lots of rules where performance is not the problem, the elegance and expressive power of lisp-like languages is going to make your life a lot easier.

Share this post


Link to post
Share on other sites
It's been a while since I've posted at these forums, but in that time, I have learned Lisp. I love it, and would not go back to any other language. In fact, all of the other languages look really weird now. Lisp has a GC, and so it makes stuff really easy. For instance in C++:

int x;
int y;
class do_something_with_something {
private:
int q;
int z;
bool function();
public:
q(); // q and z work on int x and int y
z();
}

in Lisp:

(defun foo (args &rest more_args)
(cond ((null args) nil)
(t (do_something_with_args))))

I don't have to declare the varible lambda list args here as I had to declare it in C++. These may not be that clear, but hopefully you get the general idea. I check back here later on, right now I have to run.
neo88

Share this post


Link to post
Share on other sites
It's been a while since I've posted at these forums, but in that time, I have learned Lisp. I love it, and would not go back to any other language. In fact, all of the other languages look really weird now. Lisp has a GC, and so it makes stuff really easy. For instance in C++:

int x;
int y;
class do_something_with_something {
private:
int q;
int z;
bool function();
public:
q(); // q and z work on int x and int y
z();
}

in Lisp:

(defun foo (args &rest more_args)
(cond ((null args) nil)
(t (do_something_with_args))))

I don't have to declare the varible lambda list args here as I had to declare it in C++. These may not be that clear, but hopefully you get the general idea. I check back here later on, right now I have to run.
neo88

Share this post


Link to post
Share on other sites
I don't use Lisp or Scheme, but I did use Corman Common Lisp for a while and I definitely did feel the whole "Lisp is king" thing. The only reason I didn't stick with it is that I started working and I have to use C++ at work, plus I wasn't and still am not programming much at all really. My biggest problem with Lisp is that it is just SO huge it will take a while to learn well enough that I don't have to constantly look stuff up, plus there are times when I feel regular c++ style pointers would make some things SO much easier. The whole 'its a pointer unless its a certain kind on number' thing makes some things really painful.

I really think that if there is every a revision to the Common Lisp specs, Lisp would have a real chance of coming back and being king for real. The problem is that people are happy making their own homebrew version of lisp instead of making a standard on the level of .Net or Java (the Lisp standard is just soo old...).

RE OP: Lisp/Scheme/other language is not an "AI Language", they are all general purpose languages and they can all be used for any purpose including AI.

Share this post


Link to post
Share on other sites
Quote:
Original post by Extrarius
I really think that if there is every a revision to the Common Lisp specs, Lisp would have a real chance of coming back and being king for real. The problem is that people are happy making their own homebrew version of lisp instead of making a standard on the level of .Net or Java (the Lisp standard is just soo old...).

Agreed. After reviewing a number of embeddable lisps and schemes, I eventually ended up writing the functionality I needed for a project. I'm keeping the libraries I've tested around for future consideration, but you're very right.

Also, I just realized that you sent me some links on (lisp related) GC several months ago and never thanked you, so Thanks!

Share this post


Link to post
Share on other sites
Quote:
Original post by Extrarius
I really think that if there is every a revision to the Common Lisp specs, Lisp would have a real chance of coming back and being king for real.


From what I've heard, the Lisp specs are just fine. There's a lot of stuff missing from them (threads, etc.), but it wouldn't be possible to add it to the specs because the important Lisp vendors already implement that stuff in various ways and they cannot afford to change their products (and in doing so, break the code of their customers). Common Lisp is king now because and to the extent that it is used and usable for serious projects. It already has a level of maturity where change is hard to do (as opposed to, say, Java).

The question is not whether Lisp will be the next most frequently used language on the gamedev forums. The question is not even if it could be used to create existing games. The real question is what kind of game would most profit from Lisp's strengths? Chances are it could be a pretty unique game, with everybody "serious" in the "real world" doing FPSs in C++ and all.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Diodor: Common Lisp compilers are in a pretty sorry state right now IMO. Not only do they implement 'fringe' functionality(threads, sockets, and everything else that is important today but not in the standard) differently, but even code written to 100% conform to the standard is not portable between compilers. It would take a lot to redo the standard, but IMO it will have to be redone for Lisp to ever catch on again.

Lisp is good for any game that doesn't want to be cookie cutter because the language allows for a level of flexability not available in C++/C#/Python/Java/etc (unless you recreate Lisp in your language of course). The Lisp compilers out there, while not very standards conforming (because the standards do things wrong, simply put), are very good at creating efficient code and are very optimized. I'm fairly certain that making Doom 3 in Lisp would be possible, since 99% of the processing is done in

Share this post


Link to post
Share on other sites
Scheme is the work of demons. While I stand by that phrase, I do feel that it does have a wonderful place in interactive code. There are a bunch of problems that I've had to muddle through in C++ and then realize that writing it in scheme makes it seem like the language was made just for that problem. On the other hand.. I wouldn't go coding a game engine in Scheme/Lisp.

Share this post


Link to post
Share on other sites
Quote:
Original post by falkone
Scheme is the work of demons. While I stand by that phrase, I do feel that it does have a wonderful place in interactive code. There are a bunch of problems that I've had to muddle through in C++ and then realize that writing it in scheme makes it seem like the language was made just for that problem. On the other hand.. I wouldn't go coding a game engine in Scheme/Lisp.
I don't know much about scheme, but I know enough that saying Scheme/Lisp is like saying Java/C or C#/C:
They're the same family of language just like Java and C# and C and they share a little of the syntax, but have a LOT of differences.

Share this post


Link to post
Share on other sites
I disagree. I think that any of the run-of-the-mill Lisp compilers work jsut fine. Sure, they implement some things differently, but that doesn't mean they don't conform to the standerds, because they do, only the standerd does not specify the things that are implemented differently. Take cons cells for example. Just my $0.02.
neo88

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this