Skip to content

Instantly share code, notes, and snippets.

@shaunagm
Created February 16, 2021 23:45
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/5652df9c069dd90fff6dead5497b2045 to your computer and use it in GitHub Desktop.
Save shaunagm/5652df9c069dd90fff6dead5497b2045 to your computer and use it in GitHub Desktop.
Madlibs iteration 7
#lang at-exp racket
(define tree-prompts
(make-hash (list (cons `treetype (list "Type of thing: " null)) (cons `location (list "Location: " null)))))
(define tree-template (list "There once was a big " `treetype " tree in the " `treetype " old forest of " `location "."))
(define (run-prompt sym prompts)
(define prompt-info (hash-ref prompts sym null))
(if (null? (second prompt-info))
(begin (display (first prompt-info))
(hash-set! prompts sym (list (first prompt-info) (read-line))))
null)
(second (hash-ref prompts sym null)))
(define (tell-story template prompts)
(string-join
(map (lambda (i)
(if (string? i) i (run-prompt i prompts))
)
template) ""))
(tell-story tree-template tree-prompts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment