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

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

clojurian: slightly change documentation structure and mention Martin DeMello? as the original author of `doto'

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