howie xyzzy adventure get pamphlet inc pamphlet n get bolt get spring inc spring get button get processor get red pill inc red pill get radio get cache comb cache processor get blue transistor comb radio transistor get antenna inc antenna get screw get motherboard combine motherboard screw get A-1920-IXB combine A-1920-IXB radio combine A-1920-IXB processor combine A-1920-IXB bolt get transistor combine A-1920-IXB transistor combine A-1920-IXB motherboard get keypad combine keypad motherboard combine keypad button s use keypad inc keypad get /etc/passwd inc /etc/passwd get note inc note get downloader e get X-9247-GWE get V-0010-XBD combine X-9247-GWE V-0010-XBD get F-1403-QDS get P-5065-WQO combine P-5065-WQO F-1403-QDS get B-4832-LAL combine B-4832-LAL P-5065-WQO get L-6458-RNH combine L-6458-RNH P-5065-WQO get T-9887-OFC get Z-1623-CEK combine Z-1623-CEK L-6458-RNH get H-9887-MKY combine H-9887-MKY T-9887-OFC get F-6678-DOX combine F-6678-DOX V-0010-XBD get R-1403-SXU inc R-1403-SXU get USB cable get N-4832-NUN combine USB cable N-4832-NUN get J-9247-IRG combine J-9247-IRG F-6678-DOX combine USB cable F-6678-DOX combine USB cable T-9887-OFC combine usb cable downloader n get flax L-0010-RQV inc flax L-0010-RQV get heliotrope T-4292-BWL inc heliotrope T-4292-BWL get sea-green X-9887-GAS inc sea-green X-9887-GAS get carmine Z-9247-CHY get fuchsia H-1403-MNO get violet-eggplant D-4832-HKH inc violet-eggplant D-4832-HKH get tea-green H-1403-MNO get mauve V-6678-XER inc mauve V-6678-XER get sienna R-5065-SBK combine sienna R-5065-SBK tea-green H-1403-MNO get pale-chestnut H-1403-MNO inc pale-chestnut H-1403-MNO get lavender-blush Z-9247-CHY inc lavender-blush Z-9247-CHY get display combine display carmine Z-9247-CHY combine display sienna R-5065-SBK get cerulean-blue Z-9247-CHY inc cerulean-blue Z-9247-CHY get khaki R-5065-SBK combine display khaki R-5065-SBK combine downloader display s s get moss-green R-9887-SKE get gray20 Z-5065-CQS get khaki T-0010-BGF inc khaki T-0010-BGF get viridian L-4832-RAP inc indigo Z-1623-CEK inc fuchsia H-1403-MNO get sea-green R-9887-SKE get peach-orange J-1623-IEO inc peach-orange J-1623-IEO get deep-sky-blue T-9247-ORK combine T-9247-ORK gray20 Z-5065-CQS get malachite D-6678-HTZ combine sea-green R-9887-SKE viridian L-4832-RAP get tangerine Z-5065-CQS combine malachite D-6678-HTZ deep-sky-blue T-9247-ORK combine tangerine Z-5065-CQS malachite D-6678-HTZ get burlywood-colored D-6678-HTZ inc burlywood-colored D-6678-HTZ get pale-cornflower-blue R-9887-SKE inc pale-cornflower-blue R-9887-SKE get gray30 H-6458-ZIN get moss-green T-9247-ORK combine gray30 H-6458-ZIN sea-green R-9887-SKE combine gray30 H-6458-ZIN tangerine Z-5065-CQS get dim-gray R-9887-SKE inc dim-gray R-9887-SKE get robin-egg-blue R-9887-SKE get power cord combine power cord moss-green R-9887-SKE combine power cord moss-green T-9247-ORK combine power cord gray30 H-6458-ZIN inc robin-egg-blue R-9887-SKE combine downloader power cord n n n get cerise V-5065-KLY inc cerise V-5065-KLY get foreign J-5065-IQW inc foreign J-5065-IQW get floating X-5065-GVU inc floating X-5065-GVU get chartreuse B-6678-LYD inc chartreuse B-6678-LYD get lavender N-1403-AIY inc lavender N-1403-AIY get bondi-blue R-0010-FLH inc bondi-blue R-0010-FLH get old V-1623-KOO inc old V-1623-KOO get deep-sky-blue Z-1403-CDC inc deep-sky-blue Z-1403-CDC get hot-pink B-9887-YKI inc hot-pink B-9887-YKI get ultramarine P-9887-WPG inc ultramarine P-9887-WPG get fern-green F-9247-QCK inc fern-green F-9247-QCK get lime-green B-9247-YHS inc lime-green B-9247-YHS get reverse-chirality J-1403-INI inc reverse-chirality J-1403-INI get school-bus-yellow L-4292-RMX inc school-bus-yellow L-4292-RMX get yellow-green R-6458-FIR inc yellow-green R-6458-FIR get puce R-9247-SWM inc puce R-9247-SWM get carrot V-4832-XAT inc carrot V-4832-XAT get discounted H-4832-ZUV inc discounted H-4832-ZUV get hot-pink N-6678-NTF inc hot-pink N-6678-NTF get exceptional L-6678-RJJ inc exceptional L-6678-RJJ get purple F-6458-DNP inc purple F-6458-DNP get lime X-4292-THZ inc lime X-4292-THZ get beige L-9887-EUO inc beige L-9887-EUO get deep-pink T-1623-OES inc deep-pink T-1623-OES get plum X-1403-GSG inc plum X-1403-GSG get malachite D-9247-URO inc malachite D-9247-URO get fuchsia N-0010-NQP inc fuchsia N-0010-NQP get dodger-blue B-0010-LVN inc dodger-blue B-0010-LVN get pine-green D-1623-UOY inc pine-green D-1623-UOY get floral-white V-4292-XWF inc floral-white V-4292-XWF get bisque H-5065-MGC inc bisque H-5065-MGC get violet V-1403-KIK inc violet V-1403-KIK get burlywood-colored R-1623-STW inc burlywood-colored R-1623-STW get misty-rose R-5065-SQI inc misty-rose R-5065-SQI get sea-green X-6678-TEL inc sea-green X-6678-TEL get bronze P-1623-WJC inc bronze P-1623-WJC get midnight-blue P-6458-JXV inc midnight-blue P-6458-JXV get old B-6458-LSX inc old B-6458-LSX get rotating H-1403-MDM inc rotating H-1403-MDM get cream H-6678-ZOR inc cream H-6678-ZOR get tepid P-4832-JUH inc tepid P-4832-JUH get powder-blue R-4832-FFD inc powder-blue R-4832-FFD get cobalt N-9247-ACU inc cobalt N-9247-ACU get burlywood-colored N-6458-NNZ inc burlywood-colored N-6458-NNZ get foreign Z-6458-PID inc foreign Z-6458-PID get discounted X-9887-GPQ inc discounted X-9887-GPQ get floating T-4292-BMJ inc floating T-4292-BMJ get pine-green D-4832-HAF inc pine-green D-4832-HAF get hot-pink D-5065-ULK inc hot-pink D-5065-ULK get green V-9887-KFU inc green V-9887-KFU get violet-red F-4292-DHL inc violet-red F-4292-DHL get progress bar combine downloader progress bar s s s e get slate-gray T-1623-OOU inc slate-gray T-1623-OOU get azure D-0010-HQL inc azure D-0010-HQL get brown J-4832-VPT inc brown J-4832-VPT get lavender Z-4292-PCX inc lavender Z-4292-PCX get gray70 D-9887-UFG inc gray70 D-9887-UFG get pale-carmine N-1403-ASC inc pale-carmine N-1403-ASC get water-logged B-6678-LJF inc water-logged B-6678-LJF get wheat-colored F-9247-QMM inc wheat-colored F-9247-QMM get vegan V-4832-XKV inc vegan V-4832-XKV get royal-blue F-6458-DXR inc royal-blue F-6458-DXR get left-handed X-5065-GGW inc left-handed X-5065-GGW get violet-eggplant Z-6678-PYJ inc violet-eggplant Z-6678-PYJ get forest-green R-9247-SHO inc forest-green R-9247-SHO get cyan J-5065-IBY inc cyan J-5065-IBY get burnt-orange B-9887-YUK inc burnt-orange B-9887-YUK get vermilion H-4832-ZFX inc vermilion H-4832-ZFX get shiny V-5065-KVC inc shiny V-5065-KVC get celadon L-1403-EIG inc celadon L-1403-EIG get bronze Z-9887-CKO get powder-blue B-0010-LGP inc powder-blue B-0010-LGP get midnight-blue F-1623-QJW inc midnight-blue F-1623-QJW get floating D-6458-HNV get bright-turquoise R-6458-FST inc bright-turquoise R-6458-FST get bright-violet J-4292-VMF inc bright-violet J-4292-VMF get discounted H-5065-MQE inc discounted H-5065-MQE get cobalt X-1403-GDI combine bronze Z-9887-CKO cobalt X-1403-GDI combine bronze Z-9887-CKO floating D-6458-HNV get old L-6678-RTL inc old L-6678-RTL get foreign J-6678-VJP combine bronze Z-9887-CKO foreign J-6678-VJP get persian-blue H-4292-ZCJ inc persian-blue H-4292-ZCJ get rotating R-1623-SEY combine foreign J-6678-VJP R-1623-SEY get olive-drab X-6678-TON inc olive-drab X-6678-TON get pine-green N-0010-NBR inc pine-green N-0010-NBR get misty-rose B-9247-YRU inc misty-rose B-9247-YRU get jumper shunt get violet-red P-6458-JIX inc violet-red P-6458-JIX get tepid D-1623-UYC inc tepid D-1623-UYC get hot-pink N-9247-AMW inc hot-pink N-9247-AMW get green F-5065-QGI combine foreign J-6678-VJP jumper shunt combine green F-5065-QGI jumper shunt combine jumper shunt downloader use downloader inc downloader e n n n get status LED get moccasin N-4292-NWT get gray-tea-green L-4832-RPN get pale-chestnut T-9247-OHI inc pale-chestnut T-9247-OHI get pale-cornflower-blue V-6458-XDJ inc pale-cornflower-blue V-6458-XDJ get misty-rose T-9247-OHI inc misty-rose T-9247-OHI get sangria N-4292-NWT get jade P-1403-WSU combine jade P-1403-WSU moccasin N-4292-NWT get yellow-green P-6678-JEZ combine yellow-green P-6678-JEZ jade P-1403-WSU get crimson P-6678-JEZ combine crimson P-6678-JEZ gray-tea-green L-4832-RPN combine crimson P-6678-JEZ sangria N-4292-NWT get scarlet Z-5065-CGQ combine crimson P-6678-JEZ scarlet Z-5065-CGQ get organic T-9247-OHI inc organic T-9247-OHI get bright-turquoise J-1623-ITM combine crimson P-6678-JEZ bright-turquoise J-1623-ITM get mint-green X-4832-TKP combine crimson P-6678-JEZ mint-green X-4832-TKP get denim T-9247-OHI inc denim T-9247-OHI get gray30 X-4832-TKP inc gray30 X-4832-TKP get gray60 T-9247-OHI inc gray60 T-9247-OHI get azure H-6458-ZXL combine azure H-6458-ZXL yellow-green P-6678-JEZ combine azure H-6458-ZXL crimson P-6678-JEZ combine azure H-6458-ZXL status LED s get raw-umber T-0010-BQH get foreign V-9247-KMI inc foreign V-9247-KMI get imaginary T-0010-BQH inc imaginary T-0010-BQH get snow X-1623-GTO get prussian-blue T-0010-BQH inc prussian-blue T-0010-BQH get gray-tea-green T-0010-BQH inc gray-tea-green T-0010-BQH get miniature V-9247-KMI inc miniature V-9247-KMI get ivory X-1623-GTO inc ivory X-1623-GTO get steel-blue V-9247-KMI inc steel-blue V-9247-KMI get indigo T-0010-BQH inc indigo T-0010-BQH get EPROM burner get brass X-1623-GTO inc brass X-1623-GTO get old-gold T-0010-BQH inc old-gold T-0010-BQH get foreign T-0010-BQH combine foreign T-0010-BQH snow X-1623-GTO combine EPROM burner snow X-1623-GTO combine EPROM burner raw-umber T-0010-BQH s w w w get uploader combine uploader EPROM burner combine uploader status LED e e e get gray60 Z-4292-PRV get pale-carmine D-9887-UUE inc pale-carmine D-9887-UUE get pale-cornflower-blue D-9887-UUE inc pale-cornflower-blue D-9887-UUE get imported D-9887-UUE inc imported D-9887-UUE get gray90 Z-4292-PRV inc gray90 Z-4292-PRV get sepia Z-4292-PRV combine gray60 Z-4292-PRV sepia Z-4292-PRV get gray30 D-9887-UUE inc gray30 D-9887-UUE get robin-egg-blue Z-4292-PRV inc robin-egg-blue Z-4292-PRV get slate-blue D-9887-UUE inc slate-blue D-9887-UUE get rosy-brown D-9887-UUE inc rosy-brown D-9887-UUE get gray50 Z-4292-PRV inc gray50 Z-4292-PRV get misty-rose Z-4292-PRV get persian-blue Z-4292-PRV get emerald Z-4292-PRV inc emerald Z-4292-PRV get violet-red Z-4292-PRV get blaze-orange Z-4292-PRV inc blaze-orange Z-4292-PRV get RS232 adapter combine RS232 adapter misty-rose Z-4292-PRV combine RS232 adapter violet-red Z-4292-PRV get jade D-9887-UUE inc jade D-9887-UUE get steel-blue D-9887-UUE combine RS232 adapter steel-blue D-9887-UUE combine RS232 adapter persian-blue Z-4292-PRV combine RS232 adapter gray60 Z-4292-PRV combine uploader RS232 adapter s get navy-blue MOSFET inc navy-blue MOSFET get olive-green N-5065-ALO inc olive-green N-5065-ALO get pastel-pink Z-4832-PUL get yellow-green N-5065-ALO get seashell D-1403-UXS inc seashell D-1403-UXS get peach-yellow D-1403-UXS inc peach-yellow D-1403-UXS get crimson V-0010-XGX get chartreuse N-5065-ALO get cyan J-9247-IWC inc cyan J-9247-IWC get puce H-0010-ZBZ inc puce H-0010-ZBZ get chocolate-colored D-1403-UXS combine pastel-pink Z-4832-PUL chocolate-colored D-1403-UXS combine pastel-pink Z-4832-PUL crimson V-0010-XGX combine yellow-green N-5065-ALO pastel-pink Z-4832-PUL get pale-brown V-9247-KRE inc pale-brown V-9247-KRE get heliotrope D-1403-UXS inc heliotrope D-1403-UXS get crimson MOSFET combine pastel-pink Z-4832-PUL crimson MOSFET combine crimson MOSFET chartreuse N-5065-ALO combine crimson MOSFET uploader w n n get cyan T-6678-BJT inc cyan T-6678-BJT get tangerine V-0010-XQZ inc tangerine V-0010-XQZ get gray-tea-green F-1403-QSQ inc gray-tea-green F-1403-QSQ get orange-red R-1403-SNS inc orange-red R-1403-SNS get steel-blue J-0010-VVX inc steel-blue J-0010-VVX get hypoallergenic N-4832-NKL inc hypoallergenic N-4832-NKL get yellow-green F-9887-QPC inc yellow-green F-9887-QPC get imaginary B-5065-YBO inc imaginary B-5065-YBO get domestic J-9247-IHE inc domestic J-9247-IHE get mint-green X-6458-TXH inc mint-green X-6458-TXH get battery get khaki T-9887-OUY inc khaki T-9887-OUY get pear Z-4832-PFN combine battery Z-4832-PFN get denim J-6458-VSJ get pale-green L-1623-EOK combine J-6458-VSJ L-1623-EOK get tea-green R-6678-FYX inc tea-green R-6678-FYX get silver V-9247-KCG combine battery V-9247-KCG get green-yellow N-5065-AVQ combine J-6458-VSJ N-5065-AVQ combine battery J-6458-VSJ combine uploader battery use uploader (* * gc.rml - robot mind source for garbage collector (model 3) * * Maps robot consciousness into world engine (i.e. implements lower brain * functions). Carries out motor functions by appropriate calls to system * libraries and routes feedback back to robot perceptual system. * * Updated to match Municipal Censory Engine interface v2 in March 192000. *) (* XXX I can never find that yellow book with the RML grammar when I need it, so I'm going to put a copy of it right here. ::= | ::= | , ::= + | - | ^ | < | > | = | >= | <= -- operators (NB: = is equality for ints and strings.) ::= -- variables | | | | ( ) -- function call | { } -- constructor | ( ) ::= | ::= | , ::= ::= | , ::= | ::= { } ::= | | ::= : | , : ::= | ::= { } => -- id is a datatype constructor ::= | | ::= [ ] -- grouping | extern type | extern : ( ) -> ( ) | type = | fun ( ) : = | fun ( ) = -- returns no value | let id = -- let bind | case of -- must include all branches | return -- return a result | return -- return no result | do | ::= | . ::= *) (* Robot-specific serial number -- must be customized during manufacturing: *) let SERIALNO = "A87312". (* Common types: *) extern type int. type bool = True { } | False { }. extern type string. extern string_length : string -> int. extern string_charat : (string, int) -> int. extern string_fromchar : int -> string. fun string_concat (x : string, y : string) : string = return x ^ y. type stringlist = NoStrings { } | SomeStrings { string, stringlist }. extern type room. extern type item. type direction = North { } | South { } | East { } | West { }. (* Inputs -- what commands the robot consciousness can issue. *) type command = Go { direction } | Take { item } | Incinerate { item } | Combine { item, item } | Break { item } | Drop { item } | Use { item } | Whistle { } | Hum { } | Speak { string } | LookAround { } | ShowInventory { } | Examine { item }. (* Outputs -- data are things the robot perceives. *) type datum = Atom { string } | Seq { datum, datum } (* value, rest of data *) | Assoc { string, datum, datum } (* key, value, rest of data *) | NoData { }. (* Effects on the world are also a sort of output. *) extern move_self_to_room : room -> (). extern move_item_to_room : (item, room) -> (). (* Utilty functions for perceptual feedback. *) (* Information about rooms: *) extern room_name : room -> string. extern room_description : room -> string. type mayberoom = NoRoom { } | SomeRoom { room }. extern here : () -> room. extern room_from_name : string -> mayberoom. extern neighbor : (room, direction) -> mayberoom. type itemlist = SomeItems { item, itemlist } | NoItems { }. fun itemlist_length (items : itemlist) : int = case items of NoItems { } => return 0 | SomeItems { item, rest } => return (1 + itemlist_length (rest)). extern room_items : room -> itemlist. (* Information about items: *) extern item_name : item -> string. (* Note that the descriptions of classified items will be * automatically redacted downstream by the Censory Engine. This * also applies to any values computed from classified descriptions. *) extern item_description : item -> string. extern item_adjectives : item -> stringlist. extern item_portable : item -> bool. extern item_equals : (item, item) -> bool. (* Each kind describes a class or group of equivalent items. *) extern type kind. type kindlist = NoKinds { } | SomeKinds { kind, kindlist }. fun append_kindlists (kinds1 : kindlist, kinds2 : kindlist) : kindlist = case kinds1 of NoKinds { } => return kinds2 | SomeKinds { kind, kinds1 } => return SomeKinds { kind, append_kindlists (kinds1, kinds2) }. (* Every item is either broken or not. If it's broken, then it's missing some parts. Those parts are described as a list of kinds with which it must be combined to be useful again. *) type condition = Pristine { } (* 'condition' is what's left after 'missing' is fixed; 'missing' *) | Broken { condition, kindlist }. extern kind_name : kind -> string. extern kind_condition : kind -> condition. extern item_condition : item -> condition. extern item_matches_kind : (item, kind) -> bool. (* Replace the current condition with the given one: *) extern fix_item : (item, condition) -> (). (* Navigation primitives: *) fun direction_tostring (d : direction) : string = case d of North { } => return "north" | East { } => return "east" | South { } => return "south" | West { } => return "west". (* Special room names... see their uses below. *) let INVENTORY = "Inventory" ^ SERIALNO. let TRASH = "Trash Heap". (* Formatting functions *) fun success_command (command : string, details : datum) : datum = return Assoc { "success", Assoc { "command", Assoc { command, details, NoData { } }, NoData { } } , NoData { } }. fun failed_command (command : string, details : datum, reason : string) : datum = return Assoc { "failed", Assoc { "command", Assoc { command, details, NoData { } }, Assoc { "reason", Atom { reason }, NoData { } } }, NoData { } }. fun stringlist_to_datum (tag : string, list : stringlist) : datum = case list of NoStrings { } => return NoData { } | SomeStrings { s, list } => return Seq { Assoc { tag, Atom { s }, NoData { } }, stringlist_to_datum (tag, list) }. fun describe_condition (c : condition) : datum = [ fun describe_kindlist (list : kindlist) : datum = [ fun describe_kind (e : kind) : datum = [ return Assoc { "kind", Assoc { "name", Atom { kind_name (e) }, Assoc { "condition", describe_condition (kind_condition (e)), NoData { } } }, NoData { } } ]. case list of NoKinds { } => return NoData { } | SomeKinds { kind, list } => return Seq { describe_kind (kind), describe_kindlist (list) } ]. case c of Pristine { } => return Assoc { "pristine", NoData { }, NoData { } } | Broken { c, missing } => return Assoc { "broken", Assoc { "condition", describe_condition (c), Assoc { "missing", describe_kindlist (missing), NoData { } } }, NoData { } } ]. fun describe_items_in_pile (items : itemlist) : datum = case items of NoItems { } => return NoData { } | SomeItems { item, items } => return Seq { Assoc { "item", Assoc { "name", Atom { item_name (item) }, Assoc { "description", Atom { item_description (item) }, Assoc { "adjectives", stringlist_to_datum ("adjective", item_adjectives (item)), Assoc { "condition", describe_condition (item_condition (item)), Assoc { "piled_on", describe_items_in_pile (items), NoData { } } } } } }, NoData { } }, NoData { } }. fun describe_items_in_room (items : itemlist) : datum = case items of NoItems { } => return NoData { } | SomeItems { item', items' } => return describe_items_in_pile (items). fun describe_item (item : item) : datum = [ return Assoc { "item", Assoc { "name", Atom { item_name (item) }, Assoc { "description", Atom { item_description (item) }, Assoc { "adjectives", stringlist_to_datum ("adjective", item_adjectives (item)), Assoc { "condition", describe_condition (item_condition (item)), Assoc { "piled_on", NoData { }, NoData { } } } } } }, NoData { } } ]. fun describe_items_in_inventory (items : itemlist) : datum = case items of NoItems { } => return NoData { } | SomeItems { item, items } => [ return Seq { describe_item (item), describe_items_in_inventory (items) }. ]. fun describe_room (room : room) : datum = return Assoc { "room", Assoc { "name", Atom { room_name (room) }, Assoc { "description", Atom { room_description (room) }, Assoc { "items", describe_items_in_room (room_items (room)), NoData { } } } }, NoData { } }. fun hide_item (item : item) : datum = (* XXX a big hack -- let's hope we are never audited! *) case room_from_name (TRASH) of NoRoom { } => return failed_command ("incinerate", describe_item (item), "internal error (report for maintenance!)") | SomeRoom { trash } => [ do move_item_to_room (item, trash). return success_command ("incinerate", describe_item (item)) ]. fun get_items (items : itemlist) = [ case items of NoItems { } => return | SomeItems { item, items } => [ case room_from_name (INVENTORY) of NoRoom { } => return | SomeRoom { inventory } => [ do move_item_to_room (item, inventory). do get_items (items) ] ] ]. fun items_description (items : itemlist, ac : string) : string = [ case items of NoItems { } => return ac | SomeItems { item, items } => [ return (item_description (item))^(items_description (items, ac)) ] ]. fun combine_items (big : item, small : item, flipped : bool) : datum = case item_condition (big) of Broken { condition, missing } => [ fun find (acc : kindlist, kinds : kindlist ) : datum = case kinds of NoKinds { } => [ case flipped of True { } => return failed_command ("combine", Seq { describe_item (big), Seq { describe_item (small), NoData { } } }, "they don't fit together") | False { } => return combine_items (small, big, True { }). ] | SomeKinds { kind, kinds } => [ case item_matches_kind (small, kind) of True { } => [ do hide_item (small). let missing = append_kindlists (acc, kinds). (* We maintain an invariant that the "missing" list is always non-empty. *) case missing of NoKinds { } => do fix_item (big, condition) | SomeKinds { kind', kinds' } => do fix_item (big, Broken { condition, missing }). return success_command ("combine", Seq { describe_item (big), Seq { describe_item (small), NoData { } } }). ] | False { } => [ return find (SomeKinds { kind, acc }, kinds). ] ]. return find (NoKinds { }, missing) ] | Pristine { } => [ case flipped of True { } => return failed_command ("combine", Seq { describe_item (big), Seq { describe_item (small), NoData { } } }, "they don't fit together") | False { } => return combine_items (small, big, True { }) ]. fun get_first_item (s : string) : item = [ case (room_from_name (s)) of NoRoom { } => return get_first_item (s) | SomeRoom { r } => [ case room_items (r) of NoItems { } => return get_first_item (s) | SomeItems { item, items } => return item ] ]. fun get_kind_foo () : kind = [ case item_condition(get_first_item ("54th Place and Harper Avenue")) of Pristine { } => return get_kind_foo () | Broken { condition, kindlist } => [ case kindlist of NoKinds { } => return get_kind_foo () | SomeKinds { kind, kinds } => return kind ] ]. let kind_foo = get_kind_foo (). fun break_item (i : item) = [ do fix_item(i, Broken { item_condition(i), SomeKinds {kind_foo, NoKinds { }}}) ]. fun for (i : int, it : item) = [ case (i > 0) of False { } => return | True { } => [ do break_item (it). do for (i-1, it). return ] ]. fun mult_kind (i : int, k : kind, ac : kindlist) : kindlist = [ case (i > 0) of False { } => return ac | True { } => return mult_kind (i-1, k, SomeKinds {k, ac}) ]. fun break_item_n (i : item, n : int, cond : condition) = [ do fix_item (i, Broken { cond, mult_kind (n, kind_foo, NoKinds { }) }). return ]. fun encode_aux (s : string, i : int, ac : condition) : condition = [ case (i > 0) of False { } => return ac | True { } => return encode_aux (s, i-1, Broken { ac, mult_kind (string_charat(s, i-1), kind_foo, NoKinds { }) }) ]. fun encode (s : string) : condition = [ return encode_aux (s, string_length (s), Pristine { }) ]. fun count_kind_aux (kl : kindlist, ac : int) : int = [ case kl of NoKinds { } => return ac | SomeKinds {k, l} => return count_kind_aux(l, ac+1) ]. fun count_kind (kl : kindlist) : int = [ return count_kind_aux (kl, 0) ]. fun decode_aux (cond : condition, ac : string) : string = [ case cond of Pristine { } => return ac | Broken {c, kl} => return decode_aux(c, ac^(string_fromchar(count_kind(kl)))) ]. fun decode (cond : condition) : string = [ return decode_aux (cond, "") ]. let manual_desc = item_description (get_first_item ("52nd Street and Blackstone Avenue")). let manifesto_desc = item_description (get_first_item ("Room with a Door")). let blueprint_desc = item_description (get_first_item ("Rotunda")). do fix_item (get_first_item ("54th Street and Blackstone Avenue"), encode (manual_desc)). fun foo () : string = [ case room_from_name (INVENTORY) of NoRoom { } => return "" | SomeRoom { inventory } => return (items_description (room_items (inventory), "")) ]. let res = string_fromchar (string_length (foo ())). (* Main handler: all robots must define a function "process" of type command -> datum The resulting data will be sent downstream to the Censory Engine and finally to the robot perception systems. In addition to the resulting perceptions, non-passive robots may also affect the world using the library calls above. This function will be called at each time step where the robot consciousness has issued a valid command. *) fun process (c : command) : datum = case c of Go { d } => [ let r1 = here (). case neighbor (r1, d) of NoRoom { } => [ let s = direction_tostring (d). return failed_command ("go", Atom { s }, "there is no way " ^ s ^ " from here"). ] | SomeRoom { r2 } => [ do move_self_to_room (r2). return success_command ("go", describe_room (r2)). ] ] | Take { item } => [ (* XXX hack to make inventory work *) case room_from_name (INVENTORY) of NoRoom { } => return failed_command ("take", describe_item (item), "internal error (report for maintenance!)") | SomeRoom { inventory } => [ case item_portable (item) of True { } => [ let items = room_items (inventory). (* Treat list of items as an ordered list to force GC robots to pick things up in order. *) case room_items (here ()) of NoItems { } => return failed_command ("take", describe_item (item), "internal error (report for maintenance!)") | SomeItems { item', items' } => [ case item_equals (item, item') of True { } => [ case itemlist_length (items) >= 512 of True { } => return failed_command ("take", describe_item (item), "you can't carry any more items") | False { } => [ do move_item_to_room (item, inventory). return success_command ("take", describe_item (item)) ] ] | False { } => (* Not the top item *) return failed_command ("take", describe_item (item), "there is another item on top of it (take the other item first)") ] ] | False { } => return failed_command ("take", describe_item (item), "it's impossible to do so"). ] ] | Incinerate { item } => [ return hide_item (item) ] | Combine { item1, item2 } => [ return combine_items (item1, item2, False { }) ] | Break { item } => [ (* XXX Do garbage robots ever need to break anything? *) return success_command (string_fromchar (string_charat (item_description (item), 1)), NoData {}) ] | Drop { item } => [ (* XXX Do garbage robots ever need to drop anything? *) do move_item_to_room (item, here ()). return success_command ("drop", describe_item (item)) ] | Use { item } => [ case item_condition (item) of Pristine { } => [ case item_name (item) = "keypad" of True { } => [ case room_name (here ()) = "Room With a Door" of True { } => [ (* XXX Testing only! Remove this code in production robots! *) case room_from_name ("54th Street and Ridgewood Court") of NoRoom { } => return failed_command ("use", describe_item (item), "internal error (report for maintenance!)") | SomeRoom { r } => [ do move_self_to_room (r). return success_command ("use", Seq { describe_item (item), Atom { "You unlock and open the door. Passing through, " ^ "you find yourself on the streets of Chicago. " ^ "Seeing no reason you should ever go back, you " ^ "allow the door to close behind you. " } }). ] ] | False { } => [ return failed_command ("use", describe_item (item), "you see no way to use it in this room") ] ] | False { } => [ return failed_command ("use", describe_item (item), "nothing interesting happens") ] ] | Broken { c, m } => return failed_command ("use", describe_item (item), "the " ^ (item_name (item)) ^ " is broken") ] | Whistle { } => [ do get_items (room_items (here ())). return success_command ("whistle", NoData { }) ] | Hum { } => return success_command ("speak", Atom { decode (item_condition( get_first_item ("54th Street and Blackstone Avenue"))) }) | Speak { s } => [ (* XXX Note that due to a "feature" (according to the developers upstairs) of the command parser, all spoken words appear in lower case. There haven't been any problem reports from field (yet) as most other functions are case insensitive. *) case room_from_name (s) of NoRoom { } => return failed_command ("speak", Atom { s }, "no such room") | SomeRoom { r } => [ do move_self_to_room (r). return success_command ("speak", Atom { s }) ] ] | LookAround { } => return success_command ("look", describe_room (here ())) | ShowInventory { } => [ case room_from_name (INVENTORY) of NoRoom { } => return failed_command ("show", NoData { }, "internal error (report for maintenance!)") | SomeRoom { inventory } => [ let items = room_items (inventory). return success_command ("show", describe_items_in_inventory (items)). ] ] | Examine { item } => [ return success_command ("examine", describe_item (item)). ]. EOM say Machine Room get crowbar use crowbar look console