Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Your snippet would be condensed into 1 indentation block with pattern matching. In scheme it'd be even more explicit that we're deconstructing command, therefore much much easier to follow logic. No need to worry about cmd, args, etc.

  (match command
    (("quit")    (display "Goodbye!"))
    (("look")    (describe current-room))
    (("get" obj) (character-get obj current-room))
    (("go" dir)  (set! current-room (room-neighbour dir)))
    (_           (display "Invalid command")))


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: