Salut Laurent,

that's a good remark. Collecting and exporting of constants were conflated 
in the previous version. So I added another API call: exported-constants. 
Usually this are just the ones collected from the child nodes. But for ::fn 
it's always empty.

; From your other mail
(defn processor
  [pre post]
  (fn this [form]
    (let [form (pre form)
          form (maybe recursive? update-children form this)]
      (post form))))

(defmulti exported-constants :op)

(defmethod exported-constants :default
  [form]
  (:constants form))

(defmethod exported-constants ::fn
  [_]
  #{})

(defmulti collect-constants :op)

(defmethod collect-constants :default
  [form]
  form)

(defmethod collect-constants ::constant
  [form]
  (assoc form :constants #{(:form form)}))

(defmethod collect-constants ::recursive
  [{:as form :keys [children]}]
  (->> children
    (map exported-constants)
    (reduce into #{})
    (assoc form :constants)))

((processor set-unbox collect-constants) {:op ::fn :children [{:op ::let 
:children [{:op ::constant :form 1} {:op ::fn :children [{:op ::constant 
:form 2}]}]}]})
; => {:constants #{1}, :op :user/fn, :children ({:constants #{1}, :unbox 
false, :op :user/let, :children ({:constants #{1}, :unbox true, :op 
:user/constant, :form 1} {:constants #{2}, :unbox true, :op :user/fn, 
:children ({:constants #{2}, :unbox true, :op :user/constant, :form 2})})})}

Note how the nested ::fn collects constants from its children but doesn't 
export it to its parent without the need of a filter on parent level.

Never ask such things on the list; a discussion about simplified examples 
may arise. ;) But hopefully the discussion is helpful for Aaron in his 
endeavour.

Meikel

-- 
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

Reply via email to