-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
60 lines (42 loc) · 1.82 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Suppport for pattern matching in Clojure.
== Installation
- The project uses Leiningen to manage the build.
- The project is published at Clojars
To build from source, after installing leiningen execute:
$lein deps
$lein compile-java
$lein compile
$lein jar
== Use
There are two main macros for pattern matching: 'match' and 'case'.
The macro 'match' accepts a pattern a value and an action, matches the pattern against the value,
extracts the component values and executes the action form:
;; (tuples/match pattern value action)
>(clj-tuples/match (a b (c d) e) (1 2 (3 4) 5) (+ b e))
7
The macro 'case' does pattern matching of several patterns and actions agains a single value:
;; (tuples/case value (pattern1 action1) (pattern2 action2) ... (patternn actionn))
>(def *test* '(:ok 2))
>(clj-tuples/case *test*
(s 1) (do (println (str "the state is not ok: " s)) s)
(s 2) (do (println (str "the state is ok: " s)) s)
t (println (str "unknown value")))
the state is ok: :ok
:ok
You can use symbols starting with '_' for the parts of the value you are not interested:
(clj-tuples/match (_ _ x) (1 2 3) x)
>3
(clj-tuples/match (_a _b x) (1 2 3) x)
>3
== Tests
There are some tests included in the project. You can run them using Leiningen:
$lein test
== Changelog
- version 0.1 (09/28/2009): First version.
- version 0.2 (09/29/2009): Added support for matching vectors.
- version 0.3 (09/29/2009): Initial support for matching maps.
- version 0.3.1 (10/02/2009): Fixed error in exception handling. Now errors not involving
pattern matching are not cought.
-version 0.3.2 (10/05/2009): Fixed error with comparing patterns consisting of lists with
different number of elements.
-version 0.3.3 (12/08/2009): Packaged for leiningen.