: radio ( -- d ) trigger @ location ; : say ( s -- ) me @ swap notify ; : notify_else ( s -- ) loc @ me @ rot notify_except ; : do_turn ( s -- s ) dup dup "on" stringcmp swap "off" stringcmp and if pop "Do what with it?" say exit then dup "on" stringcmp not if radio "*on" prop-exists? not if radio "*on" "yes" 0 addprop "You turn the radio on." say me @ name " turns on the radio." strcat notify_else "It is currently tuned to: " radio "*freq" getpropstr strcat " " strcat radio "*band" getpropstr strcat dup say notify_else else "Radio is already on." say then pop else radio "*on" prop-exists? if radio "*on" remove_prop "You turn the radio off." say me @ name " turns off the radio." strcat notify_else else "Radio is already off." say then pop then ; : do_tune tolower "" "fm" subst "" "am" subst .sstrip dup "." instr not if atoi dup dup dup 510 < rot 1630 > rot 10 % or or if pop "Invalid AM frequency." say else intostr radio "*freq" 3 pick 0 addprop radio "*band" "AM" 0 addprop "You set the radio to " over strcat " AM" strcat say me @ name " sets the radio to " strcat swap strcat " AM" strcat notify_else then else dup strlen 4 < over dup "." instr 1 - strcut pop atoi dup 87 < swap 108 > or or if pop "Invalid FM frequency." say exit then dup dup "." instr 1 - strcut swap pop strlen 1 = if pop "Invalid FM frequency." say exit then dup dup "." instr 1 - strcut 1 strcut swap pop 1 strcut pop atoi swap atoi swap dup 2 % not if pop pop "FM tenths must be odd." say exit then intostr swap intostr "." strcat swap strcat radio "*freq" 3 pick 0 addprop radio "*band" "FM" 0 addprop "You set the radio to " over strcat " FM" strcat say me @ name " sets the radio to " strcat swap strcat " FM" strcat notify_else then ; : main ( s -- ) trigger @ name tolower "tune" 4 strncmp not if do_tune exit then trigger @ name tolower "turn radio" 10 strncmp not if do_turn exit then pop "Well, that didn't work." say ;