Skip to content

Instantly share code, notes, and snippets.

@shaunagm
Created February 16, 2021 22:15
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 shaunagm/39c796dcb51666d0fa7848bb79eb2000 to your computer and use it in GitHub Desktop.
Save shaunagm/39c796dcb51666d0fa7848bb79eb2000 to your computer and use it in GitHub Desktop.
Madlibs Iteration 4
#lang racket
(define cat-story (list
"There once was a cat named ~a who lived in ~a"
"Name: "
"Location: "))
(define pirate-story (list
"A pirate named ~a roamed the high seas of ~a in ~a ship. It was a ~a day when suddenly there came ~a from a distance."
"Name: "
"Location: "
"Pronoun: "
"Adjective: "
"Noun: "))
(define (run-prompt prompt)
(display prompt)
(read-line))
(define (print-story template answers)
(apply printf template answers))
(define (tell-story story)
(print-story
(first story)
(for/list ([prompt (rest story)])
(run-prompt prompt))
)
)
(tell-story cat-story)
(tell-story pirate-story)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment