Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Switches and random

From: joel:neely:fedex at: 17-Feb-2002 16:48

Hi, Daniel, [Izkata--aol--com] wrote:
> I am making a welcome message type of script, > ... Yes, I have to use switches, or something similar... >
Here's a version that doesn't require switch, lets you change the range of phrases by changing data, and lets you use predefined phrases at various places in the phrase tree. HTH! -jn- 8<-------------------------------------------------------- randphrase: make object! [ languages: [ "favorite language is" [ "REBOL"] [ "predicate calculus"] ] desserts: [ "favorite dessert is" [ "chocolate cake"] [ "strawberry cheesecake"] [ "espresso"] ] phrasetree: [ [ "I" [ "like" [ "you"] [ "coffee"] ] [ "hate" [ "viruses"] [ "bugs"] ] ] [ "My" languages desserts ] [ "Your" languages [ "favorite color is" [ "periwinkle"] [ "mauve"] ] ] ] run: func [/local sentence gap branch] [ sentence: copy "" gap: "" branch: phrasetree while [0 < length? branch] [ branch: reduce random/only branch sentence: rejoin [sentence gap branch/1] gap: " " branch: next branch ] join sentence "." ] ] 8<-------------------------------------------------------- which does this: 8<--------------------------------------------------------
>> randphrase/run
== "My favorite language is predicate calculus."
>> randphrase/run
== "I like you."
>> randphrase/run
== "I hate bugs."
>> randphrase/run
== "I like coffee."
>> randphrase/run
== "I hate bugs."
>> randphrase/run
== "Your favorite color is mauve."
>> randphrase/run
== "Your favorite language is REBOL." 8<-------------------------------------------------------- -- ; sub REBOL {}; sub head ($) {@_[0]} REBOL [] # despam: func [e] [replace replace/all e ":" "." "#" "@"] ; sub despam {my ($e) = @_; $e =~ tr/:#/.@/; return "\n$e"} print head reverse despam "moc:xedef#yleen:leoj" ;