source: project/wiki/eggref/4/clojurian @ 25961

Last change on this file since 25961 was 25961, checked in by Moritz Heidkamp, 8 years ago

clojurian: add documentation

File size: 3.4 KB
Line 
1[[tags: egg]]
2== clojurian
3
4A collection of modules providing syntax and utility functions
5inspired by [[http://clojure.com|Clojure]].
6
7[[toc:]]
8=== Overview
9
10Currently the only module provided by this egg is {{clojure-syntax}}.
11
12=== clojure-syntax
13
14<syntax>(doto val (proc args ...) ...)</syntax>
15
16Inserts {{val}} as the first argument of each {{(proc args ...)}}
17clause (i.e. right after {{proc}}). Returns {{val}}. This is useful
18e.g. for mutating a record on initialization.
19
20Example:
21
22<enscript highlight="scheme">
23(define boolean-vector
24  (doto (make-vector 100)
25        (vector-fill! #t 0 50)
26        (vector-fill! #f 50)))
27=>
28
29(define boolean-vector
30  (let ((vec (make-vector 100)))
31    (vector-fill! vec #t 0 50)
32    (vector-fill! vec #f 50)
33    vec))
34</enscript>
35
36
37
38<syntax>(-> val (proc args ...) ...)</syntax>
39<syntax>(->* val (proc args ...) ...)</syntax>
40
41Inserts {{val}} as the first argument of the first {{(proc args ...)}}
42clause. The resulting form is then inserted as the first argument of
43the following {{proc}} form and so on. This is known as the ''thrush
44combinator''. The starred version ({{->*}}) is multi value aware,
45i.e. each form's return values are spliced into the argument list of
46the successing form.
47
48Single value example:
49
50<enscript highlight="scheme">
51
52(-> 10 (- 2) (/ 5) (* 3))
53
54=>
55
56(* (/ (- 10 2) 5) 3)
57</enscript>
58
59Multi value example:
60
61<enscript highlight="scheme">
62
63(->* (values 1 2) (list))
64
65=>
66
67(receive args (values 1 2) (apply list args))
68</enscript>
69
70
71<syntax>(->> val (proc args ...) ...)</syntax>
72<syntax>(->>* val (proc args ...) ...)</syntax>
73
74Works just like {{->}} and {{->*}} only that the forms are inserted at
75the end of each successive clause's argument list.
76
77Example:
78
79<enscript highlight="scheme">
80(->> (iota 10)
81     (map add1)
82     (fold + 0)
83     (print))
84
85=>
86
87(print
88 (fold + 0
89  (map add1
90   (iota 10))))
91</enscript>
92
93
94=== Author
95
96Moritz Heidkamp
97
98=== Version history
99
100; 0.0.1 : Initial release
101
102=== License
103
104
105  Copyright (c) 2010-2011, Moritz Heidkamp
106  All rights reserved.
107 
108  Redistribution and use in source and binary forms, with or without
109  modification, are permitted provided that the following conditions are
110  met:
111 
112  Redistributions of source code must retain the above copyright
113  notice, this list of conditions and the following disclaimer.
114 
115  Redistributions in binary form must reproduce the above copyright
116  notice, this list of conditions and the following disclaimer in the
117  documentation and/or other materials provided with the distribution.
118 
119  Neither the name of the author nor the names of its contributors may
120  be used to endorse or promote products derived from this software
121  without specific prior written permission.
122 
123  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
124  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
125  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
126  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
127  COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
128  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
129  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
130  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
131  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
132  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
133  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
134  OF THE POSSIBILITY OF SUCH DAMAGE.
135
Note: See TracBrowser for help on using the repository browser.