I am very stupid and I am having trouble figuring out how to read
this:

(defmacro match-func [& body] `(fn [~'x] (match [~'x] ~@body)))

((match-func [q :guard even?] (+ 1 q) [z] (* 7 z)) 33)
;; 231

What? Why 231?

The article is here:

http://java.dzone.com/articles/my-first-clojure-macro

I especially struggle with the longer version:

(defmacro match-pfunc [& body]
"Create a partial function that does pattern matching."
(let [rewrite (mapcat (fn [x] [(first x) true]) (partition 2 body))]
`(fn ([x#] (match [x#] ~@body))
([x# y#]
(cond
(= :defined? x#)
(match [y#] ~@rewrite)
(= :body x#)
'(~@body))))))


The article says:

What this gives us is a function than can be invoked with a single
parameter:
(pf 44)
And it can be invoked with 2 parameters:
(pf :defined? 44)


I keep looking at these 2 lines thinking maybe they reveal how
different parameters cause a different action to be triggered, but I
am unable to make sense of it:

`(fn ([x#] (match [x#] ~@body))
([x# y#]

The anonymous fn is simply being returned? Is it returned at compile
time, or run time?



-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to