Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #59799 > unrolled thread
| Started by | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| First post | 2017-05-25 04:34 +0000 |
| Last post | 2017-05-24 22:49 -0700 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.forth
Rosetta: Mad Libs "Robert L." <No_spamming@noWhere_7073.org> - 2017-05-25 04:34 +0000
Re: Rosetta: Mad Libs Julian Fondren <julian.fondren@gmail.com> - 2017-05-24 22:49 -0700
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Date | 2017-05-25 04:34 +0000 |
| Subject | Rosetta: Mad Libs |
| Message-ID | <og5msg$1e1e$1@gioia.aioe.org> |
> Then, find each replacement to be made within the story, ask
> the user for a word to replace it with, and make all the
> replacements.
>
> Stop when there are none left and print the final story.
>
> The input should be an arbitrary story in the form:
>
> <name> went for a walk in the park. <he or she>
> found a <noun>. <name> decided to take it home.
>
> Given this example, it should then ask for a name, a he or she
> and a noun (<name> gets replaced both times with the same
> value).
def mad_lib(template)
blanks = template.scan(/<.*?>/).uniq
puts "The template is:", template
story = template
blanks.each{|s|
print "Supply replacement for #{s}: "
story.gsub!(s, gets.strip)
}
puts ; puts "The story is:", story
end
mad_lib "<name> went for a walk in the park. <he or she>
found a <noun>. <name> decided to take it home."
===>
The template is:
<name> went for a walk in the park. <he or she>
found a <noun>. <name> decided to take it home.
Supply replacement for <name>: Hansel
Supply replacement for <he or she>: He
Supply replacement for <noun>: toad
The story is:
Hansel went for a walk in the park. He
found a toad. Hansel decided to take it home.
In Forth?
--
Much of what I'll be talking about today is taken from that excellent essay,
which includes incontrovertible mathematical and statistical proof that violent
crime bears a close, nearly direct, relationship to the presence of Blacks and
Mestizos in our midst.
nationalvanguard.org/2014/02/american-dissident-voices-america-race-and-violent-crime/
[toc] | [next] | [standalone]
| From | Julian Fondren <julian.fondren@gmail.com> |
|---|---|
| Date | 2017-05-24 22:49 -0700 |
| Message-ID | <d42d9c11-6f03-481d-9221-46ad1a23f3ad@googlegroups.com> |
| In reply to | #59799 |
On Wednesday, May 24, 2017 at 11:34:27 PM UTC-5, Robert L. wrote:
> def mad_lib(template)
> blanks = template.scan(/<.*?>/).uniq
> puts "The template is:", template
> story = template
> blanks.each{|s|
> print "Supply replacement for #{s}: "
> story.gsub!(s, gets.strip)
> }
> puts ; puts "The story is:", story
> end
>
> mad_lib "<name> went for a walk in the park. <he or she>
> found a <noun>. <name> decided to take it home."
>
> ===>
> The template is:
> <name> went for a walk in the park. <he or she>
> found a <noun>. <name> decided to take it home.
> Supply replacement for <name>: Hansel
> Supply replacement for <he or she>: He
> Supply replacement for <noun>: toad
>
> The story is:
> Hansel went for a walk in the park. He
> found a toad. Hansel decided to take it home.
>
> In Forth?
Something like this:
wordlist constant madlibs
: $$ ( c-addr u -- )
cr ." Supply replacement for " type ." : " here 80 accept allot ;
: mad ( -- )
here get-current madlibs set-current
begin ( a wid )
begin parse-name dup 0= while
2drop 10 c, refill 0= abort" input exhausted"
repeat
2dup madlibs search-wordlist if execute else
over c@ [char] $ = if $$ else
here swap dup allot move
then bl c,
then
again ;
get-current madlibs set-current
: libs ( a wid c-addr u -- )
2drop set-current
here over - type quit ;
: . ( c-addr u -- )
-1 allot here swap dup allot move bl c, ;
set-current
mad
$name went for a walk in the park. $he
found a $noun . $name decided to take it home.
libs
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web