Advertisement

Lisp and Scheme, do you use them?

Started by September 21, 2004 10:29 PM
27 comments, last by Woodsman 20 years, 2 months ago
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?

Hero of Allacrost - A free, open-source 2D RPG in development.
Latest release June, 2015 - GameDev annoucement

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.
Advertisement
My best, most complicated project so far was in Lisp, and I succeeded in bringing it as far as I did because of Lisp. Lisp is king.
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).
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]
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.
If a plant cannot live according to its nature, it dies; so a man.
Advertisement
I use Lisp and prolog because I have to for college, but my professor said that current real A.I. projects are done in C++, so I have no real intentions of sticking with either.
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)
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?
If a plant cannot live according to its nature, it dies; so a man.
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)

This topic is closed to new replies.

Advertisement