Pattern matching on records in Clojure -


is supported right now? information find example wiki (https://github.com/clojure/core.match/wiki/deftype-and-defrecord-matching) produces error:

compilerexception java.lang.assertionerror: invalid list syntax (red. (red. x b) y c) in (black. (red. (red. x b) y c) z d). valid syntax: [[:default :guard] [:or :default] [:default :only] [:default :seq] [:default :when] [:default :as] [:default :<<] [:default :clojure.core.match/vector]]

this has not been implemented yet, since records behave maps can do:

(defrecord ab [a b]) user.ab user> (let [x (->ab 1 1)]   (match [x]     [{:a _ :b 2}] :a0     [{:a 1 :b 1}] :a1     [{:c 3 :d _ :e 4}] :a2     :else nil)) :a1 

you can match on type of record, bit inelegant.

user> (let [x (->ab 1 1)             aba user.ab]   (match [(type x) x]     [aba {:a _ :b 2}] :a0     [aba {:a 1 :b 1}] :a1     [aba {:c 3 :d _ :e 4}] :a2     :else nil))   :a1 

https://github.com/clojure/core.match/wiki/basic-usage#map-patterns


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -