diff options
author | rekado <rekado@elephly.net> | 2014-12-11 20:48:13 +0100 |
---|---|---|
committer | rekado <rekado@elephly.net> | 2014-12-11 20:48:13 +0100 |
commit | 58dd0d498899e4f6d5ae2a67504bce620c20c823 (patch) | |
tree | d1a889f69ff9ef4aa210c1c17ccda3f5b44fa195 | |
parent | b2d20af884f494fc5178659663ff7d52046fe179 (diff) |
convert register-stanza-handler to syntax
allow omitting guard expression.
-rw-r--r-- | xmpp.scm | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -20,10 +20,17 @@ (define *stanza-handlers* '()) (define *stanza-id-handlers* (make-hash-table)) -(define (register-stanza-handler predicate handler) - "Register handler function that will be executed when a stanza is +(define-syntax register-stanza-handler + (lambda (s) + "Register handler function that will be executed when a stanza is encountered that matches the given predicate." - (set! *stanza-handlers* (cons `(,predicate . ,handler) *stanza-handlers*))) + (syntax-case s () + ((_ guard handler) + (if (eqv? #t (syntax->datum #'guard)) + #'(set! *stanza-handlers* (cons `(,(lambda _ #t) . ,handler) *stanza-handlers*)) + #'(set! *stanza-handlers* (cons `(,guard . ,handler) *stanza-handlers*)))) + ((_ handler) + #'(set! *stanza-handlers* (cons `(,(lambda _ #t) . ,handler) *stanza-handlers*)))))) (define (register-temp-stanza-handler-for-id stanza-id handler) "Register handler function that will be executed when a stanza with |