blob: b201844e38c579887b291dd4fff9ad4af83837f6 (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
(define-module (gnubba sugar)
#:use-module ((sxml simple) #:select (sxml->xml))
#:export (xmpp->))
;; Simple syntax for XMPP "discussions".
;; TODO: can this become an actual monad? Would it be worth the
;; effort?
(define-syntax xmpp->
(lambda (x)
(syntax-case x (<-)
;; send and forget stanza
((_ sock (<- stanza) exp ...)
#'(begin
(sxml->xml stanza sock)
(xmpp-> sock exp ...)))
;; send stanza and pass response to next expression
((_ sock (res <- stanza) exp ...)
#'(let ((s stanza))
(begin
(register-temp-stanza-handler-for-id
(stanza-id s)
(lambda (res)
(xmpp-> sock exp ...)))
(sxml->xml s sock))))
;; unwrap single expression
((_ sock exp)
#'exp)
;; simply evaluate expression and move on to match next expression
((_ sock exp exp* ...)
#'(begin
exp
(xmpp-> sock exp* ...))))))
;; EXAMPLE
;; (xmpp-> (current-output-port)
;; (res <- (iq "hello"))
;; (display res)
;; (display "something else")
;; (<- (message "mama@localhost" "hello, there"))
;; (display "we ignore a response to this message"))
|