Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;
- ;; Conversations
- ;;
- (define *conversations-hash-table* (make-hash-table))
- (define *conversations-cc-hash-table* (make-hash-table))
- (define (make-ask nick c)
- (lambda msg
- (call-with-current-continuation
- (lambda (k)
- (apply printf msg)
- (hash-table-set! *conversations-cc-hash-table* nick k)
- (c #t)))))
- ; Start a conversation
- ; TODO pass input to first part of conversation
- (define (--> nick tag)
- (if (hash-table-exists? *conversations-hash-table* tag)
- (call-with-current-continuation
- (lambda (k)
- ((cadr (hash-table-ref *conversations-hash-table* tag)) (make-ask nick k))
- (hash-table-delete! *conversations-cc-hash-table* nick)))
- (printf "~aNo such conversation.~n" (color 'RED))))
- ; Continue a conversation if one exists
- (define (-> nick input)
- (let ((c (hash-table-ref/default *conversations-cc-hash-table* nick #f)))
- (when c
- (c input))))
- ; Used to define a @conversation
- (define (conversation tag desc proc)
- (hash-table-set! *conversations-hash-table* tag (list desc proc)))
- (conversation 'tell "Leave messages for others in a channel."
- (lambda (ask)
- (let ((who (ask "Who would you like to leave a message for?~n"))
- (message (ask "What would you like to say?~n")))
- (printf "I will tell ~a => ~a~n" who message))))
Add Comment
Please, Sign In to add comment