You are looking at historical revision 25974 of this page. It may differ significantly from its current revision.
A collection of modules providing syntax and utility functions inspired by Clojure.
Currently the only module provided by this egg is clojure-syntax.
clojure-syntax[syntax] (doto val (proc args ...) ...)
Inserts val as the first argument of each (proc args ...) clause (i.e. right after proc). Returns val. This is useful e.g. for mutating a record on initialization.
(define boolean-vector (doto (make-vector 100) (vector-fill! #t 0 50) (vector-fill! #f 50))) => (define boolean-vector (let ((vec (make-vector 100))) (vector-fill! vec #t 0 50) (vector-fill! vec #f 50) vec))[syntax] (-> val (proc args ...) ...)
[syntax] (->* val (proc args ...) ...)
Inserts val as the first argument of the first (proc args ...) clause. The resulting form is then inserted as the first argument of the following proc form and so on. This is known as the thrush combinator. The starred version (->*) is multi value aware, i.e. each form's return values are spliced into the argument list of the successing form.
Single value example:
(-> 10 (- 2) (/ 5) (* 3)) => (* (/ (- 10 2) 5) 3)
Multi value example:
(->* (values 1 2) (list)) => (receive args (values 1 2) (apply list args))[syntax] (->> val (proc args ...) ...)
[syntax] (->>* val (proc args ...) ...)
Works just like -> and ->* only that the forms are inserted at the end of each successive clause's argument list.
(->> (iota 10) (map add1) (fold + 0) (print)) => (print (fold + 0 (map add1 (iota 10))))
About this egg
The source code is hosted at Bitbucket. Feel free to fork it and send pull requests there.
Original doto implementation by Martin DeMello
- Initial release
Copyright (c) 2012, Moritz Heidkamp All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.