[Quiz] [Solution] Lisp Game

Hello Group,

Nice quiz James!

I refreshed and added to my lisp knowledge and had fun with adventure.
I did a one to one translation from the lisp code to ruby code. I used
a similar user interface targeting irb as proposed.

Using a method_missing hack I allowed things like

    pickup bottle

or even

    splash bottle frog

to work.

Then I rewrote the whole thing in ruby style using a readline
interface and adding some capabilities. I think it came out quite nice
and I juggled a lot with meta programming concepts. So thanks to all
the helpfull people here on the list I have learned a lot this week.

The solution can be found and browsed at

http://ruby.brian-schroeder.de/quiz/adventure/

best regards,

Brian

···

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/

Brian Schröder:

...
or even

    splash bottle frog

to work.

Then I rewrote the whole thing in ruby style using a readline
interface and adding some capabilities. I think it came out quite nice
and I juggled a lot with meta programming concepts. So thanks to all
the helpfull people here on the list I have learned a lot this week.

I've enjoyed reading both versions of your code. It looks a lot more
comfortable than my attempts at retaining the LISP code's semantics.

The define_game_action method is particularly interesting: using "subject,
object = *args.flatten" to un-collect arguments from a passed array (built
by a magic method-missing) is cool. The coolest bit, though, is passing the
parameter (local) variable action to instance_eval inside the define_method
block. I don't quite get how that works; if you read my code, you'll see I
defined that function into a separate method. I thought methods were banned
from accessing local variables from outside their scope - this one seems to
be staying in like in a closure.

I'm glad to see evidence in the "Eval and block problems" thread that it's
harder than it looks for other people, too :slight_smile:

Cheers,
Dave

define_method() builds a method from the provided block and all Ruby blocks are closures. That's why it behaves differently, I think.

James Edward Gray II

···

On Oct 5, 2005, at 10:36 AM, Dave Burt wrote:

The coolest bit, though, is passing the parameter (local) variable action to instance_eval inside the define_method block. I don't quite get how that works; if you read my code, you'll see I
defined that function into a separate method. I thought methods were banned from accessing local variables from outside their scope - this one seems to be staying in like in a closure.