This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-07-10
Channels
- # announcements (3)
- # beginners (67)
- # calva (4)
- # cider (3)
- # clj-kondo (58)
- # cljs-dev (4)
- # clojure (172)
- # clojure-berlin (4)
- # clojure-chicago (8)
- # clojure-europe (4)
- # clojure-greece (8)
- # clojure-italy (12)
- # clojure-nl (4)
- # clojure-spec (7)
- # clojure-uk (77)
- # clojurescript (13)
- # clojutre (16)
- # core-async (10)
- # cursive (3)
- # datomic (29)
- # figwheel-main (27)
- # fulcro (22)
- # garden (3)
- # jobs (2)
- # jobs-discuss (13)
- # juxt (5)
- # leiningen (14)
- # mount (4)
- # off-topic (28)
- # pathom (6)
- # pedestal (8)
- # portland-or (2)
- # re-frame (20)
- # remote-jobs (6)
- # shadow-cljs (13)
- # sql (74)
- # testing (17)
- # tools-deps (1)
- # vim (1)
- # xtdb (1)
@i Boot lets you add dependencies to a running REPL. CLI/`deps.edn` allows that as well, if you use the add-lib
branch of tools.deps
.
I'm not sure if you can do it out of the box with Leiningen...
Hi guys, there is a library or home-made fn that i can merge n collections by ratio? I mean if i have [1 2 3] and [a b] [z x y] and ratios {:first-coll 1 :second-coll 2 :third-coll 3} so the result should look like (or something similar to) [z x y a b 1 2 3]
@bennyk, I can't tell from that example what you need. What do the ratio values mean? What does it mean that :first-coll is 1 and :second-coll is 2? I'm looking for a pattern in the result and my brain is too tired 😅
haha yea sorry for the bad explanation. The function should get N collection and N ratios. It construct 1 new collection. To describe better here is an example: given collection-a: [1 2 3] and collection-b: [a b] and collection-c: [z x y] as input collections, a number Q and {:first-coll 1 :second-coll 2 :third-coll 3} The result collection will contain all the items from the given collections, but ordered like this: construct first Q elements by taking 3 elements from the third collection, 2 from second collection and 1 from third collection. Then construct the next Q items. If for example all the items were already taken from the 2 first collections (collection-a and collection-b) it will just add the items that left from the third collection-c. The end result will look like: [ z x y a b 1 2 3 ]
For [1 2 3] and [a b] [z x y w u v] and ratios {:first-coll 1 :second-coll 2 :third-coll 3} => [ z x y a b 1 w u v 2 3 ]
Hello& I'm playing with Ring and trying to send some edn structures between front and back and the opposite way. I believed in Rich's isomorphysm, but all edn<->json converters/middlewares I tried made me disappointed - i.e. on
{1 1,
"2" "2",
:a :a,
[1 "2" :a] [1 "2" :a],
{1 1, "2" "2", :a :a, [1 "2" :a] [1 "2" :a]}
{1 1, "2" "2", :a :a, [1 "2" :a] [1 "2" :a]}}
in body on back side I got
{
"1": 1,
"2": "2",
"a": "a",
"[1 \"2\" :a]": [
1,
"2",
"a"
],
"{1 1, \"2\" \"2\", :a :a, [1 \"2\" :a] [1 \"2\" :a]}": {
"1": 1,
"2": "2",
"a": "a",
"[1 \"2\" :a]": [
1,
"2",
"a"
]
}
}
on front side - it stringifyes all keywords and all key types! Can a achieve a real 1-to1 convertation anyway? I know, that json have not keywords, but I it can be a convention that any string starts with :
have to convert to keywordI do not have much experience with using it myself, but have you tried Transit? https://github.com/cognitect/transit-clj
it's a data format that works over json, but serializes all clojure data structures preserving their types
Sounds promising, I was ready to write my own custom bicycle, but it seems that there is a reason to look at it first 🙂
For testing needs it was easier for me to make some quick and dirty encoder/decoder for transition edn thru json 🙂
(defn encode-edn [x]
(cond
(keyword? x) (str x)
(map? x) {"map" (map encode-edn x)}
(coll? x) (mapv encode-edn x)
:else x))
(defn decode-edn [x]
(cond
(string? x) (if (str/starts-with? x ":") (keyword (subs x 1)) x)
(map? x) (->> (get x "map") decode-edn (into {}))
(coll? x) (mapv decode-edn x)
:else x))
when making a post from clj-http I am getting an
Unhandled sun.security.provider.certpath.SunCertPathBuilderException unable to find valid certification path to requested target
any suggestions of where to start?
I’ve debugged this in the past with the JVM option -Djavax.net.debug=all
In my case I needed to add the relevant certificates to the JDK Truststore using keytool
Yeah, most likely the server isn't using a trusted certificate. Check with browser or openssl if that's the case. If they say the certificate is valid they might be a mismatch between what Java considers a valid certificate and what browser/OS considers a valid certificate. You may need to import that specific certificate into the java keystore as cichli suggested. In some cases, there might be problems with intermediate certificates.
curl works to the same thing.
@vlaaad thanks, it works nice and I think faster, than construction of temp clojure structures. And I do not need json (with its limitations) anywhere. Seems, that only 2 special points - this string can be readed only with cljs clients (it is not a common json api), and it can not be structured in browser developer tools
Anyone here have much experience with integrant? I posted a q on #integrant but not sure if the channel is in the view of many users.
@bennyk, this is a pretty specialized use-case, so there's no library fn. I'd take the approach of taking each collection, and partition-all by its respective "ratio". (partition-all 3 [1 2 3 4 5 6]) yields ((1 2 3) (4 5 6)). You can then recursively concat the elements of the partitioned collections together.
currently using clojure.shell/sh inside the code to curl it all up, which seems like quite an anti-pattern (and not very production friendly), but resolving cert issues in clojure is definitely testing my knowledge.
@macrobartfast there's a shell command to add a trusted cert for a jvm, that's probably what you want here
keytool -import ...
perhaps
thanks! I'll take a look.
in this case it's someone else's server, so don't know if that will help...
also, depending on OS, there's utilities to keep the jvm certs up to date via the package manager
and since curl seems to work, I'm guessing they have things right... but my knowledge of cert stuff is pretty weak.
@macrobartfast the import works with any cert - the example is your own self-signed cert, but the same import works in any case where you know a specific cert should be trusted but it doesn't have a global root
it could be you need to make your OS update java's certs
ah ok... so I would find out what the cert is from the vendor.
lol... I'm really tipping my hand here.
even curl can get you the cert to add (or openssl) iirc
oh, cool!
> connects to the desired website and pipes the certificate in PEM format on to another openssl command that reads and parses the details
Durham, North Carolina
I need a macro where I use another macro inside. Namely I need a macro that takes a params
map and a body
, and does with-redefs
on some function based on params
then run body
inside, but I’m struggling with all those splicing/unsplicing rules. Can someone show me a similar example please.
I don't have a specific example, but the main things that helped me with this sort of thing were: 1) understanding that splicing/ quoting etc. are not macro features, they are list construction features 2) the goal of a macro is to construct the code you want compiled as a list - whether your list happens to contain a macro invocation vs. a function call shouldn't change things much
So I need something like this:
(defmacro with-all-redefs
[{:keys [agreement-map
certificate-map] & body]
`(let [doc-pkgs (list agreement-map certificate-map)]
(with-redefs [db/get-project (constantly doc-pkgs)]
~@body)))
doc-pkgs is invalid as a binding name inside `
but for your case here, replacing it with doc-pkgs#
suffices
(that's an auto-gensymed local, all uses are guaranteed to use the same symbol)
okay I’ve fixed that, but I think still missing something macroexpand creates strange list of things
maybe that’s what supposed to happen, I dunno. I’m gonna test. Thank you @U051SS2EU
the expansion of ` (especially with ~@) tends to look very weird
it's the same
(let [foo# ...] (frob foo#))
the two uses of foo# are guaranteed too expand to the same auto-generated symbol
now I’m struggling with destructuring… how do you make a macro that take a map and destructure it?
I think the easiest way is to use the normal (non :keys) map destructure
{foo# :foo bar# :bar}
oh, but your :keys destructure is outside the ` block, so it should be fine anyway
why this not working:
(defmacro with-all-redefs
[params & body]
`(let [{:keys [foo]} ~@params]
(prn foo)))
(with-all-redefs
{:foo "one"})
oh that's not what you had before, you do need the alternative destructure for that
but if it's possible to move the let binding outside the syntax quote block that's even better
also that ~@params is surely wrong
cmd)user=> (defmacro with-all-redefs
[params & body]
`(let [{foo# :foo} ~params]
(prn foo#)))
#'user/with-all-redefs
(ins)user=> (with-all-redefs {:foo "foo"})
"foo"
nil
Most of the macros I create of are hours of work 🙂
but those sweet sweet minutes of work it saves lol
In a multimethod, is it possible to override the dispatch function and call a specific method? I'd like to create a new method that simply calls one of the other defined methods. (I need to do this because there's a different method that takes priority if I don't. Also, the multimethod is a library function so I can't change it.)
you can reach into the multimethod and pull out the function for a given dispatch value and just invoke it directly
Exactly what I want! What's the syntax for that?
it isn't syntax, you use get-method, pass it the multimethod and the dispatch value to get the function from the multimethod, then pass it whatever arguments
awesome, thanks!
Yep, solved my problem perfectly. Thanks again. I didn't know about get-method, and apparently was using the wrong search terms. 🙂
And in case anyone else ever hits this: if you pass a SQLException to clojure.data.java/from-java, it'll overflow the stack, because SQLException implements Iterable and returns itself as the first item of the iteration. Can be fixed with: (defmethod from-java java.sql.SQLException [^Object instance] ((get-method from-java :default) instance))
Might be good to put that in a ticket for the clojure.data library if you are willing. I would be a little bit surprised if the maintainers want to change the lib for that case, but having it documented near the library might be useful.
I'm certainly willing if you think it'd be useful
For all I know, there might be dozens of such weird cases for various Java classes, and trying to collect them all in one place would be a nightmare 🙂
Yeah. I consider this class somewhat ill-behaved. There are getNextException/setNextException methods, but if you access it as an iterator it follows that chain, starting with itself. Nothing that tries to walk the class recursively is going to work. My one-liner ignores the Iterator behavior, but it'll still capture the whole chain of exceptions through the getNextException getter. So that solution is quite specific to this one class.
How does one file a ticket for that project?
The link to do so changed in the past month or so -- let me look for the updated one ...
Going to http://clojure.org and clicking the DEV link near the top right takes you to a page with lots of instructions, including a "If you simply need to file a bug, you can do so" link under the "Becoming a Contributor" heading.
That link lets anyone create a bug report, which someone (likely Alex Miller) will decide where it goes.
awesome, thanks
Hey folks, I need some more JDK 11 help here
I’m getting these kinds of errors on JDK 11, but not JDK 8 -
java.lang.NoClassDefFoundError
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
This error is being thrown when trying to load a function that’s bound in a let
it’s compiled on JDK 8 right now, yes
This isn’t reproducible on my local machine though
*isn’t
there's probably something beneath those traces that will clue you towards what isn't being found
I know what isn’t being found, but I can’t figure out why it isn’t being found
Nope, only jdk internal reflection references
I can get the full stack here, but I have to clean up some names before that
hahaha
Fair, one sec!
@gseyffert the AOT compiled stuff on JDK 8 is probably calling a method on a class that either no longer exists or was renamed on JDK11, or has been made module private in JDK11
Actually in this case it’s pulling a function off of a record
A record we own
sorry still cleaning this stack
the function is a protocol method implemented by the record? or a fn stored in a record's field?
the latter I believe.
accessed via (:a-keyword a-record)
do you get the error accessing the fn on the defrecord, or after accessing when you try to call it?
The latter
OK here’s the clean stack -
The flow is basically -
(let [a-fn (:some-kw a-record)
...
reduce-fn (bound-fn
([] {})
([m itm]
...
(if (or (nil? a-fn) (a-fn some args)) ;; throws here
...
)
)
)
]
(fold 4 merge reduce-fn a-coll)
)
it does in some cases, but this will throw for record instances that don’t even have :some-kw
defined (just nil
)
I'd expect that to throw
In my code example above it’s more like (if (and a-fn (a-fn some args)) ...)
or rather, it’s
(if (or (nil? a-fn) (a-fn args)) ...)
So we aren’t trying to call nil
I attached a remote debugger as well to repro and indeed (nil? a-fn)
resolved as true
it’s messing me up because we have another similar function that uses the same pattern, except w/out binding a function from a record, and it works just fine
on JDK 11
/**
* Returns a rethrowable exception for this task, if available.
* To provide accurate stack traces, if the exception was not
* thrown by the current thread, we try to create a new exception
* of the same type as the one thrown, but with the recorded
* exception as its cause. If there is no such constructor, we
* instead try to use a no-arg constructor, followed by initCause,
* to the same effect. If none of these apply, or any fail due to
* other exceptions, we return the recorded exception, which is
* still correct, although it may contain a misleading stack
* trace.
*
* @return the exception, or null if none
*/
^^^ at java.base/java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:603)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at java.base/java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:603)
at java.base/java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:678)
at java.base/java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:722)
at java.base/java.util.concurrent.ForkJoinPool.invoke(ForkJoinPool.java:2423)
at clojure.core.reducers$fjinvoke.invokeStatic(reducers.clj:30)
at clojure.core.reducers$foldvec.invokeStatic(reducers.clj:306)
notice you're in a sad path alreadyHa true
I hear you, but it’s also the case that some instances this works fine, and on other instances it doesn’t
Restarting helps, but then over time the errors reappear
virtual machine, same host
So 2 JVMs running on the same host, one will throw this error and the other won’t
And once it starts throwing, it doesn’t stop
It does seem to be some issue with the classloader... besides JDK 11, the only correlation I’ve been able to find is just amount of traffic that instance has taken since starting up
On this machine I might have a repl. I can look in a few minutes
I wonder if the very first time the offending class gets loaded is within a context in which it cannot initialize
That’s a sore point haha. I wish it wasn’t but unfortunately it is
Much of our stack is ancient and still uses threadlocals (!!!)
Hence the usage of bound-fn
Hmm that is a thought!
For sure