This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-24
Channels
- # announcements (2)
- # beginners (130)
- # calva (72)
- # cider (4)
- # cljdoc (15)
- # cljs-dev (3)
- # cljsrn (2)
- # clojars (4)
- # clojure (55)
- # clojure-nl (1)
- # clojure-uk (19)
- # clojurescript (46)
- # cursive (95)
- # datomic (6)
- # figwheel (40)
- # fulcro (12)
- # hyperfiddle (3)
- # off-topic (11)
- # onyx (3)
- # parinfer (6)
- # pathom (15)
- # protorepl (38)
- # re-frame (67)
- # reitit (18)
- # shadow-cljs (45)
- # tools-deps (2)
It always has either two or three elements? Maybe destructuring would be easier here
(defn add-id [[tag attr-or-body body] the-id]
(into [tag] (if body [(assoc attr-or-body :id the-id) body] [{:id the-id} attr-or-body]))))
then you can just call (add-id hiccup-data "some-id")
Ok, I think I got something that works, but it sure looks ugly 🙂
(defn add-id [field-html id]
(let [[element & rest-elements] field-html
[attr body] (if (map? (first rest-elements))
[(first rest-elements) (rest rest-elements)]
[{} rest-elements]
)
]
(vec (concat [element (assoc attr :id id)] body)))
)
(defn foo
[[tag attr-elem & elems]]
(if (map? attr-elem)
(concat [tag] [(assoc attr-elem :id :some-id)] elems)
(concat [tag {:id :some-id} attr-elem] elems)))
I hope I can shake that feeling eventually that some things that are "easy" in Java are hard in clojure 😉
If your level of Java familiarity is much higher than Clojure, then that feeling can take a while to shake. It is a learning experience.
(defn foo
[[tag attr-elem & elems]]
(into [tag]
(concat (if (map? attr-elem)
[(assoc attr-elem :id :some-id)]
[{:id :some-id} attr-elem])
elems)))
i feel like there is a monadic solution to this one as well. this sounds like an either or some kind of state monad could work
as usual, if things tend to become too complicated, the approach is probably wrong. Turned out that normalizing the structure first, then manipulating the second element is much easier. Good lesson.
I can't seem to find any option/environment variable that allows me to change the Java Path / Java Home for the clojure
script. Could someone point me to the proper documentation?
The clojure
script I have does not set the JAVA_HOME env variable, but expects it to have a value already set when it starts. If you use the bash shell (or several others with similar command syntax) you should be able to first do export JAVA_HOME=/path/to/my/java
Thank you @andy.fingerhut! Yeah just figured that out too. Simply setting JAVA_HOME
is enough 🙈
My Clojure functions seems to be called at the same time. Aren't function supposed to be called one after the other when they are on the same file in Clojure?
I was trying to practice using match ( from examples on the web like )
(let [x true y true z true] (match [x y z] [_ false true ] 1 [false true _ ] 2 [ false] 3 [ true ] 4 :else 5))
and i get Caused by: java.lang.RuntimeException: Unable to resolve symbol: match in this context
match isn’t part of the Clojure core. You have to include core.match as a dependency
i will give that a shot
thanks .. that worked to require it in my project.clj file.. gosh .. i am the unlimate noob ..
match
is something that you would expect to be in clojure.core
, but Rich Hickey has opinions about pattern matching
i read something about that where Rich was saying he did not like certain kinds of pattern matching. i liked the erlang style function patter matching and i was trying to experiment with working on how to do that
i saw that library called defun but i not sure if anyone using it or that if that is kinda frowned on ( in favor of using the match function )
Clojure has multimethods which are kind of a rough approximation of certain kinds of Erlang pattern matching
i was reading about that too .. i don't mind doing stuff that is not idiomatic clojure but it is nice to know what other people do to solve that kind of problem
that error
i am curious how to run that ( i am using lein repl and also regular closure cli
@somedude314 Functions are supposed to be called one at a time, per JVM thread at least, no matter whether they are in the same file, or different files. What have you tried that leads you to think it might not be doing that?
i think i am pretty up to date with clojure with
REPL-y 0.3.7, nREPL 0.2.12 Clojure 1.8.0
But note that if function A calls function B, then in one sense A and B are being called "at the same time", overlapping in time. That is not unique to Clojure.
@dansudol You might need to do (require '[core.match :refer [match])
?
ok ..trying that
i tried to require core.match and now get
Could not locate clojure/core/match__init.class
i guess i have to install core.match or something ?
oh .. ok .. i thought something like core.match was part of the core package. most of the examples on teh web make it look like that
@andy.fingerhut here's my code https://bpaste.net/show/22941769984b - they are working 100% of the time when I call (setup-db-tables! "drop") and (setup-db-tables! "create") separately. If I call them together, it's as like the tables are not given enough time to get deleted.
A quick note, before understanding all of your code, but maybe the root cause of issues you are seeing: for
in Clojure is lazy. It returns an unevaluated lazy sequence, which is not evaluated until and unless something "forces" the elements of the lazy sequence to be realized.
Maybe you might want doseq
there instead
doseq
is "eager"
@andy.fingerhut that solved the issue! Thank you.
I'm wondering what could be an elegant way to provide support for new data sources processing based on the profile the program is running with. E.g. If I have several profiles in my profiles.clj, e.g. :local, :remote-A, :remote-B etc (which provide e.g. :endpoint to the service I request the data). Then I should be able to define dispatching based on the profile we are running and when I call e.g. (get-data) this method would dispatch based on the profile (i.e. using the :endpoint and the processing also is a bit different for various data sources). Multimethod so that I define some auxiliary multimethod "internal-get-data" with dispatching using some data which comprises the profile (or some environmental data in that profile)? Pseudocode: (defn get-data [] (internal-get-data <some-dispatching-data>)) i.e. <some-dispatching-data> => provides the information for the dispatching?
any cursive users out there feel like giving me a hand. i am loath to admin it, but i am mostly lost trying to set it up .. i have gotten somewhere but need help on getting really going
oh .. thanks did not know that existed
I use cursive, it's great. I can try to help.
man .. i be desperate .. i just can;;t figure it out and i keep re reading the docs over and over again
Let's go to #cursive and continue there...
BTW, how do you go there? 🙂
a friend who uses clojure told me about this channel ( he uses emacs )
I mean I can't find the channnel in this Clojurians slack...
Ok. I found it now, let's go there.
ok .. got it
FYI I think Cursive just released a new version and they’re in the midst of updating the docs?
gosh .. i hope they update the docs .. man .. i just stare at them mystified because it does not match the current version
wow .. that is timely .. thanks
it’s very unfortunate that they would release the new version without updating the documentation. I’ve sent one or two PRs myself to update their docs (and I don’t even use Cursive day-to-day)
ok .. that is pretty hillarious
Hello 🙂 This is my first time trying to fix reflection warnings therefore help is welcome 😛
(def ^HmacUtils gh-sha1-generator
(^HmacUtils HmacUtils. HmacAlgorithms/HMAC_SHA_1 (:github-webhook-secret envs)))
I’m receiving the following warning:
Reflection warning, codcheck/auth.clj:14:3 - call to org.apache.commons.codec.digest.HmacUtils ctor can't be resolved.
What is a correct way to fix it?Ok I got it. All I had to was to add type annotations for ctor args.
(def ^HmacUtils gh-sha1-generator
(HmacUtils.
^HmacAlgorithms HmacAlgorithms/HMAC_SHA_1
^String (:github-webhook-secret envs)))
Btw what do you guys do with reflection warnings in 3rd party libraries? I mean how do you disable them
Thanks @lilactown 🙂
If reflection occurs in non-critical-path code, e.g. init code intended to be run once or a few times in your application, it is perfectly reasonable to leave it there. Clojure itself has dozens of occurrences of reflection in its implementation like this.
But shouldn’t we remove those warnings? I mean Clojure and Library maintainers should either remove those warnings or allow community to do it.
For instance I’m preparing the PR for buddy.sign. I think it’s important because for instance Graalvm requires no warnings as far as I can tell
If they aren't hurting performance in a significant way, I'd say no. Also some reflection warnings are impossible to remove with type hints.
e.g. if the run time type is truly unknown at compile time on a Java interop call, and must be resolved at run time.
When compiling Clojure, there are no reflection warnings, because the places where reflective calls exist, (set! *warn-on-reflection* true)
has not been done in that file, so the compiler issues no warning.
If there is a reflective call in the inner loop of some performance-sensitive part of a library, I'd say that is a performance bug, yes.
Ok now I got it. There are so many things I don’t know about Clojure/Jvm ecosystem. Thank you @andy.fingerhut for clarification. 🙂
Everything is new to a person once. No worries.
How can I make this function work when its comment has quotes: (defn hi "not w"k"ing" [] "hello")
without escaping every quote?
@lilactown Ah okay, thanks
If you want it to be a doc string, yes. You can comment lines with ';' of course, no quote escaping required there.
@andy.fingerhut gotcha, ; didn't cross my mind in this case, will use it
Hey all, I've used the ramdajs library for a long time, and now that I'm working in clojurescript, I find myself often reaching for (and manually writing) ramda functions, but I'm curious if that's an antipattern? Like, should I be investing more time in understanding transducers, or using spectre? I know ramda's auto-curried approach isn't really clojure's jam (which is cool, because in clojure it's rarely necessary), but things like a.filter(whereEq({x: 1, y: 2})
are so handy to have around. Should I discipline myself to use clojure's idioms, or is ramda (via cljsjs maybe) an ok way to go?
it’s non-idiomatic, not portable, performance will be worse than native JS or it just straight up won’t work with Clojure data structures
I'm curious what's not idiomatic about it, for example how might you do (some (where-eq {:x 1 :y 2}) xs)
in vanilla clojure?
I don’t think you really need transducers or specter to reproduce a lot of what ramda gives you
Best I can come up with is (some #(and (= (:x %) 1) (= (:y %) 2)) xs)
which is pretty ugly
interesting, maybe I'll just start porting ramda to clojure then, I use probably 30% of the library (but it's huge)
And the whole iteratee-last style in ramda isn't necessarily relevant in clojure everywhere
You can't use thread-first because of some
's signature, or thread last because of assoc
annoyingly, sequence operations are often reverse (e.g. map
, filter
) because if you pass in only a predicate it returns a transducer
as->
or for simple cases I do things like:
(-> x
(->> (some pred?))
(assoc key val))
Thanks all, I will not use ramda
, instead I will port concepts over in an ad-hoc, clojurey way until I grok the idioms better.
there are some utility libraries around like https://github.com/weavejester/medley