This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-14
Channels
- # adventofcode (1)
- # babashka (60)
- # beginners (107)
- # calva (11)
- # cider (3)
- # clara (11)
- # clj-kondo (6)
- # cljs-dev (33)
- # clojure (70)
- # clojure-dev (4)
- # clojure-europe (3)
- # clojure-italy (2)
- # clojure-kc (1)
- # clojure-losangeles (12)
- # clojure-nl (4)
- # clojure-spec (32)
- # clojure-uk (35)
- # clojuredesign-podcast (1)
- # clojurescript (28)
- # core-logic (4)
- # cursive (5)
- # datomic (34)
- # devcards (1)
- # emacs (16)
- # events (13)
- # fulcro (15)
- # graalvm (5)
- # graphql (3)
- # jobs (8)
- # joker (2)
- # kaocha (17)
- # malli (6)
- # music (3)
- # off-topic (58)
- # protorepl (7)
- # re-frame (28)
- # rewrite-clj (9)
- # shadow-cljs (102)
- # spacemacs (3)
- # sql (20)
- # tools-deps (9)
i'm running into a weird issue where the google-cloud-pubsub
library works in a standalone application, but when i include the same code in my luminus web application, the program hangs on waiting for the publish request to happen
(ns pubsub-test.core
(:require [clojure.tools.logging :as log]
[mount.core :refer [defstate] :as mount])
(:import (com.google.cloud ServiceOptions)
(com.google.pubsub.v1 ProjectTopicName PubsubMessage)
(com.google.cloud.pubsub.v1 Publisher)
(com.google.protobuf ByteString))
(:gen-class))
(defn- connect! [{:keys [topic-id]}]
(-> (ServiceOptions/getDefaultProjectId)
(ProjectTopicName/of topic-id)
(Publisher/newBuilder)
(.build)))
(defstate publisher
:start (connect! {:topic-id "my-topic"})
:stop (.shutdown publisher))
(defn publish! [message]
(let [data (ByteString/copyFromUtf8 message)
pubsubMessage (-> (PubsubMessage/newBuilder)
(.setData data)
(.build))]
(.publish publisher pubsubMessage)))
(defn -main [& _args]
(do
(mount/start)
(let [message-id (-> (publish! "Hello, World!")
(.get))]
(log/info "Message ID: " message-id))))
at this point i'm guessing that some executor is failing to run the publish request, but i don't have any hypotheses as to why this would only be an issue in the luminus application
in case anyone is interested i figured out the issue. luminus includes google closure to support clojurescript. both com.google.javascript/closure-compiler-unshaded
and com.google.cloud/google-cloud-pubsub
depend on protobuf-java
. unfortunately, they depend on different, incompatible versions
Hi! is there an alternative to core.match
that I can use to store patterns to be matched as data and not have to rely on the match
macro? To clarify, what I'd like is to have something like this:
(def patterns
'[[_ 1 2]
[a b c]
[a b]
[_ & tail]])
(let [my-data [0 1 2]]
(doseq [pattern patterns]
(println (matches? pattern))))
;; => {:match true :bindings {}}
;; => {:match true :bindings {:a 0 :b 1 :c 2}}
;; => {:match false}
;; => {:match true :bindings {:tail [1 2]}}
I have a namespace with a :gen-class
(I need to subclass and to be accessible from Java): https://gist.github.com/1bf76fb6eb8f5217062db5b0f15e1167
When I compile this I get 60 .class files, i.e. the gen-class class, a dozen classes corresponding to vars in that namespace, and the rest from clojure.specs.alpha
(see gist)
what's the right way to distribute this? The generated class relies on some of those vars. can I just distribute the single class file + the clj
file?
no, you need all of those classes
the ones from that namespace that is
you don't need the core.specs.alpha ones (those were transitively compiled)
the clj file won't be used
I'm getting a bit of a puzzling error. I'm referencing this in logback.xml
, and when the process boots I get this
2019-11-14 15:35:08.689 INFO org.eclipse.jetty.util.log - Logging initialized @62847ms to org.eclipse.jetty.util.log.Slf4jLog
Syntax error (ClassNotFoundException) compiling new at (ring/adapter/jetty.clj:31:3).
lambdaisland.logback.clojure_filter.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a
When I take it out of logback.xml
, start the process, then put it back in and wait for logback to rescan its config, then it worksCompiling namespace with -Dclojure.spec.skip-macros=true
does not produce spec classes
I notice what seems to me to be a disproportionate number of UK/EU to US jobs being posted in #remote-jobs. Anyone have an idea about the reason for that? Does Clojure have a bigger market share, compared to other languages, outside of the U.S.?
I don't think that's either true or that you can draw that conclusion from posting occurrence
I'm getting back a method for this:
(.getMethod String "contains" (into-array [CharSequence]))
I want to write my own method invocator that looks like:
(defn invokeMethod [^Object obj method args]
(let [class (.getClass obj)
method (.getMethod class method (into-array (map #(.getClass ^Object %) args)))]
(.invoke method obj (into-array args))))
so it just gets all the classes from the args and then tries to find the matching method and invokes it.
This doesn't go well with for example:
(invokeMethod "foo" "contains" ["o"])
because then it tries to:
(.getMethod String "contains" (into-array [String]))
which doesn't return a method...
How to solve this?(.getClass %) on an argument may return a concrete class more specific than in the signature of the target method
see the congruence checks in the Reflector https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Reflector.java#L141-L142
tldr: you can't guess the right method to call in one shot if all you have is arguments
feel free to use the public Reflector methods if you're doing stuff like this
because calls to that class get embedded in compiled reflective Clojure code, we generally try hard to only grow not break that class so it should be pretty stable
but I would not consider it "official" public API
Does anyone know of any clojure libraries that wrap the java.nio.file.FileSystem
stuff?
Datoteka claims to have a file storage abstraction; but AFAICT it’s not the java one and doesn’t seem anywhere near as useful or complete.
I'm getting a reflection warning for this:
(defn invoke-static-method #?(:clj [_ctx [[^Class class method-name] & args]]
:cljs [_ctx & _args])
#?(:clj
(Reflector/invokeStaticMethod class (str method-name) (into-array args))
:cljs (throw (js/Error. "Not imlemented yet."))))
Reflection warning, sci/impl/interop.cljc:20:6 - call to static method invokeStaticMethod on clojure.lang.Reflector can't be resolved (argument types: java.lang.Class, java.lang.String, unknown).
Interestingly enough that will work for any object array, so typehinting (into-array String ["1" "2"])
as an object array is legal.
the magic of inheretance
they have some methods on fibers that are overloaded to take either a callable or a runnable
oh wow, they are doing continuations
if what they make is meaningfully a continuation, yeah, that seems like a big deal
I think it is technically a delimited continuation, and I am not sure what the exposed api will be, but it sounds like blocking operations in fibers will transparently turn into a callback thing with the current continuation , which is neat
Ron said they'll likely not expose the continuation api at first, but will do in the following releases
an overview I saw just now mentioned coroutines, which means you could potentially have a core.async rewrite using yield for channel writes and resume for channel reads maybe?
I think I saw @ghadi Had posted a Gist with some Clojure code interacting with fibers?
the degree to which core.async would need a rewrite depends on how transparently they handle it, if the fiber support in the jvm automatically turns blocking things like taking locks in to callbacks with continuations, then core.async doesn't really need rewriting, just use the "blocking" api in fibers and it will come out right
the benefit I imagined is being able to use yield / resume in place of a state machine rewrite while still getting the right semantics, but maybe that's far fetched
if the continuation usage in fibers is entirely transparent, you can get rid of the go macro all together, >!! will behave like >! in fibers and continue to behave as does now outside of fibers
yeah, it would potentially allow eliminating a lot of complexity
Maybe I was thinking of this https://twitter.com/roman01la/status/1153989387211948032
@emccue ☝️:skin-tone-2: