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

Last change on this file since 26734 was 26734, checked in by Moritz Heidkamp, 9 years ago

clojurian: document clojurian-syntax, not clojure-syntax (thanks David Krentzlin for pointing this out)

File size: 3.7 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 {{clojurian-syntax}}.
11
12=== Modules
13
14==== clojurian-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==== Source
99
100The [[https://bitbucket.org/DerGuteMoritz/clojurian|source code is
101hosted at Bitbucket]]. Feel free to fork it and send pull requests
102there.
103
104==== Authors
105
106[[/users/moritz-heidkamp|Moritz Heidkamp]]
107
108Original {{doto}} implementation by Martin DeMello
109
110==== Version history
111
112; 0.0.1 : Initial release
113
114==== License
115
116
117  Copyright (c) 2012, Moritz Heidkamp
118  All rights reserved.
119 
120  Redistribution and use in source and binary forms, with or without
121  modification, are permitted provided that the following conditions are
122  met:
123 
124  Redistributions of source code must retain the above copyright
125  notice, this list of conditions and the following disclaimer.
126 
127  Redistributions in binary form must reproduce the above copyright
128  notice, this list of conditions and the following disclaimer in the
129  documentation and/or other materials provided with the distribution.
130 
131  Neither the name of the author nor the names of its contributors may
132  be used to endorse or promote products derived from this software
133  without specific prior written permission.
134 
135  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
136  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
137  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
138  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
139  COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
140  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
141  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
142  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
143  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
144  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
145  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
146  OF THE POSSIBILITY OF SUCH DAMAGE.
147
Note: See TracBrowser for help on using the repository browser.