Hello!
So here is a short example:
-----------------------------------------------------------------------------------------------------------------
;; Story:
;; I have an EDN data structure from an external API
;; I extract several patterns of records from it.
;; I would like to treat the patterns as data, pass them around, modify
them etc.
(def sample-data {:tracks {:items [1 2 3 4 5]}})
(def pattern [:tracks :items count])
;; Thread first -> should be what I need, but I need to "apply" it...
(apply -> (cons sample-data pattern)) ;; Can't take value of a macro:
#'clojure.core/->
;; So make a new macro that reuses ->
(defmacro get->> [data pattern]
`(-> ~data ~@pattern))
;; This raises an error
(macroexpand-1 '(get->> sample-data pattern))
;; Don't know how to create ISeq from: clojure.lang.Symbol
;; But this works correctly
(macroexpand-1 '(get->> sample-data [:tracks :items count]))
;; As does
(get->> sample-data [:tracks :items count]) ; => 5
-----------------------------------------------------------------------------------------------------------------
I understand why the macro cannot be applied, as macros are expanded at
compile time
and are therefor "invisible" to functions.
Could anyone explain why get->> doesn't work? And why does it work with
literal data,
but not with a var?
Thank you!
Jordan
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.