Created
February 16, 2021 23:45
-
-
Save shaunagm/5652df9c069dd90fff6dead5497b2045 to your computer and use it in GitHub Desktop.
Madlibs iteration 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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