[plt-scheme] How to use Eval for a MUD

From: Synx (plt at synx.us.to)
Date: Wed Jan 27 16:48:23 EST 2010

Jakub Piotr Cłapa wrote:
> IMHO you should be wrapping all
> wizard-written code in a lambda which gets the current world state as an
> argument.

That seems kind of pointless really. I was going to keep the current
world state in a sqlite database, referenced by global variables. Should
work fine, for transactions and such. No need for me to mess with weird
concepts like Monads, which I'm sure you are aware do not exist.

> My point is that you probably don't want to make much use of Scheme
> object/code-organization/module infrastructure since it may be not
> dynamic enought for you. OTOH you want to evaluate the code once and get
> nice closures JITed for efficiency.

I think the only issue is when and how often do I want to load and
evaluate properties from my database object system. Too much disk
loading can slow things down, even in a text based game, and it's hard
to moderate use of the disk itself, due to the high latency.

> For MUDs STM seems to be the best way to handle concurrency [1].

Couldn't I just use threads? ._.

(thread
  (run-one-session input output))

> Opening an STM transaction
> for the duration of one player command seems to be a good idea. (almost
> all player commands must be atomic)

Or just opening a transaction in general.

(with-transaction db-connection
  (evaluate-next-command ...))

One important idea is to somehow be able to connect the command input
with the command output. So something could be injecting lines into the
player input, but if each line were preceded by an ID unique to the
command used to execute it, you could differentiate, and possibly
reroute different results to different locations.

e.g.
hit demon 7 times
11424
11616: the feather demon hits you for 2 damage! 98/100HP
11424: you hit the feather demon for 100 damage! 9900/10000HP
11616: the feather demon hits you for 2 damage! 98/100HP
13424: CoolDude26 messages you "Hey man, U grinding?"
11424: you hit the feather demon for 103 damage! 9793/10000HP
11616: the feather demon hits you for 2 damage! 96/100HP
message Cooldude26 "Not now man, I'm grinding!"
11424: you hit the feather demon for 103 damage! 9793/10000HP
11616: the feather demon hits you for 2 damage! 98/100HP
11425: You message CoolDude26 with "Not now dude, I'm grinding!"

That sort of a prefix I wouldn't want to require, but ought to be
possible for people who want it and/or have clients that handle it
specially.

What does STM stand for, anyway? [1] doesn't mention it.


Posted on the users mailing list.