Tatsuhiko Miyagawa's Blog

Sandwich ordering callback function

March 29, 2007

Here’s the callback code that works for Bayside Market and a deli in front of my apartment. Inspired by the SWL work by Nick. Maybe we can write a SML::Callback function that reads SML document and compiles it to the callback function.

use strict;   my $fail;   sub order_sandwich {     local $_ = shift; # prompt       /^How are you/         and return “I’m good.”;     /^What .* order/         and return “Chicken Breast Sandwich.”;     /^What kind of bread/         and return “French Roll.”;     /^(Put )?everything\?/i         and return “Yes.”;     /cheese/         and return “Cheddar Cheese.”;       if ($fail++ <= 3) {         return “Sorry?”;     }       return “Whatever.”; }