This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-04
Channels
- # announcements (1)
- # architecture (18)
- # aws (7)
- # babashka (63)
- # beginners (38)
- # bristol-clojurians (1)
- # circleci (1)
- # clj-kondo (10)
- # clojars (4)
- # clojure (159)
- # clojure-berlin (3)
- # clojure-europe (4)
- # clojure-italy (7)
- # clojure-losangeles (6)
- # clojure-nl (7)
- # clojure-spec (3)
- # clojure-uk (109)
- # clojurescript (54)
- # css (1)
- # cursive (38)
- # data-science (2)
- # datascript (3)
- # datomic (14)
- # docker (2)
- # duct (11)
- # fulcro (47)
- # jobs (8)
- # jobs-discuss (3)
- # kaocha (4)
- # malli (3)
- # nyc (2)
- # off-topic (30)
- # overtone (3)
- # re-frame (17)
- # reagent (33)
- # shadow-cljs (29)
- # spacemacs (3)
- # specter (4)
- # tools-deps (13)
- # xtdb (13)
Is it possible to write a macro that returns the qualified name of a symbol passed as parameter? Example:
(my-macro foo)
; => this-ns/foo
(my-macro other-ns/foo)
; => other-ns/foo
macros don't implicitly namespace symbols, but the ` reader-macro does
but it doesn't apply to your args
hm .. so I guess that I have to (in the macro) manually append the current ns to the symbol’s name when it is unqualified.
also "current ns" in a macro can be counterintuitive
Yeah, is it the namespace where the macro is defined, or where it is invoked?
And out of curiosity, what problem are you trying to solve?
It’s a little difficult to explain ..
It’s related to the defc
macro in https://github.com/green-coder/vrac
I would like to refer to external functions from inside the template as if the template was Clojure syntax.
For example:
(defn sum [a b]
(+ a b))
(defc my-comp [data]
{:id :app/my-comp}
(let [x (:number1 data)
y (:number2 data)]
[:div x " + " y " = " (sum x y)]))
the let
expression is just symbolic data, but I wish to have current-ns/sum
and its value from the symbol sum
you can resolve
in terms of *ns*
- is that sufficient?
I think that would work. Thank you. I will try it tonight. (in 12 hours)
Hey. I am debugging some code with a toplevel def and use something of the following form to try to monitor the changes.
(def ^:dynamic *a* (atom {}))
(add-watch *a* :watcher
(fn [key atom old-state new-state]
(prn "-- Atom Changed --")
(prn "key" key)
(prn "atom" atom)
(prn "old-state" old-state)
(prn "new-state" new-state)))
(reset! *a* {:foo "bar"})
The above works fine in a clean project, but somehow has no effect (nothing printed) in the code I am working on. Is there something I need to be aware of when using add-watch
or any ideas what could be the issue?The repo where it doesn't work is https://github.com/clojure-emacs/cider-nrepl btw
Somethow my add-watch
statement has no effect if I do
(-> *a* .getWatches keys)
I get nil.why put an atom in a dynamic var?
that's weird
@U051SS2EU yes I don't know. haven't written the code myself. Maybe its stayed this way as a legacy. https://github.com/clojure-emacs/cider-nrepl/blob/master/src/cider/nrepl/middleware/debug.clj#L58
No there is some good reason, but I don't know exactly. Without the ^:dynamic
the code fails.
I'm suspicious that the failure could be related to the way the dynamic var is used - it could point to another atom in the code you care about
Hi! Beginner question here, I'm trying to find my way through the options of serializing Clojure objects. I have a small ML model as an instance of a deftype that implements a bunch of protocols. Now that it's trained, I'd like to save it out to disk so that I can use it later on. In Python I'd either use TensorFlow's options to save to disk, or just use Pickle if it's an class I defined myself. I don't seem to find an equivalent to Pickle that works out of the box for custom objects in Clojure though. Am I missing something? A bit more background info: What I'm trying to save out is small neural net, implemented as a NeuralNetworkInference deftype as defined in Dragan Rocks' blogpost: https://dragan.rocks/articles/19/Deep-Learning-in-Clojure-From-Scratch-to-GPU-12-A-Simple-Neural-Network-Training-API. So it's basically a bunch of Neanderthal matrices and some function definitions wrapped in an interface. Thanks! 🙂
@frederikdieleman You do not need to serialize functions etc, just data - your weight and bias matrices. Until I provide an out-of-the-box solution for that (in Deep Diamond) please see what Kamil Toman provided as a DIY solution https://github.com/katox/neanderthal-stick
Neanderthal-stick doesn't seem to be on clojars, so had to clone it. In the end it did turn out to be the easiest solution. Worked great, only thing I still needed to add was a way to serialize the type of activation function each layer has. On a sidenote: I didn't find the repo of the code you created in the "Deep Learning from Scratch to GPU" series and hence don't know what kind of licence you've put on it. Is it ok if I use it in a repo of mine? (with mention of source of course)
@frederikdieleman java comes with serialization, but for clojure data you can use transit
and extend it for native types as needed
transit will pick up the custom data readers / writers for any defrecord / deftype
this is an example of using java's built in serialization, fwiw - I agree that it has serious problems
(import ( FileOutputStream
FileInputStream
ObjectOutputStream
ObjectInputStream
IOException))
(require '[ :as io])
(defn to-file
[file-name & data]
(with-open [file (FileOutputStream. file-name)
stream (ObjectOutputStream. file)]
(doseq [d data]
(.writeObject stream d))))
(defn from-file
[file-name]
(with-open [file (FileInputStream. file-name)
stream (ObjectInputStream. file)]
(into []
(take-while (complement #{::done}))
(repeatedly
#(try
(.readObject stream)
(catch IOException _ ::done))))))
I think the problems with java serialization are less severe with clojure (especially if you commit to reading and writing from the same clojure version) but transit is still more compact and it's human readable
Thanks for the help! In any case it's just for short-term saving of my own ML models, so not too worried about potential risks with it. Unfortunately Neanderthal matrices are not serializable, so will have a look at one of the other options.
the obvious workaround would be to convert neanderthal matrices into a tag plus an array of arrays (that should serialize very efficiently...) - but I'm sure it's even simpler in a proper clojure serialization lib
it works out of the box with all Clojure standard types AFAIK, and serialises to bytes
As a Clojure beginner, I just discover condp
and wow ! 😮
I updated my "Perfect number" exercism and now it's more concise than cond
https://exercism.io/tracks/clojure/exercises/perfect-numbers/solutions/4e1654ede3b945518f1e0a4b0d18b0cf