Guest User

Untitled

a guest
Apr 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.33 KB | None | 0 0
  1. ;;
  2. ;; Conversations
  3. ;;
  4.  
  5. (define *conversations-hash-table* (make-hash-table))
  6. (define *conversations-cc-hash-table* (make-hash-table))
  7.  
  8. (define (make-ask nick c)
  9.   (lambda msg
  10.     (call-with-current-continuation
  11.       (lambda (k)
  12.         (apply printf msg)
  13.         (hash-table-set! *conversations-cc-hash-table* nick k)
  14.         (c #t)))))
  15.  
  16. ; Start a conversation
  17. ; TODO pass input to first part of conversation
  18. (define (--> nick tag)
  19.   (if (hash-table-exists? *conversations-hash-table* tag)
  20.     (call-with-current-continuation
  21.       (lambda (k)
  22.         ((cadr (hash-table-ref *conversations-hash-table* tag)) (make-ask nick k))
  23.         (hash-table-delete! *conversations-cc-hash-table* nick)))
  24.     (printf "~aNo such conversation.~n" (color 'RED))))
  25.  
  26. ; Continue a conversation if one exists
  27. (define (-> nick input)
  28.   (let ((c (hash-table-ref/default *conversations-cc-hash-table* nick #f)))
  29.     (when c
  30.       (c input))))
  31.  
  32. ; Used to define a @conversation
  33. (define (conversation tag desc proc)
  34.   (hash-table-set! *conversations-hash-table* tag (list desc proc)))
  35.  
  36. (conversation 'tell "Leave messages for others in a channel."
  37.   (lambda (ask)
  38.     (let ((who (ask "Who would you like to leave a message for?~n"))
  39.           (message (ask "What would you like to say?~n")))
  40.       (printf "I will tell ~a => ~a~n" who message))))
Add Comment
Please, Sign In to add comment