This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-16
Channels
- # announcements (11)
- # beginners (184)
- # calva (91)
- # cider (68)
- # cljdoc (42)
- # cljs-dev (44)
- # clojure (228)
- # clojure-dev (1)
- # clojure-europe (3)
- # clojure-italy (4)
- # clojure-losangeles (6)
- # clojure-nl (9)
- # clojure-spec (73)
- # clojure-uk (19)
- # clojurescript (61)
- # core-async (6)
- # cursive (2)
- # datomic (11)
- # fulcro (28)
- # hyperfiddle (16)
- # leiningen (2)
- # luminus (3)
- # off-topic (19)
- # om-next (1)
- # re-frame (2)
- # reagent (12)
- # reitit (4)
- # ring-swagger (5)
- # shadow-cljs (14)
- # slack-help (6)
- # spacemacs (2)
- # tools-deps (40)
- # vim (15)
- # yada (4)
i'd like to parallelize jobs over 3 cores, queuing waiting jobs.
right now, we're using pipeline-blocking
to parallelize over 3 cores. looks like this:
(pipeline-blocking 3 out-chan (map process) (to-chan jobs) true)
i think this processes jobs 3 at a time--that's good. but i think that because we have numerous end-users who can kick off lists-of-jobs, we have potentially 3 x number-of-users-who-kick-off-jobs
it might be as simple as a top-level channel:
(def queueing-channel (chan))
then
(put-all-elems-on-chan! queueing-channel jobs)
(pipeline-blocking 3 out-chan (map process) queueing-channel true)
but i'm having trouble finding the equivalent of put-all-elems-on-chan!
i think that if i call
(pipeline-blocking 3 out-chan (map process) (to-chan jobs) true)
say 10 times, i'll get 30 jobs processing at the same time. i'd like a max of 3 jobs processing at once.
i'm phrasing this in this way because i'm not sure if i'm right about pipeline-blocking
thanks. i now think that this is what i want:
(def queueing-channel (chan))
(put-all-elems-on-chan! queueing-channel jobs)
(pipeline-blocking 3 out-chan (map process) queueing-channel true)
i'm finding it hard to understand the async docs. my own fault, of course.some-fn
and every-pred
- why don't they have same postfix (either -fn
or pred
)? Is there some convention/logic behind it, or only history, please?
some-fn returns whatever your fn returned for the item, every-pred just returns true or false like a predicate
Clojure 1.9.0
(ins)user=> ((some-fn :a :b) {:b "OK"})
"OK"
(ins)user=> ((every-pred :a :b) {:b "OK" :a "YES"})
true
Ah... Thank you @noisesmith.
on a side note, it bugs me to irrational levels that some-fn
and every-pred
don't follow a common naming scheme, lol
As long as you realize you are not completely rational in how much it bugs you 🙂
hi folks, I'm setting up compojure, ring, java.jdbc and postgres. When I lein ring server
I get String cannot be cast to clojure.lang.Ifn
in core.clj
during Thread.run
Anyone see this before?
@thomasb That suggests you have, essentially, (some-string-value ...)
What does your Compojure routes
form look like?
hi @seancorfield, routes are here ^^^
Line 12.
Line 11 ends with )
but the call to (views/home-page)
should be inside that.
And the )
at the end of line 12 is closing (defroutes ...
-- it should be at the end of line 26.
yeah, I see that now.
I guess you're not using an editor that auto-balances parentheses based on indentation?
pretty plain vim config
You'll find it hard to edit a Lisp that way, I think.
I'm not familiar with paredit/parinfer plugins for vim but that's what you'll want to look for.
understood
Let me know if those edits fix the problem and get your app running.
yes, that was it. server is running. will look into a plugin for that. thanks for your help!
You're welcome! I'm off for the evening. If you need help with java.jdbc
, feel free to post in #sql and I'll answer when I can (I maintain that library).
Is this an SD card that is already formatted, and looks like a normal file system to the OS?
If so, then it should be the same as writing any other file that is on a disk or SSD drive.
I agree with 95% of that
I don’t buy the argument for lists in :import
> Use lists (parentheses) for the top-level clauses such as (:require ...). Because the first element, the :require or :import keyword, is special.
why to have a keyword with double semicolon? like in here https://clojure.org/reference/multimethods
user=> (require '[clojure.set :as set])
nil
user=> ::set/foo
:clojure.set/foo
user=>
::
is often used in examples because it makes code shorter, but I don't like it in real code because it ties code to a particular namespace, if you have ::
somewhere and then move that code to a different namespace it means something different
that fails because it can't look up the alias
:nonexisting-ns/Ok is fine
my-custom-ns=> (ns foo.bar)
nil
foo.bar=> *ns*
#object[clojure.lang.Namespace 0x1e71dad1 "foo.bar"]
foo.bar=> :my-keyword
:my-keyword
foo.bar=> ::my-keyword
:foo.bar/my-keyword
foo.bar=> (= ::my-keyword :foo.bar/my-keyword)
true
foo.bar=> (= ::my-keyword :my-keyword)
false
the word 'namespace' in clojure is confusing a first since it has two different meanings, one for keywords and the other for "group" of symbols
Not quite. It’s just that :my-keyword
will evaluate to the same value anywhere. But (= :foo.bar/my-keyword :other.ns/my-keyword) ;; => false
A practical example might be distinguishing between similarly named keywords between separate use cases. For instance you may want to differentiate between :project.ns.db/connected
and :project.http/connected
and ::connected
will either resolve to :project.ns.db/connected
or :projected.http/connected
depending on the value of *ns*
.
so :foo/bar
is a valid keyword, and has the namespace part foo
regardless of if the var namespace foo
exists or not
and if you ran (ns project.ns.db)
you could do (::status {:project.ns.db/status :ok :project.http/status :error}) ;; => :ok
no, because keywords don't implement IMeta - but why would you need to hint something that's a literal in the code?
if it's a symbol bound to a keyword, yes you can type hint symbols
keywords don't have separate instances - :foo and :foo will be the same object internally, so there's no place to put the metadata without putting it on all occurances
right, ^clojure.lang.Keyword x
oh oops, I misread your question, sounds like we've sorted it out anyway
generally there is no good reason to do that
type hints help with interop calls and your interaction with Keywords should pretty much always be via clojure code, not java interop
I was doing it as a form of documentation since it was 1 of several args to a function, some of which already had (useful) type hints
It is a best practice to only add type hints when necessary and avoid type hints that have no value
Hey everyone, I’m just trying ClojureScript and figwheel and wondering if this is ok:
(event/listen (dom/get-element "test")
:blur
(fn []
(prn ":blur")))
This event handler doesn’t work when I run after production build js.
But if I replace :blur
to “blur” it does.
So is it required? for advanced optimization?it's likely easier to launch your luminus app from a repl, but alternatively there's an nrepl function to start a repl from within your app if you add tools.nrepl as a dep
I am trying to write a local library and I am getting.
Could not locate satlib__init.class or satlib.clj on classpath.
satlib is the library.
I was thinking I failed RTFM but I looked at 'lein classpath' and it includes a jar with satlib .clj so I am suspecting a mystery (almost certainly caused by my doing something wrong)
The code chunks
sat core https://pastebin.com/7yCi21jf sat project https://pastebin.com/R9jr7A69 satlib project https://pastebin.com/TrqL6ZWV satlib https://pastebin.com/dCyFxY1X
I tried that at one point. I have subsequently renamed core to satlib in src
lemme look at something
When you require a library using :requre
/ :use
etc, you are specifying the namespace you want to load. That namespace needs to be in a file following some mild rules.
For satlib.core
the file would be satlib/core.clj
For satlib
the file would be satlib.clj
As in the ns argument? Yup, but I just changed it and it didn't fix it.
Should I migrate back to satlib.core?
@jrootham up to you—the thing you require just needs to line up with what is available on your classpath
Is there a way to see what exactly is on the classpath, below the 'lein classpath' and 'jar tf" levels?
like, opening the actual artifacts? your editor should be able to do that
right, if I do (io/resource "some/file.clj") that printed result shows you the path where file.clj was actually found and if it was found (non-nil) you can open it and slurp or read or whatever
But here the file is not available because it is not found.
I get "No such namespace:
jar tf
HOT.jar META-INF/MANIFEST.MF META-INF/maven/satlib/satlib/pom.xml META-INF/leiningen/satlib/satlib/project.clj project.clj META-INF/leiningen/satlib/satlib/README.md META-INF/ META-INF/maven/ META-INF/maven/satlib/ META-INF/maven/satlib/satlib/ META-INF/maven/satlib/satlib/pom.properties satlib/ satlib/satlib.clj
That's the jar in the maven repository
So, what silly thing have I done?
I have tried that, shall I try again and hope to get it right this time?
So satlib/satlib in the project file and satlib.satlib in the use
so you can't just kind of go around changing things in place or the other and say it doesn't work, those 3 things don't need to be some specific value, but they need to match
Following what @hiredman said, if in the JAR, it is named satlib/satlib.clj
, in that file it has to have (ns satlib.satlib)
and you have to require it using (:use satlib.satlib)
(since you are using :use
)
The ns in satlib
(ns satlib (:gen-class) (:require [clojure.set :refer [intersection difference union]]) (:require [clojure.string :as str]) )
the names in project.clj are generally related to maven artifact names, and don't need to match or be related in away to clojure namespaces that may be defined in files in that artifact
generally in clojure single segment namespaces like satlib are considered a bad idea (for reasons that have to do with how the compiler maps clojure code to jvm bytecode in classes)
OK, that seems to work
so the namespace satlib would be expected to be found in satlib.clj, satlib.core would be expected to be in satlib/core.clj
Thank you both very much
When I run lein run
with a luminus app running the snippet above and try to connect to the repl I get a ton of output and cider-connect hangs
what about lein repl :connect
with the port number?
web_1 | [java.lang.Thread run Thread.java 748]]} Unhandled REPL handler exception processing message {:id 10d1b11a-937b-4849-a2d4-42c2206309ef, :op clone})
I would avoid putting cider code in an app, also
if you want cider features, start the app from inside cider maybe?
which reloaded the nrepl code, which created new protocol definitions (with the same name as the old one)
Oh wait, maybe this is my fault. I tried sending the code that defines the repl server to the repl 😛
I could maybe try cider-jack-in but I’m trying to run the luminus app from a docker container compsed with a postgres container for storage.
web_1 | 2018-11-16 23:04:03,434 [main] INFO ts-api-explorer.core - #'ts-api-explorer.core/repl-server started
web_1 | 2018-11-16 23:04:26,768 [clojure-agent-send-off-pool-3] ERROR nrepl.misc - (#error {
web_1 | :cause No implementation of method: :send of protocol: #'clojure.tools.nrepl.transport/Transport found for class: nrepl.transport.FnTransport
web_1 | :via
web_1 | [{:type java.lang.IllegalArgumentException
web_1 | :message No implementation of method: :send of protocol: #'clojure.tools.nrepl.transport/Transport found for class: nrepl.transport.FnTransport
web_1 | :at [clojure.core$_cache_protocol_fn invokeStatic core_deftype.clj 583]}]
web_1 | :trace
web_1 | [[clojure.core$_cache_protocol_fn invokeStatic core_deftype.clj 583]
web_1 | [clojure.core$_cache_protocol_fn invoke core_deftype.clj 575]
web_1 | [clojure.tools.nrepl.transport$eval20851$fn__20852$G__20842__20859 invoke transport.clj 16]
web_1 | [clojure.tools.nrepl.middleware.session$register_session invokeStatic session.clj 144]
web_1 | [clojure.tools.nrepl.middleware.session$register_session invoke session.clj 137]
web_1 | [clojure.tools.nrepl.middleware.session$session$fn__21472 invoke session.clj 188]
web_1 | [clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__21121 invoke middleware.clj 22]
web_1 | [nrepl.server$handle_STAR_ invokeStatic server.clj 17]
web_1 | [nrepl.server$handle_STAR_ invoke server.clj 14]
web_1 | [nrepl.server$handle$fn__42728 invoke server.clj 26]
web_1 | [clojure.core$binding_conveyor_fn$fn__5476 invoke core.clj 2022]
web_1 | [clojure.lang.AFn call AFn.java 18]
web_1 | [java.util.concurrent.FutureTask run FutureTask.java 266]
web_1 | [java.util.concurrent.ThreadPoolExecutor runWorker ThreadPoolExecutor.java 1149]
web_1 | [java.util.concurrent.ThreadPoolExecutor$Worker run ThreadPoolExecutor.java 624]
web_1 | [java.lang.Thread run Thread.java 748]]} Unhandled REPL handler exception processing message {:id BB0741D0-3CEF-4F9C-AC1C-3D4630FF0A18, :op clone})
i think there are two clashing versions of nrepl here. note clojure.tools.nrepl.transport
and nrepl.transport.FnTransport
. Lein has not had a release in a while and is still using deprecated contrib nrepl rather than the newer versions
Removing cider restored it to normal. I can connect but when I do I see:
WARNING: CIDER requires cider-nrepl to be fully functional. Many things will not work without it!
it's confusing but there are two "nrepl" things around. There's cider/cider-nrepl "0.19.0-SNAPSHOT" and nrepl "0.4.5" versus [org.clojure/tools.nrepl "0.2.13"]
Backing up a bit I think the way I organized this project with Docker is creating some issues.
Because now I can connect to cider but if I try to execute anything against the repl I see a no client repls in current session even though I’m looking at a cider repl pane right next to it.
If I have a mixed data structure like below, is there a way I can update-in the tail of a vector like this?
@ben.grabow Have you looked at Specter?
I haven't
Looks like it will do just what i need. Thanks!