Skip to content

Instantly share code, notes, and snippets.

@draegtun
Last active December 16, 2015 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save draegtun/5465881 to your computer and use it in GitHub Desktop.
Save draegtun/5465881 to your computer and use it in GitHub Desktop.
Rebol [
see-gist: https://gist.github.com/miyagawa/5455942
also-this: https://gist.github.com/shanselman/5422230#comment-823247
comment: "My fledgling Rebol port of this Perl code"
requires: "Rebol/View - for https:// port"
github-support: "Thank you Austin@Github for (initiating) the fix for Rebol syntax highlighting"
]
split-string: func [text delim /local s coll] [
coll: copy []
parse/all text [
some [copy s [to delim | to end] (append coll s) delim]
]
coll
]
pick-random: func [from-series] [
random/seed now ; only needs to be done once per script but here so not forgotten!
pick from-series random length? from-series
]
spam-text: read https://gist.github.com/shanselman/5422230/raw/9863d88bde2f9dcf6b2e7a284dd4a428afdc8
samples: split-string spam-text "|^/"
template: pick-random samples
; below replaces {placeholders} within the input stream (template)
parse/all template [
any [
thru "{" begin: copy s to "}" ending:
(
begin: back begin ; move back to include {
ending: next ending ; move forward to include }
text: split-string s "|"
move-mark: change/part begin pick-random text ending
)
:move-mark ; moved the mark to end of change
]
]
print template
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment