[Quiz] [Solution] Lisp Game

Discussion in 'Ruby' started by Brian Schröder, Oct 3, 2005.

  1. 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, Oct 3, 2005
    #1
    1. Advertising

  2. Brian Schröder

    Dave Burt Guest

    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 :)

    Cheers,
    Dave
     
    Dave Burt, Oct 5, 2005
    #2
    1. Advertising

  3. 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.


    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
     
    James Edward Gray II, Oct 5, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ruby Quiz

    [QUIZ] Lisp Game (#49)

    Ruby Quiz, Sep 30, 2005, in forum: Ruby
    Replies:
    7
    Views:
    135
    soxinbox
    Oct 3, 2005
  2. Jim Menard

    [SOLUTION] Lisp Game (#49)

    Jim Menard, Oct 2, 2005, in forum: Ruby
    Replies:
    9
    Views:
    102
  3. Markus Koenig

    [SOLUTION] Lisp Game (#49)

    Markus Koenig, Oct 2, 2005, in forum: Ruby
    Replies:
    5
    Views:
    123
    James Edward Gray II
    Oct 9, 2005
  4. Louis J Scoras
    Replies:
    13
    Views:
    320
    Dave Burt
    Oct 5, 2005
  5. Sean O'Halpin

    [Solution] Lisp Game #49

    Sean O'Halpin, Oct 6, 2005, in forum: Ruby
    Replies:
    0
    Views:
    177
    Sean O'Halpin
    Oct 6, 2005
Loading...

Share This Page