Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use namespaced keywords with records ?

Tags:

clojure

In my app I need an optimization booster. I noticed that records are significantly faster than maps (probably because record' fields are accessed with native class field access by the JVM)

The map I'm replacing used namespaced keywords as keys

(def m {:app.core/k 1 })

I'm replacing the definition with

(defrecord R [k])
(def m (->R 1))

Code is

(defn two [m] (assoc m :app.core/k 2))

Unfortunately, running this code when m is a record, it assoc a new namespaced key :app.core/k that won't benefit optimization.

Is it possible to declare the record such that it will use namespaced keyword ?

like image 951
Demeter Purjon Avatar asked Oct 25 '25 04:10

Demeter Purjon


1 Answers

There is no such a possibility for this, at least as I know. Only non-qualified names for deftype/defrecord declarations are allowed.

I'm not sure if it will help, but still: you may declare instances of typed records using the standard # reader macro prepending any map. So probably you could get rid of the most of constructor functions:

(def m #some.ns.YourRecord {:foo 1 :bar 2 :baz 3})
like image 132
Ivan Grishaev Avatar answered Oct 28 '25 02:10

Ivan Grishaev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!