Skip to main content
GameDev.net gamedev.net
🔒 Locked

LISP as a scripting language for games

Started by Subotron Feb 27, 2006 at 6:26 PM 52 replies 13.4k views
Original Post
Subotron
Subotron
As a part of my study I now follow a course on LISP. I think I really like the language ('think' because I loved it at first, but now have a hard time getting anything done fast because I'm not really used to the syntax yet), and from what I remember to have heard (and my memories are not always accurate :p) it's does a pretty good job as a scripting language for games. Yet, on this forum I see mostly LUA, no LISP at all. I know it's used for AI quite a lot (AI is my study), but I'm not sure if it suits as a general scripting language. So what I'd like from you is to tell me why or why not to choose for LISP. I prefer it because I know it a bit now, and it's a good way to exercise for my exams :), yet I don't want to spend time on a project that's not going to be of any use. Second question, if the outcome of the 1st is positive, how hard (on a scale of one to ten, also compared to other scripting languages) would it be to write my own interpreter? I have quite a lot of C++/OpenGL/and the rest experience, and I am quite a quick learner, yet the 'machine part' of C++ (allocating memory, binary reading 'n stuff) is something I'm not that good at (maybe it's good for me to learn it this way actually?). I prefer writing my own interpreter, because the game engine I'm writing is just a way for me to learn. Yet, I also want to create something within a year (I've been working for 3 years now, had my ups and downs and a lot of complete overhauls :)) so it shouldn't be extremely hard. If the answer to this question is negative I'd like to hear if there are any interpreters which I can use that you recommend. I hope I made clear what I want. Thanks a lot for your input!
SiCrane
SiCrane
Personally, one of the points on my wish list for a good scripting language is that it be easy for someone who doesn't have a four year degree in computer science to use. Lisp more or less fails on that goal. Lisp is fairly powerful, but it takes a fairly different mindset to use than more procedural languages.

Writing a Lisp interpreter, for a reduced subset of Lisp anyways, is relatively easy. However, if you aren't that familiar with C++ memory management you might have a hard time dealing with the garbage collection necessary for a proper Lisp implementation.
Promit
Promit
Insomniac (or was it Naughty Dog?) used a custom LISP-like for several years as their scripting language of choice. They threw it out eventually; I don't claim to know the reason behind it, but they mentioned in at least one post-mortem that they only had one guy who knew how to code in the language (the same guy who designed it). So there's nothing inherently wrong with LISP technically that keeps it from being used. I don't know, however, what the status of LISP<->C++ type bindings is.

[Edited by - Promit on February 27, 2006 6:33:58 PM]
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Fruny
Fruny
I'm with SiCrane. Isn't the point of scripting to a game to enable non-programmers to add content to the game?
"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
Roboguy
Roboguy
Quote:
Original post by SiCrane
Personally, one of the points on my wish list for a good scripting language is that it be easy for someone who doesn't have a four year degree in computer science to use. Lisp more or less fails on that goal. Lisp is fairly powerful, but it takes a fairly different mindset to use than more procedural languages.


I would say this problem is not inherit of Lisp. Are just refering to Common Lisp?
Subotron
Subotron
Quote:
Original post by Fruny
I'm with SiCrane. Isn't the point of scripting to a game to enable non-programmers to add content to the game?


true (and make it easier in general. I want to get to the point where 'everything' can be done using an in-game console)

Yet, I thought LISP's syntax was pretty easy... and the way it's built made me feel it's really easy to implement (like the + primitive is threated like any other (c++) function: operands after the operator). This threating-everything-the-same approach seems really convenient to me. Plus, books like The Little LISPer teach you LISP in hardly any time (at least enough to use it in a console I reckon) so I'm not really sure why you guys say it's so hard?
intransigent-seal
intransigent-seal
First of all, something that needs to be made clear is that Lua is a specific implementation (well, technically it would be possible to make a separate implementation of the Lua language, but there's only one defacto implementation that everyone uses), whereas Lisp encompasses a whole set of dialects (Common Lisp and Scheme being the big two), and each dialect may itself have several implementations, so comparing the two is somewhat of a simplification.

Having said that, here are some unordered points to consider:
  • Some games have used a lisp dialect as a scripting language (Crash Bandicoot and Jak and Dexter come to mind; other threads on GDnet probably have more)

  • Lisp is not a particularly easy language to pick up and get the most out of in a short timespan - to use lisp well (something I certainly couldn't claim to do), you need a fair amount of experience with it, so that doesn't help it in the choice for a scripting language.

  • Implementing a dialect of lisp is not too difficult - if you were more interested in the language aspects than the final product/game side of things, then I'd certainly suggest you try writing your own implementation. Making an implementation that is robust, well designed and fast is far, far harder, so if you're more interested in getting on with your game, I would strongly suggest you go with an existing implementation (you might take a look at guile, for example)

  • The link between Lisp and AI is more an accident of history than because lisp is particularly well designed for AI work. Lisp is useful for far more than AI, and AI can be done in many more languages than just Lisp. Besides which, AI has moved on since Lisp was invented - AI is no longer based on symbolic processing, for the most part, which is really the thing that makes lisp good at it.

  • High level languages are getting closer to lisp all the time. Proper lexical closures, for example, are present in many high level languages (including Lua)


John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Roboguy
Roboguy
Quote:
Original post by Subotron
Quote:
Original post by Fruny
I'm with SiCrane. Isn't the point of scripting to a game to enable non-programmers to add content to the game?


true (and make it easier in general. I want to get to the point where 'everything' can be done using an in-game console)

Yet, I thought LISP's syntax was pretty easy... and the way it's built made me feel it's really easy to implement (like the + primitive is threated like any other (c++) function: operands after the operator). This threating-everything-the-same approach seems really convenient to me. Plus, books like The Little LISPer teach you LISP in hardly any time (at least enough to use it in a console I reckon) so I'm not really sure why you guys say it's so hard?


Like I said, they are probably refering to Common Lisp. The Little LISPer teaches Scheme. We really need to define what we mean by "Lisp" or this thread is going to get confusing, since there are three fairly commonly used meanings (the Lisp family, Common Lisp or Scheme)
Subotron
Subotron
I probably should mention in my course we use Scheme, not common LISP or something else. Forgive me for the vagueness :)

So I'd prefer using Scheme over LISP, but yes, I want to become quite serious with my engine (in a non-commercial way, but I think it's quite good ;)) so I'll only combine it with LISP/Scheme if it's any good.
Cocalus
Cocalus
The biggest disadvantage is that few people seem to be able to program in it (some aren't even willing to try). If the language is just for you then that's not really a problem. The hard part would be interfacing it with C/C++.

As far as interpreter's go it's pretty easy to implement a small dialect of LISP (it may be tricker to optimize though). SICP can teach you a lot about programming in scheme (a dialect of LISP). And the latter chapters are about making a interpreter and compiler for scheme (which is written in scheme but it teaches the concepts needed). I'm going through the book now and I'm on the interpreter chapter.
SiCrane
SiCrane
Quote:
Original post by Roboguy
I would say this problem is not inherit of Lisp. Are just refering to Common Lisp?

I would. And I'm referring to all Lisp dialects, including Scheme. Don't get me wrong, Scheme is my preferred Lisp dialect, but most people just don't grok functional languages. Ever tried grading for a class that used Scheme as the implementation language? It's not pretty.
Flatlander
Flatlander
One thing to remember is that the language wouldn't need to be that functional. In Common Lisp, for example, you can easily use imperative style if that's what fits the problem. You could have something like

(move-player-to 10+player.x 0 player.y)
(when near some-object (play-sound tzabang))

if that's what you want. I don't think that's too weird of an syntax for a non-lisper and you still could keep the more lispy features available for those who want to use them. Personally I would use ECL or some of the numerous Schemes (maybe Chicken) available rather than wasting my time on reinventing the wheel. Both Chicken and ECL have compilers and language features that make them adequate for more than mere scripting, in case you are interested in implementing bigger parts of your engine with lispy language.
---from www.yellow-hut.com/blog
Steadtler
Steadtler
There are at least 3 PS/PS2 games entirely written in Lisp.
Troll
Troll
Quote:
Original post by Steadtler
There are at least 3 PS/PS2 games entirely written in Lisp.


How many companies? Besides those written by Naughty Dog, are there any others? And are they written entirely in Lisp or just partially?
The Reindeer Effect
The Reindeer Effect
Quote:
Original post by SiCrane
Personally, one of the points on my wish list for a good scripting language is that it be easy for someone who doesn't have a four year degree in computer science to use. Lisp more or less fails on that goal. Lisp is fairly powerful, but it takes a fairly different mindset to use than more procedural languages.

Writing a Lisp interpreter, for a reduced subset of Lisp anyways, is relatively easy. However, if you aren't that familiar with C++ memory management you might have a hard time dealing with the garbage collection necessary for a proper Lisp implementation.


Huh? What aspects of a four year CS degree are required to learn Scheme? Can you give me any tangible examples of why Scheme is more complex than your language of choice? It is one of the simplest languages in existence ... the syntax is minimal and the culture promotes english words as fundamental rather than arbitrary symbols. The canonical introductory program for any language is 'Hello World'. Here is the Scheme solution:

"Hello, World!"

This evaluates to "Hello, World!". Confused yet?

Procedural languages are a branch, Scheme is the root. You can program in an imperative style if you so desire ... Scheme is multiparadigm. As Fruny mentioned, the purpose of a scripting language is to allow non-programmers to add content to the game. The issue here is the interface: users don't want to be brought down with low level details. They wish to be operating at a certain level of abstraction. If you use Scheme like an idiot and bombard them with irrelevent details then they are going to be confused. Likewise with ANY language.

Complain about the parentheses. Complain about the lack of Scheme libraries. Complain about performance (this is not a well founded complaint, but it still is a popular one). Don't just make vague statements that have no grounds.
SiCrane
SiCrane
Quote:
Original post by Flatlander
One thing to remember is that the language wouldn't need to be that functional. In Common Lisp, for example, you can easily use imperative style if that's what fits the problem. You could have something like

(move-player-to 10+player.x 0 player.y)
(when near some-object (play-sound tzabang))

While I sympathize with that point of view, the fact that the code you posted is not valid Lisp or Scheme undercuts the point you were trying to make. Presumably you meant (move-player-to (+ 10 player.x) 0 player.y). Now, you're someone who's aparently familiar enough with Lisp dialects to want to recommend it as a scripting language, but you still can't bang out a two line example without a syntax error. That's a pretty bad sign for the suitability for a scripting language.
Trap
Trap
There is nothing technical about Lisp that makes it somehow more difficult to use than any other programming language.

It's a social problem. It is perceived as difficult/impractical/elitist/whatever and people refuse to give it a try.
Trap
Trap
Quote:
Original post by SiCrane
While I sympathize with that point of view, the fact that the code you posted is not valid Lisp or Scheme undercuts the point you were trying to make. Presumably you meant (move-player-to (+ 10 player.x) 0 player.y). Now, you're someone who's aparently familiar enough with Lisp dialects to want to recommend it as a scripting language, but you still can't bang out a two line example without a syntax error.

You can't know if it is a syntax error. You can make your own syntax in Lisp, so every example that is a valid list can have any meaning you want it to have.

That said, it is probably a very bad idea to make 10+player.x mean (+ 10 player.x). + is a valid part of symbol-names, so you can have a "variable" named a+b. Especially you could have a thing named player.x+ and then player.x+10 would be very difficult to interpret.
Oluseyi
Oluseyi
Quote:
Original post by Trap
There is nothing technical about Lisp that makes it somehow more difficult to use than any other programming language.

It's a social problem. It is perceived as difficult/impractical/elitist/whatever and people refuse to give it a try.

Yeah. I mean, who doesn't think in prefix notation?

The closer your notation is to the rudimentary bits of algebra non-programmers are likely to be familiar with, the better your language as a scripting tool. Unsurprisingly, LISP (all variants/dialects; I'm not bothering to discriminate) fails here.

Let's take The Reindeer Effect's "Hello, World!" example. The code:
"Hello, World!"

"evaluates to" "Hello, World!" What does that even mean to a non-programmer? Where's the verb? Is that text printed out? How does he know?

The "simplicity" of LISPs is based on many, many unintuitive assumptions, from the perspective of the lay programmer. Explicit is better than implicit for them, so long as there's a high enough level of abstraction.
Trap
Trap
Quote:
Original post by Oluseyi
Yeah. I mean, who doesn't think in prefix notation?

The closer your notation is to the rudimentary bits of algebra non-programmers are likely to be familiar with, the better your language as a scripting tool. Unsurprisingly, LISP (all variants/dialects; I'm not bothering to discriminate) fails here.

All programming languages use prefix-notation for most things:
do(a, b, c)

some with a weird fixation on the first parameter:
a.do(b, c)

There is no rule that says that math has to be prefix-math in Lisp, there are several Lisp-apps that provide a infix-math interface, maxima for example. There are libs that provide an infix-reader.

One of the most common languages used by non-programmers is a functional one btw: Excel

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.