k-combinator over and over again pasted by certainty on Thu May 31 18:24:21 2012
(define-syntax returning (syntax-rules (=>) ((_ expr => binding body ...) (let ((binding expr)) body ... binding)) ((_ expr body ...) (let ((tmp expr)) body ... tmp)))) (returning (vector 1 2 3) => vec (vector-set! vec 0 100) (print "I set the vector")) (returning (list 1 2 3) (print "I return a list"))
mw-k-combinator pasted by certainty on Thu May 31 18:46:52 2012
(define-syntax returning (syntax-rules () ((_ expr) expr) ((_ ((binding expr) ...) body ...) (let ((binding expr) ...) body ... (values binding ...))) ((_ (binding more-bindings ...) expr body ...) (receive (binding more-bindings ...) expr body ... (values binding more-bindings ...))))) ;; examples (returning (vector 1 2 3)) (returning (foo) (list 1 2)) (returning ((foo (list 1 2)) (bar (vector 1 2))) (print "Some vector and a list walk into a bar")) (returning (foo bar) (values 1 2) (print "I can have multiple values"))
k-combinator in action pasted by certainty on Thu May 31 18:52:45 2012
(define (make-server-socket type uri #!key (socket-options '((hwm . 2))))
(returning (socket) (make-socket type)
(socket-set-options-from-alist! socket socket-options)
(bind-socket socket uri)))using doto added by DerGuteMoritz on Thu May 31 18:59:44 2012
(define (make-server-socket type uri #!key (socket-options '((hwm . 2))))
(doto (make-socket type)
(socket-set-options-from-alist! socket-options)
(bind-socket uri)))