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

Scheme Script

Started by PeterTarkus Apr 18, 2004 at 9:10 AM 25 replies 4.4k views
Original Post
PeterTarkus
PeterTarkus
Hi Folks, I have been toying with a few script languages. I have decided though I am going to spend all my effort on building a Scheme setup specifically for game programming. I have been thinking of taking Tiny Scheme and working with it to build it into a small Game programming system by connecting it to SDL or other libraries. If I can get it to run an asteroids game it is a good start :-) I am curious how many people are interested in seeing Scheme become more popular for game programming. If we had a decent system I think it would rock. Peace->Out
Oluseyi
Oluseyi
The only problem I see with Scheme is that the functional programming paradigm isn''t exactly easy for non-programmers (the main audience for scripting languages) to grasp.
SiCrane
SiCrane
Scheme can be written in a non-functional style. Try taking a look some of the script-fu that was done for Gimp. (Or if you''re a functional language purist, don''t, because it will set you on fire.)
JuNC
JuNC
I think more to the point is the terseness of the usual Scheme syntax, not exactly human friendly (and if you argue - YOU AREN''T HUMAN! ).
PeterTarkus
PeterTarkus
Well, if you took away the ( ) and allowed infix (C style) notations what you would get would look alot like Python :-)

define foo(x):
if(x = 1):
return 1
else:
return foo( x - 1 )

You could hack it in scheme to parse this structure into Scheme code.

In fact I say Python is really just a mutated Scheme!
Viper3369
Viper3369
quote:
Original post by PeterTarkus
I have been toying with a few script languages. I have decided though I am going to spend all my effort on building a Scheme setup specifically for game programming.



Scheme is one of those languages which shouldn't really be called a scripting language. As others have pointed out here and elsewhere) Scheme/Lisp isn't very readable for one. I guess you'll have to choose who your target audience is; it shouldn't be game designers, artists or other non-(real)-programmers. You'll also find some programmers are put off, just because it's Scheme; mainly because they've never come across such a radically different syntax.

See the Scripting Language Proposal thread.

You probably change your mindset and design a *programming* language for *programmers*. I'm not sure this is the right forum for discussing that?

Interestingly enough, Scheme or Lisp is a pretty good language to design and implement a scripting language in; you get some tools straight out of the box; read, eval. For this sort of thing I recommend this text, which has been my faithful friend over the years. He describes modern languages using a Lisp like interpreter, which is written in Pascal.


Programming Languages: An interpreter-Based Approach, Samuel N. Kamin, Addison-Wesley


--
Harvey Thompson (aka Viper)
Software Engineer/Games Researcher, UK.

[edited by - Viper3369 on April 23, 2004 8:37:56 AM]

[edited by - Viper3369 on April 23, 2004 8:39:40 AM]
PeterTarkus
PeterTarkus
I know of only 1 game that used a Lisp interpreter for scripting.

I agree Scheme is hard to read but it is not a difficult language, no more difficult than any of the other scripting languages. I could easily argue that Python is a programmers language too.

My definition of a script language might be different than yours.
Scheme is not as big as Lisp. Compared to Lisp Scheme *is* a scripting language in my eyes. You can prototype very fast in the language. You can use the REPL to alter the behavior of objects dynamically. It is extremely small and embeddable and can connect to C/C++ through FFI.

I don''t think I have violated the integrity of this forum with my proposal. I was meaning to find out how many others might be interested in such a thing. Apparently, not many :-)

Close the thread...

Peace
Oluseyi
Oluseyi
One last thing:
quote:
...I think that if you try to ignore the fact that millions of programmers around the world have learned lisp and don''t prefer to use it, you''re in the land of morbid cognitive dissonance.
PeterTarkus
PeterTarkus
I wonder where you found that quote :-)

Well, maybe I can take it to a different direction. Instead of using Scheme as the script language, instead use Scheme to build script languages both dynamically and statically.

I am working around the details, perhaps in the future some people might be interested and I will make a tutorial on how to use tiny-scheme to build custom mini-languages for their projects.

The nice thing about Tiny Scheme is it supports dynamic loading so you could say (dynamic-load (library)) and plop, all your C functions have been embedded into the interpreter. Than you just whip up a top level loop to interpret the syntax of your script language :-)

See yah guys
GnuVince
GnuVince
Scheme is an extremely good choice in my opinion. Its syntax is the simplest of any programming language, its semantics fit in 55 pages (slimmest standard of any programming language), many people have been exposed to Scheme in college and Scheme is just fun
PeterTarkus
PeterTarkus
I agree too :-) Scheme''s power is in manipulating symbols. I wrote a lexer and parser for a tiny language in like 15 minutes.

With dynamic-load you can load in a DLL of C functions and it integrates them directly to the language interface. What could be easier for a game programmer?? :-)

I was never exposed to Scheme at all, I went to school in the Pascal age and my University did not teach Scheme at all. In fact, they taught Mainframe assembler, so that ought to tell you something At that time they offered an advanced course on C programming which I took and I never went back to Pascal again. You have to remeber at that time C++ was still C-front and there existed no compilers on PCs for the language at all... and this is only in 1994 too.. well, technically, Turbo C++ existed but the compiler was so buggy it was unuseable.

I only started picking up Scheme a little while ago and discovered it was very cool and actually useful. It''s syntax is hard to pick up when you have been engrained in the imperative style but once you get it it is really not that much different in what it can do.

Peace->

PeterTarkus
PeterTarkus


Tutorial part #1

Goto http://tinyscheme.sourceforge.net/ and download it.

If you are using MSVC you have to edit the makefile. Uncomment all the VC stuff and comment all the linux stuff. In makefile # is comment character.

If you are using MSVC6, type vcvars32.bat (hopefully you installed it when it asked). If you are using MSVC7, open a .NET command prompt. Type NMAKE.

Now hopefully it is built. Type scheme. You are now in the REPL :-)

Your first scheme program

>(define (sqr n)(* n n))
>( sqr 2 )

You should see
4

:-)

( )''s are everywhere get used to them :-)

Scheme is not infix like C, 1+1 in scheme is (+ 1 1).

Here are some links to stuff to teach you the language:

http://www.scheme.com/tspl2d/
http://mitpress.mit.edu/sicp/

Well it''s not much of a tutorial but I wrote it in 5 minutes. Maybe in the **future** I can submit a more formal tutorial to Gamedev.

Tiny-Scheme does not implement all of the standard but it implements most of what you would need for a interpreter in a game or to make a small interpreter for your own language.

In scheme everything is a list
( ... )

And lists are both code and data. That is the one thing about Scheme which differs from C etc.

There are a few built in functions for manipulating lists

car ( list ) : this returns the first element
cdr ( list ) : this returns the remainder of the list after the
first element
cadr ( ) : this depends, this does car cdr, and might be more of them like caddr which is car cdr cdr etc.
cons A B : this joins A . B togethor
list A B : this creates a proper list

You can define variables like
(define a)
(set! a ''(1 2 3 4 5) )

But instead do not do this but use
(let (( ...)) ) instead and avoid global variables much

''(...) or quote( ) makes a literal list otherwise the interpreter tries to evaluate it.

(set! a ''(+ 1 2 3) )
(eval a)

this will evaluate a and return 6 :-) One of the interesting things about scheme is you can create dynamic functions on the fly and eval them. This is really useful as you can make programs that make programs that make programs ... :-)

Well I am NOT a scheme guru by any means and I might be leading you astray on some ideas. I will write a better tutorial when I''ve gotten better at it :-)

schlook
schlook
(im the AP above. might as well register..)

wow, that was fast! thanks for the crash course! i allready got tiny up and working right before i hassled you for the tutorial. it was mentioned in another thread around here so i thought i would check it out.

the thing is im looking for a scripting and configuration language for this litle hobby sound generating stuff im doing in c++ and since im mostly toying around i figured it would be fun to test something different then lua and python (which seem to be the two main scripting solutions right now) and see how it works out. i have been using haskell some in school and found the functional style programming quite refreshing and intersting. been meaning to look in to lisp (some people seem to like it alot) but never really took the time so this scheme scripting stuff looks very interesting.

anyways, i will be of reading up on the language (thanks for the links) and try to get it to work with my existing code and see if it clicks. im not sure on the best way to get scheme and c++ to work together but i guess i will have to experiment a bit..

quote:
Original post by PeterTarkus
"I am working around the details, perhaps in the future some people might be interested and I will make a tutorial on how to use tiny-scheme to build custom mini-languages for their projects."


i will be looking out for that tutorial. sounds fascinating

[edited by - schlook on April 25, 2004 3:44:26 PM]
Thoooms
Thoooms
During the fall of 2003 I wrote a scheme compiler in Standard ML, it compiles to a custom bytecode format interpreted by a VM which we wrote too. Since I already have those two pieces I have begun the task to integrate the VM into my engine which would give me a compiled scripting language. Although this is no novelty I still think it is cool due to the fact that no third party components are involved.

My main problem is ofcourse how to handle the interface between the Scheme program and the rest of the engine. I have added a single predefined function not present in the R5RS (The Scheme specification) which will act as a dispatcher, the scheme code will then make a trap to the engine when it desires - much like a standard OS system call, but good ideas are welcome.

[edited by - thoooms on April 25, 2004 4:10:41 PM]
fodd3r
fodd3r
Due to scheme''s regularity, I find it easy to teach others how to work with it. Bring out recursion as a formal topic and that''ll make them cry. Then again, you can just create a few simple constructs to get around that. =)

BTW, there is a mod called trucombat for quake 3, someone on the forum there, created a scheme scripting system for quake 3, not sure how far they got. Gonna have to google to find the link.

Maybe later.
Zahlman
Zahlman
quote:
Original post by GnuVince
55 pages (slimmest standard of any programming language)


Scary.

Of course, there are all kinds of esoteric programming languages that get thought up by some university undergrad and written up in a couple pages worth of HTML on their webpage, but those don''t really count.
flangazor
flangazor
quote:
Original post by Oluseyi
One last thing:
quote:
...I think that if you try to ignore the fact that millions of programmers around the world have learned lisp and don''t prefer to use it, you''re in the land of morbid cognitive dissonance.

If you try to ignore the fact that millions of music fans around the world have heard Cossi Fan Tutti but never [been to see it live|bought a copy], you''re in the land of morbid conginitive dissonance.

Virtually the only complaint people have against Lisp/Scheme is the syntax and this is coming from people who use C style languages. Apart from the raging incongruity of the situation we have, I would like to point out that C style languages take first year University students weeks to get up to speed with wheras Scheme is being taught to children as young as eight and for most others the syntax takes about 10 minutes to learn.
PeterTarkus
PeterTarkus
Hmm, well I was in a real good mood today, got a little piece the other night :-)

To be honest I wasn''t sure if he meant that as a positive comment or a negative comment on Lisp. It is sort of ambigous, it could be taken either way. Read it about ten times or so and apply a little zen, he could be saying 1 up for Lisp, or he could be saying 1 down. I am a glass-half full kind a guy so I took it as positive, meaning that if you beleive programmers hate lisp you are decieved. Maybe he meant, if you think programmers like lisp, you are decieved. Whatever. I don''t care really. I think Scheme is much better than what people credit it for. Unlike C it is based on a formal theory of computation and completely seperated from a physical implementation. That is good as you work on a high level from the top up. It is bad because you rely on a good compiler to create efficient code. But CMUCL supposedly generates code that is as good as C.

C succeeded because the original C language was so mind boggingly simple to build compilers for, it is just an abstract model of a typical program machine. Really the C abstract machine model is hideously broken, if you have worked in the language for more than a few months you begin to realize how many kludges have been worked into C++ it is pathetic. I use C++ mainly because I have full control of everything, not necessarily do I think it is a good language and in fact it is rife with pitfalls and traps. If you think otherwise you are crazy.

Well whatever have fun.

Later
JuNC
JuNC
quote:

Original post by flangazor
...with wheras Scheme is being taught to children as young as eight and for most others the syntax takes about 10 minutes to learn.



Maybe I''m going blind, but that thread just appears to be a couple of people suggesting he teach Scheme, not that anyone actually is or has. Most people in the position to teach 8 year olds (i.e. primary school teachers) wouldn''t have the first clue what Scheme is (a few of my teacher friends from when I was at uni do though - after me harping on about it for months ).

flangazor
flangazor
They are discussing teaching their children. There was a thread about teaching Lisp to other children. For what it''s worth, here''s a thread about an 8th grader who successfully uses Scheme to write games.

Back on topic... I remember Age Of Kings having a scripting language for random map generation and AI rules that felt quite Scheme-like to me. Then again I suppose it was only a data definition format.

Topic Locked

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

Sign in to reply to this topic.