|
The point of this SPEL is to show you just how sophisticated
and clever you can get with these SPELs. Also, the ugliness
doesn't really matter much if we only have to write it once and
then can use it to make hundreds of commands for a bigger
adventure game.
|
Let's use our new SPEL to replace our ugly weld
command:
|
(game-action weld chain bucket attic
(cond ((and (have 'bucket) (setq chain-welded 't))
'(the chain is now securely welded to the bucket -))
(t '(you do not have a bucket -))))
|
Look at how much easier it is to understand this command -
The game-action SPEL lets us write exactly what we
want to say without a lot of fat. It's almost like we've
created our own computer language just for creating game
commands. Creating your own pseudo-language with SPELs is
called Domain Specific Language Programming, a
very powerful way to program quickly and elegantly.
|
(weld chain bucket)
|
==> (you do not have the chain -)
|
...we still aren't in the right situation to do any welding,
but the command is doing its job!
|
<< begin
< previous -
next >
end >>
|