This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-04
Channels
- # announcements (5)
- # beginners (124)
- # boot (43)
- # braveandtrue (8)
- # calva (1)
- # cider (44)
- # cljs-dev (1)
- # clojure (188)
- # clojure-canada (3)
- # clojure-germany (1)
- # clojure-italy (5)
- # clojure-nl (13)
- # clojure-russia (1)
- # clojure-spec (14)
- # clojure-uk (42)
- # clojurescript (94)
- # core-async (5)
- # cursive (5)
- # datomic (45)
- # duct (3)
- # emacs (6)
- # figwheel-main (93)
- # fulcro (22)
- # graphql (3)
- # hyperfiddle (1)
- # leiningen (3)
- # off-topic (1)
- # pedestal (1)
- # play-clj (1)
- # portkey (1)
- # re-frame (17)
- # reagent (71)
- # remote-jobs (2)
- # rum (3)
- # shadow-cljs (45)
- # spacemacs (17)
- # specter (18)
- # tools-deps (27)
- # unrepl (1)
- # vim (3)
problem is im not sure what I'm looking for
how to phrase it, rather
oh , i see
those are quick shorthands for accessing maps. you can also use the get
function, which does about the same thing. for deeply nested maps, there’s also get-in
where you can give it a path of keys to look up
oh great now i have a null pointer exception
fixed it
can I create a new instance of the list, but without the last item in it?
any idea how that differs from (butlast list)?
aw yes. I see that running type
on each
does (drop-nth
exist?
https://stackoverflow.com/questions/24553524/how-to-drop-the-nth-item-in-a-collection-in-clojure
the top solution is the one you should go with if you want it to be lazy like drop
/`drop-last`
Anyone with some experience regarding batch-ques with rabbitmq? I am currently trying to implement a "User-notification-que" where they can Accept/Cancel. Grouping users together. I want to try and not save info in a database since they're not important to me if all 10 of them don't accept.
I was thinking about batching 10 - 100 users together at a time in my api and then send their Id to a consumer, but it's also this thing if 1 cancels, then I have to reque all of them. so it would be like: 1. 10 requests to my api from users who wants to que up [Batch them here.. if possible] 2. Produce an event which a consumer is listening to. 3. Send "Accept" - notification to the users 4. If accept : do something, If 1 user presses cancel or doesn't click accept within 15 minutes -> Send the remaining 9 users to the que again)
Will use LinkedBlockingQueue
or look at pre-fetch.
Hey! I want to use data_readers.clj in my project, but I get Attempting to call unbound fn: #'equipage.data-reader/money
:
Question: I am trying to move environment variables from profiles.clj
into the project.clj
file. The only thing I want to keep in the profiles.clj
is passwords/credentials. In my project.clj
I have
:profiles { :dev [:shared :project/dev :profiles/dev] }
where :shared
is defined as :shared { :env { :mysql-port "1433" } }
I suspect that is just the way Leiningen prints them (using name
on :project/dev
produces just "dev"
).
Leiningen prints the fill list of profiles being applied. Behind the scenes, they are merged into a single "profile".
@mario.cordova.862 Do you have the lein-environ
plugin in your project.clj
? (per this SO Q&A: https://stackoverflow.com/questions/21517583/cant-access-environment-variables-in-leiningen-project-clj-with-environ )
@seancorfield I do have that plugin installed but I got it working by changing the profile name to something else. So it became :profiles { :develop [:shared :project/dev :profiles/dev] }
Ah, interesting...
(there's a #leiningen channel if you get stuck with quirks of Leiningen and no one here seems to be able to help -- caveat: I don't know how active it is since I don't use lein
)
@seancorfield apart from the confidence of using an “official” tool; have you found a tangible benefit since switching from lein/boot -> clj?
@dadair I like the simplicity and consistency of it (sorry for the slow reply -- was in a meeting from 11am).
I like that it adds less "weight" to the dev/test/build process.
We're looking at migrating at least some of our dev/test/build process at work from Boot to clj
but we have a lot of machinery in Boot right now so that has proven challenging so far (I think I've had that branch open for a few months now!).
(defn calcMultiples [limit n] (take n (filter (or multipleOf3 multipleOf5) (range limit))))
or
takes two Boolean (or at least truthy) values...
You could either write it out explicitly -- (fn [v] (or (multiple-of-3 v) (multiple-of-5 v)))
-- or look at some-fn
And a word on style: in Clojure we use kebab-case
for most names, rather than camelCase
(like Java etc).
And "Welcome to Clojure!" @gold88
Thank you for your feedback and helpful advice on my first lines of clojure 🙂 happy to be here @seancorfield
>whose values do not exceed four million. I just added a predicate like before but It can't be the right thing.
since the filter is called after the number has been calculated, i probably wanna check that before
(although, in this case, don't you just want to ensure limit
is no bigger than four million?)
https://projecteuler.net/problem=2 it's talking about the computed fibonacci values which are even
(defn fib ([] (fib 0 1)) ([a b] (lazy-seq (cons a (fib b (+ a b))))))
(defn even-fib [n] (take-while #(> 4000000 %) (filter even? (fib))))
nice. you can also just piece everything together like
(->> (fibs)
(take-while (fn [v] (< v 4000000)))
(filter even?)
(reduce + 0))
In other words, they don’t pass the result of one function to the next like you might imagine.
They end up behaving that way, but you’ll see, with some corner cases, that they are best thought of as macros that rearrange your code.
that's my favorite example (the ->> version is almost like where
in ml / haskell)
=> (->> (+ lexical demo) (let [lexical 11 demo 31]))
42
@gold88 yes, , is whitespace, that has nothing to do with what's happening there
the thing shown in these examples is that it isn't passing a result to the next form - it's injecting the literal form into the other literal form before compiling
if you use threading in the normal way it's fine for a beginner - this is a sample that helps you when an unexpected bug happens
eg. (-> 2 (fn [x] (* x x)))
- that expands to (fn 2 [x] (* x x))
i just copy paste commands that i dont know yet in there and i dont need to do (doc fname)
(defn ->host
[{:keys [domain repo-name branch-name]}]
(str (sanitize-name repo-name) "-" (sanitize-name branch-name) "." domain))
(defn subdomain->host
[domain subdomain]
(str subdomain "." domain))
i saw these in a github projectit's a naming convention. ->host
means 'make a host', and subdomain->host
means 'convert a subdomain into a host'
if someone has (defrecord foo ...)
clojure will create ->foo
and map->foo
automatically. we also use names like that directly
-, >, +, *, |, and many others are not "special" in clojure, they are just part of a name
(`.` and /
on the other hand do have some "magic" to them in the reader so aren't as free)
https://github.com/bbatsov/clojure-style-guide#arrow-instead-of-to covers the second one
into a foo, yeah
(def ^:dynamic *buffer-size* 1024)
okay this one has two question: ^:
? and asterisk wrapped strings?
*ear-muffs*
is a convention to indicate dynamic variables -- names that can be bound to new values at runtime using binding
And ^:dynamic
is metadata for the var and is shorthand for ^{:dynamic true}
which marks the var as dynamically rebindable
(binding [*buffer-size* 2048]
... execute this code with *buffer-size* bound to 2048 ...
... )
;; and now *buffer-size* is back to 1024
You'll also see
(def ^:private foo 42) ;; make foo private to this namespace
...
;; but it can still be accessed as #'the-ns/foo outside that namespace
@gold88 If you haven't already seen it, this is very helpful for the syntax stuff https://clojure.org/guides/weird_characters
thats helpful, thanks @seancorfield
they are more common in older code in my experience, but sometimes they are much nicer than the alternative of a shared mutable value
since binding
changes the view of the variable inside a specific scope, but is invisible outside that scope
and some things like *out*
for example are always going to be dynamic so it makes sense to alt least know how to use them well