This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-13
Channels
- # beginners (202)
- # boot (7)
- # cider (14)
- # clara (2)
- # cljs-dev (7)
- # clojure (56)
- # clojure-italy (9)
- # clojure-spec (6)
- # clojure-uk (12)
- # clojurescript (40)
- # core-async (3)
- # datomic (6)
- # duct (1)
- # editors (10)
- # emacs (5)
- # fulcro (24)
- # off-topic (16)
- # onyx (4)
- # pedestal (1)
- # planck (8)
- # portkey (2)
- # re-frame (31)
- # reagent (23)
- # tools-deps (8)
- # vim (3)
Hi All, I’m having a problem related to trying to load/require/compile clojure from clojure that I feel like probably is possible, yet I am doing something slightly wrong to get it working
ive written a tool that takes an interface definition language, and compiles it to clojure
what I would like is to have a unit-test in the tool that runs the code generator, compiles the result, and then runs tests against some of the symbols in the compiled code
ive tried all variants of load-file/load-string, requires :reload, and compile I can think of
in some forms, I think I am pretty close, but I can never seem to subsequently reference what was compiled and I dont understand why
in case it helps, here is a sample of one of the approaches I tried: https://gist.github.com/ghaskins/57245da53b66b0ede4b1f745a17015e6
e.g.
(pprint (ns-publics 'com.example.tutorial.sample))
returns a sane list of symbols from the expected namespace@ghaskins Are you getting an error like: "... java.lang.ClassNotFoundException: com.example.tutorial.sample ..." ?
Yep! Or variants of that. And everything does work if I (ns-resolve) as you suggested. I can probably work with this if necessary, but I would like to try to get the symbols in a way that they can be used naturally if at all possible.
@U0CMVHBL2 I figured out the magic….if I put the logic to generate/compile/require outside of the deftest form, it all works fine
You are welcome
Something to be cautious about -- when you use clojure.test / deftest, and run tests, the order that different deftests run relative to each other is not easily predictable. It is probably some kind of order determined by hashing their names or something equally difficult to predict.
I do not know what guarantees the implementation may have about running other top level forms before the contents of the test code inside of deftest's.
If so, I believe the reason why is because doing the require followed by trying to use the newly required namespace in a symbol inside of a larger top level form (here 'deftest'), the Clojure compiler is trying to read, then compile, that entire top level form, and the require isn't actually done until after reading the entire top level form is complete. Someone will correct me if I've messed up the precise reason there.
If you use (ns-resolve 'com.example.tutorial.sample 'pb->AddressBook) it should return the var, which is as if you had successfully written #'com.example.tutorial.sample/pb->AddressBook. You can use @ or deref on the (ns-resolve ...) expression to get the value of the var.
@benzap If you replace the let statement you tried with (let [x (var foo)] (meta x))
it will get the same metadata as (meta (var foo))
.
ok, so I’ve got a code base with some hard coded values/thresholds etc. I want to make these things options. what’s everyone’s favourite way of handling config?
I like to make it the first because then it’s easy to use partial
to create pre-configed versions
that’s what I was thinking… just means I really do have need to partial them before I can use them cleanly with update
or swap!
etc…
Ok another question… If I want to use namespaced keys in my map when destructuring is their an equivalent to ::
in the :keys
list I want to unpack?
Thanks for yesterdays discussion @leonoel @andrebras @manutter51 @joelsanchez @matt220 @the2bears @sveri @sundarj
I don't think I need that value https://github.com/technomancy/leiningen/commit/e04f1bee9bc7cdfb419b6b188a10e2076d6867eb I have dymanic shared lib files in native, and I need to ensure that the directory is copied from target when useing the library, as the lib files have relative RPATH's from the root directory.
is there a clojure email (javamail) interface that doesn't require i write attachments to disk? i'd like to attach from streams
The docstring i'm trying to get is in a (fn []) which is a value within a map. If i'm not mistaken, this is not a var in any sense of the word. However, if I make a temporary var, is it possible to bind this (fn []) temporarily using set!
, and retrieve the (fn []) metadata?
So the only way to really preserve the foo
meta data is to store it off to the side explicitly, since there is no way to access the (fn []) metadata after it's use in the map
@benzap When defn occurs, it creates a metadata map and puts it on the var being defn'd. It doesn't put metadata on the function value itself.
Judging by what I want, i'm likely going to develop a separate collection to store metadata on key values. I suppose it's similar to how clojure.spec would store spec data
I’m writing a deftype
for a transient that wraps a map, I’m using ^:unsynchronized-mutable ^ITransientMap m
for the backing map, and mutating it with (set! m (.assoc m k v))
but I’m wondering if there are faster options?
Faster for doing what? What read / write operations in what concurrency scenarios?
The map is backing a kv index, the goal is to speed up adding entries but lookup is also required
why not use one of the built in hash-map types?
(by which I mean, the ones provided by the jvm)