This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-12-19
Channels
- # adventofcode (44)
- # announcements (2)
- # aws (9)
- # beginners (166)
- # braveandtrue (16)
- # calva (170)
- # cider (14)
- # cljdoc (9)
- # cljs-dev (4)
- # cljsrn (1)
- # clojars (1)
- # clojure (150)
- # clojure-dev (15)
- # clojure-europe (4)
- # clojure-india (3)
- # clojure-italy (93)
- # clojure-nl (18)
- # clojure-serbia (1)
- # clojure-spec (5)
- # clojure-uk (45)
- # clojurescript (54)
- # cursive (19)
- # data-science (8)
- # datomic (83)
- # emacs (6)
- # events (1)
- # hoplon (3)
- # hyperfiddle (3)
- # jobs (6)
- # jobs-discuss (1)
- # klipse (1)
- # lein-figwheel (6)
- # leiningen (15)
- # lumo (1)
- # nrepl (1)
- # pedestal (15)
- # re-frame (48)
- # reagent (4)
- # reitit (2)
- # remote-jobs (1)
- # rum (2)
- # shadow-cljs (111)
- # spacemacs (10)
- # sql (16)
- # testing (10)
- # tools-deps (5)
A question for you guys. I got confused with a word phrase while I was reading a official Clojure document for transient at https://clojure.org/reference/transients#_how_they_work What does that mean by bashed in-place as in the following quote: > Note in particular that transients are not designed to be bashed in-place. You must capture and use the return value in the next call. FYI, I think I got the most feel of this feature, transient. Just to make sure if I've missed something.
It means basically that you should always use the return value of operations like conj! disj! assoc! etc., just like you would if it were the non-! version of that function, rather than using the original transient collection that you passed to conj! disj! assoc! etc., when making further modifications.
There is a little bit more discussion of that in the http://ClojureDocs.org examples for assoc! here: http://clojuredocs.org/clojure.core/assoc!
Ask more questions if that doesn't help make it clear. That page is very quickly and easily editable for anyone, so quick to improve it if you know what wording might be confusing there.
Actually, one thing that I may have been unclear about above: the phrase "just like you would if it were the non-! version of that function".
When we are talking about regular persistent collections, not transients, you can take a collection named m
and do something like (conj m 5)
. After that returns, both m
and (conj m 5)
are still persistent collections, on which you can do the full set of persistent operations on.
When you take a transient-ified collection m
and do (conj! m 5)
, you should pretend like m
is undefined, and never refer to it again. It may or may not be the identical object as returned from (conj! m 5)
.
@andy.fingerhut Thanks to you , I learned what it's supposed to mean. However, the phrase be bashed, is it a, some kind of lingo for CS? I tried to reason the contextual meaning by referring to English-English dictionary (say, https://dictionary.cambridge.org/dictionary/english/bash) but meanings seem mostly for hit or criticize.
The best guess for the word be bashed
under the circumstances, in my opinion, is be bashed == be modified
. Please correct me if I am still confused.
That is correct: be bashed
is being used in the sense of be modified
. Itβs a metaphorical usage, meant to be more fun to read than a more literal be modified
would have been.
@manutter51 Yeah. Now, I can feel a dynamic action in the phrase, if I got it right. Thanks alot !!
I think it stems from !
being called "bash" in some tech circles...
(I'm used to it being called "bang" but I think I've seen "bash" used occasionally)
Imagine taking a mallet and changing the transient value in place by bashing it repeatedly with the mallet π
In the given sense, we could also name assoc!
and conj!
as bashing functions because they are bang functions and bang and bash are inter-changible in some tech circles. Haha
Hey all again, I am following this https://clojurebridgelondon.github.io/workshop/functions/name-smash.html on this site, this works: (def students ["Ada Lovelace" "Anne-Marie Imafidon"]) (clojure.string/split students #" ")
However in my repel I get an exception
ClassCastException clojure.lang.PersistentVector cannot be cast to java.lang.CharSequence clojure.string/split (string.clj:219)
I am sure its me thats at fault here, i just dont know what ive done
Yes, In your code above, students is a vector ["Ada Lovelace" "Anne-Marie"]
clojure.string/split needs a string as input
so you need to call split on each student, as opposed to the vector of students
So in the little online repel on this site the output is:
["[\"Ada" "Lovelace\"" "\"Ali" "Ebadian\"]"]
then the site goes into map and flatten to make it look nicer
the vector is being turned into a string implicitly, I guess because that's what javascript does
This is why the [
are included in part of your output
(def students ["Ada Lovelace" "Anne-Marie Imafidon"])
(clojure.string/split (str students) #" ")
It's having ^ this effect
ahh indeed
thanks
also the site doesnt really explain whats the rol of #
oh wait
that #
is put infront of a string to make a regular expression pattern
so you can do e.g. #"[a-z0-9]+"
and that kind of thing
more generally, itβs a reader macro: https://clojure.org/guides/weird_characters#dispatch
oh right
that makes more sense.
Sorry about all these questions btw, it looks like i only learn by trying and breaking things then questiong what went wrong (good thing I am not a doctor)
don't worry, this is a great way to learn a language, no-one gets hurt π
While you guys are being far too kind, i am going to show my utter nobiness by the next question
i see a lot of reference to lazy sequences in the docs
but no real good explaintion on what are sequences or lazyness
and vars #'my-var
so if you call, for example, (range 1000000000000000), it won't actually generate a range of 1 squillion numbers straight away
But if you do (take 100 (range 100000000000000)), you'll get the numbers 1 to 100 in a sequence
so if I want the last number in that range, it will generate everything and get the last number?
or does it do something clever and it workout
however, if you only want the last number, it doesnβt keep all the intermediate stuff in memory
so from earlier code (map #(clojure.string/split %1 #" ") students)
returns a lazy squence of ("Ada" "Lovelace" "Anne-Marie" "Imafidon")
No, it should return a normal sequence of (("Ada" "Lovelace") ("Anne-Marie" "Imafidon"))
` user=> (type (map #(clojure.string/split %1 #" ") students)) clojure.lang.LazySeq `
Again sorry about these silly questions
I should note I came here to ask a question before getting distracted, I'm very much also A Beginner
i guess there is levels to beginners
I am white in my introductory class, you're graduating from your white belt class
I am not sure if anyone will find this useful, but it just blew my mind
https://stackoverflow.com/questions/22416387/differences-between-a-seq-and-a-list
Anyway, my question: is there an easy way to split a sequence into equally-sized sequences? It seems like something I'd find in the standard library but couldn't...
I wrote this function, but I doubt it's the best way:
(defn split-on-width
[values width]
(loop [remaining values
new []]
(if (empty? remaining)
new
(let [[head tail] (split-at width remaining)
next-new (concat new [head])]
(recur tail
next-new)))))
partition
?
That is very interesting, Ali, I had some trouble working out the difference myself
Hey folks, apply
is not about taking each args
and apply on a function? Why this doesn't work (apply inc [1 2 3])
it will just take each element of the coll and pass them as argument to to inc
but inc accept only one arg at time
What does the args definition mean here?
(s/defn render-pulse-section :- RenderedPulseCard
[timezone {card :card {:keys [data] :as result} :result}]
It's a nested destructuring, there's a guide on the official site https://clojure.org/guides/destructuring
These should be equivalent:
(defn foo [{card :card {:keys [data] :as result} :result}]
,,,)
(defn foo [m]
(let [card (:card m)
result (:result m)
data (:data result)]
,,,))
Hi, in development for a http-kit server application using mount
, I'm using lein repl
and doing (mount/start)
, which starts my server listening (within the repl process, i'm guessing?). My core.main
function is very simple:
(defn -main [& args]
(mount/start))
However, when i do lein run
, it exits immediately - this seems like a really silly question, but how do I keep the process up and running here?(exits immediately after starting all the mount components, I should say - the code is working fine, i just need the server to stay up and listening)
@hoopes what's the bottom of your project.clj look like? that is where you can define specific lein commands
26 :profiles {:dev {:source-paths ["dev"]
27 :repl-options {:init-ns user}
28 :dependencies [[org.clojure/tools.namespace "0.2.10"]
29 [org.clojure/java.classpath "0.3.0"]]}
30
31 :uberjar {:main ws.core
32 :aot :all}}
33
34 :aliases {"dev" ["with-profile" "+dev" "repl"]
35 ;"make" ["clean" "uberjar"]
36 }
37 )
https://github.com/tolitius/mount/blob/uberjar/test/app/app.clj#L16 reading this...now i'm just wondering what i'm doing wrong π my example looks just like that
hey all, is there an idiomatic way to pull out the first value from a collection that satisfies a predicate? like some
, but returning the actual value that matches instead of true
. would prefer to avoid filter
ing through the rest of a large-ish collection with an expensive op if I can avoid it
btw, filter returns a lazy sequence so doing (first (filter pred coll))
should give the same result without consuming more of the collection than it needs
when using hiccup to generate html, if I want to include jQuery via the google CDN, do you have to use the with-base-url
util?
like so:
(util/with-base-url "https:" (page/html5 (page/include-js
"//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js")))
because I cannot get it to workHi. I am wondering if someone could help point me in the right direction. I need to instantiate a Java interface using new
as well as overriding a method of the interface. I led myself to believe I could do these two things in two steps using reify
to instantiate the interface and then pass it to another class' method, but then the method of the said class doesn't seem to recognise the "reified" interface's type. I might be way off the mark with all of this as I am not an experienced coder, and have no real knowledge of Java, but I don't seem to be making any more progress on Stack Overflow.
This is the code I am trying to translate to clojure directly:
myButton.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
// display pin state on console
System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " = " + event.getState());
}
});
This is my attempt in Clojure:
(def listener (reify GpioPinListenerDigital
(^void handleGpioPinDigitalStateChangeEvent [this ^GpioPinDigitalStateChangeEvent event]
(println (str " --> GPIO PIN STATE CHANGE: "
(.getPin event) " = " (.getState event))))))
(.addListener myButton listener)
Hi @UA8TV3QHF, thanks for the reply. Below is the error message:
IllegalArgumentException No matching method found: addListener for class com.pi4j.io.gpio.impl.GpioPinImpl clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:79)
I amtrying to do a naive translation from http://pi4j.com/example/listener.htmlHi again. I got help on SO. So this is finally a closed case for me. https://stackoverflow.com/questions/53875417/how-to-call-a-reified-java-interface-from-a-class-in-clojure-call-cant-be-reso
Hey there, is there any way to use core.logic or core.unify to write an algebra solver, particularly when working with arbitrary sequences? Something I could say a = b + (sum cs) - (sum ds)
, give it a, cs, and ds and get a out?
Also being able to distinguish between applying sequences of multipliers in parallel (`10 + 10% + 10% = 120`) vs in serial (`10 + 10% + 10% = 121`) would be helpful
There most likely is, but I suspect it wouldn't be a small amount of code, even given the help you would get from relying on core.logic and core.unify. There are commercial systems like Mathematica and open source alternatives (Octave? Maxima? I haven't checked recently to see what is current there) that might be worth examining, unless one of your primary goals is keeping it in Clojure
Maybe way more than you want to dig through here: https://en.wikipedia.org/wiki/List_of_computer_algebra_systems
I've been using wolfram alpha to help me through the stickier bits, so I imagine Mathematica is close to what I want. However, it's really just for a small amount of tricky domain logic, maybe ~400 lines worth. I'm just looking for a way to avoid implementing the equation in both directions basically.
This StackOverflow topic may have some leads, but I haven't read through the linked topics to see what their quality might be: https://stackoverflow.com/questions/12592118/how-to-solve-math-equations-using-core-logic
I saw that, don't think it'll do for my use case. https://github.com/clojure-numerics/expresso looks interesting though
This Google groups discussion is from 2012, but some of the people involved may have done some work that would interest you: https://groups.google.com/forum/#!topic/clojure/fRuTGeW5Wm4
espresso looks more current than anything I have found yet.
If I got a clojure symbol like 'java.lang.IllegalArgumentException
how can I resolve that to its actual class?
That works. I tried that but for some reason I thought it was just returning a symbol. π
cani get test code in an uberjar? ex: i have tests under test directory i want to run during a smoke test of production but not sure its in the uberjar it doesnt seem like it is
@ben.borders None of the tools I know of will put tests in an uberjar. What you could do is put those particular tests under the src
directory somewhere and perhaps add a -main
function that will run those tests (so you can easily run the tests in production).
But I would be very wary of running tests in production -- just in case anything destructive gets into those tests.