This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-11
Channels
- # aws (6)
- # beginners (167)
- # cider (41)
- # cljs-dev (6)
- # cljsrn (3)
- # clojure (399)
- # clojure-dusseldorf (1)
- # clojure-nl (2)
- # clojure-spec (3)
- # clojure-uk (47)
- # clojurescript (16)
- # core-async (8)
- # cursive (56)
- # datomic (14)
- # devcards (1)
- # docs (2)
- # duct (2)
- # editors (3)
- # emacs (3)
- # fulcro (178)
- # graphql (10)
- # off-topic (107)
- # onyx (7)
- # pedestal (21)
- # planck (13)
- # re-frame (58)
- # reagent (76)
- # ring-swagger (3)
- # shadow-cljs (85)
- # slack-help (2)
- # sql (1)
- # tools-deps (11)
- # uncomplicate (5)
- # vim (24)
- # yada (4)
@lgesssler I've heard directly from the person that implemented the foo.core convention in leiningen that it was a way to avoid single segment namespaces with gen-class in them, if you use lein new my.domain/foo
you will get my.domain.foo instead of foo.core
(my.domain/foo makes a directory "foo", my.domain.foo makes a directory "my.domain.foo" but the contents appear identical)
do any of you guys use clojure.test
? if so, is it possible to run all tests except for one (which will be my integration test)? I am trying to just move it to a different folder, but everytime I run lein test
it will run every test inside /teste
folder.
@brnbraga95 Sounds like you could use test selectors for that...
lein test help
should explain that.
You can mark that single test with metadata such as ^:ignore
and then define
:test-selectors {:default (complement :ignore)}
in your project.clj
Or if you could could just tell lein test
which namespaces you want to test (I don't know how many test namespaces you have).
my test folder is:
test:
unity:
files
integration:
files
I tried something like lein test test/unity
but had no luck, I can specify each file lein test :only test/unity/test1.clj
but that is not very handyI am trying to run Cursive in IntelliJ IDEA. I keep getting Could not locate clojure/spec/alpha__init.class or clojure/spec/alpha.clj on classpath.
@seancorfield what does (complement :ignore)
means? did not quite understand what it is saying
@brnbraga95 Specify the namespace not the file path.
thanks sean, got it.
(complement :ignore)
is a predicate that means "does not have :ignore
metadata" in this case.
@lukasz.pomorski01 Hard to say based on so little information -- try the #cursive channel as @cfleming is usually very responsive there.
When I start lein figwheel and the REPL starts, and I interact with the REPL the default font color for my input is really difficult to see (light gray - REPL output is black and ok). Is there some way to change the terminal font colors for Figwheel? Or is this something I have to change in my Linux workstation?
@kari.marttila Iโm a bit confused, can you post a screenshot?
The font for namespace is light gray (hardly visible). My workstation is Ubuntu14. The terminal is Terminator.
I made a workaround - I made a remote REPL connection using Cursive - it is more convenient to use Cursive IDE anyway so this is not such a big issue.
Damn, this is so much fun to learn how to create a SPA using ClojureScript. ๐
Heh. I wonder if it accepts changes to the base font colour, but all the differently-coloured bits are set elsewhere (or hard set) and everyone else uses terminals with a black background
That's the first time I've seen a developer's terminal that's dark text on a light background
Black background is worse for your eyes, see: http://uxmovement.com/content/when-to-use-white-text-on-a-dark-background/
@kari.marttila well, I donโt seem have syntax highlighting in figwheel shell. Apologies, I have no idea how to address your issue.
Is there any way to apply the namespaced map shorthand syntax to nested keys? That is, is there a briefer way to say #::my-ns{:key1 #::my-ns{:key2 42}}
?
@chokheli and @carr0t: Ok. No problem. I'll investigate my Ubuntu / Terminator configuration. And using remote REPL in IntelliJ IDEA / Cursive is anyway more enjoyable since I have all my favorite hot keys there.
Hi, total Luminus newbie here. I'm reading the book Web Development with Clojure, and I just created a new Luminus app using lein new luminus guestbook +h2
. I'm trying to create new migrations using lein migratus create guestbook
but I'm getting the error 'migratus' is not a task. See 'lein help'.. Any ideas?
@nikoszp The Luminus http://www.luminusweb.net/docs#creating_the_database website is more upto date. For the first project.
@nikoszp I had similar issues, Luminus has changed somewhat since that book has been release. You have to check the Luminus website/Github for changes or use the specific versions within the book.
How can I do this? ((f a b c) [x y z] => [(a x) (b y) (c z)]. where "a b c" are functions. It would be a nice way of converting a vector of string data to a vector of types (numeric, dates, etc). Thanks!
map over both functions and data in parallel? (map #(%1 %2) [a b c] [x y z])
Perfect! I was trying out the csv libs, reading in futures data, left with vectors of string data and was thinking...why don't those libs let you pass in a vector of functions to convert all that data to types because that's the first thing one is most likely to do next?
I donโt think thatโs what you want
then you be applying a b and c all to x y and z
all the time
keywords are very useful for "enum-like" values, such as in this map example {:type :combobox}
Hi, I need to transform this map {:1 {:pct 60} :2 {:pct 40}}
into this {:1 {:pct 60 :amount 120} :2 {:pct 40 :amount 80}}
I did it this way (reduce into {} (map (fn [[key pct]] {key {:pct (:pct pct) :amount (utils/round (* 200 (/ (:pct pct) 100)))}}) {:1 {:pct 60} :2 {:pct 40}}))
I also have a version with merge-with
(merge-with into mimapa (reduce into {} (map (fn [[key pct]] {key {:amount (utils/round (* 200 (/ (:pct pct) 100)))}}) mimapa)))
being mimapa (def {:1 {:pct 60} :2 {:pct 40}})
they work, but are they fine?
if you want to go slightly further, first define this
and then
hyper-concise : )
thanks!
Can you make lein repl require clojure.repl
automatically? So I can use doc, apropos, source?
@grierson if you scroll up, @mfikes was just giving some advice on that, I believe: https://clojurians.slack.com/archives/C053AK3F9/p1523335339000044
Normally clojure.repl/doc
and friends are automatically referred into your user
namespace when you do lein repl
I wonder what the experience would be like if a repl had a mode that auto-referred any unique name across all namespaces.
thanks, that has to be more efficient, since it's just one pass
Another option is using the xform
arity of into
:
(defn map-vals [f m]
(into {}
(map (fn [[k v]] [k (f v)]))
m))
that's using the single-arity version of map
which returns a transducer. That's also single pass (because of how transducers work)I've been using:
(defn- fmap [f m] (into {} (for [[k v] m] [k (f v)])))
which is almost identical to that last version @seancorfield.
Not sure about the performance implications, would be interesting to test.@andrew354 to make it more like a real fmap, use (empty m) instead of {} - that way it also works on records, sorted maps, etc.
generally I would expect reduce
or the transducer into
forms to perform better than for
, which is seq based
there are plenty of map-vals impls out there already in various utility libs too
the reason I suggested something more general is that the name fmap implies something very general
check out libs like Medley, Plumbing, Useful, Tupelo, etc
some basic benchmarking:
(into {} (for [[k v] m] [k (f v)]))
46 ยตs
(into {} (map (fn [[k v]] [k (f v)])) m)
32 ยตs
(reduce-kv (fn [m k v] (assoc m k (f v))) {} m)
28 ยตs
where f
= inc
and m
= (into {} (map (fn [x] {x x})) (range 100))
the performance aspects split into consumption of the inputs and production of the output. for
is seq-based which in a case like this Iโd expect to produce more objects and thus be slower.
of course it probably doesn't matter unless it's a hotspot, but it was a fun excuse to use criterium
also there's two ways to use into with map, the one using the map transducer will be faster
it could even be faster than the reduce-kv with assoc
it was ambiguous with the way you used the ...
there are also issues on the collection side about whether youโre using transients and also how the entries are created
there is some optimized code around creating maps from vectors and while itโs not obvious, collecting into a transient vector, then creating a map in one step might actually be faster, esp in small common cases (little harder to bench)
Hi everyone! I'm back with another question... I feel like I just hacked together a solution to get the tests to pass for an exercise http://exercism.io/submissions/826a32bc19bc4439ab7a91258ced2a61#L43 Is there a way to bubble/throw up a value instead of an exception? Right now I'm just putting values in that wouldn't ultimately allow for a passing value... I saw this solution from SO, but it didn't work for me: https://stackoverflow.com/questions/32416048/how-to-return-a-value-on-clojure-try-catch
Also, please let me know if I should put code directly in Slack or if the community prefers links to bins or if I should post the question on SO
@loganpowell: a small thing - you don't need to nest let like that
let is already able to see previous bindings at each step
@noisesmith how do you mean?
The let
s can be be inline?
You have a cascade of three let
s that could all just be one.
ah! sweet!
thank you ๐
You could also use destructuring to avoid calling str-2-seq
twice:
(let [[digits checkr] (str-2-seq isbn) ...
Very nice!
thank you
Also (if condition true false)
is the same as just condition
.
or (boolean condition)
if someone really needs true or false (no code in clojure itself will care)
(that condition
yields a true boolean in this case -- and
on two boolean operations)
oh, yeah, in that case you don't need boolean
are you guys still talking to me?
Yes ๐
haha, sorry, which part/line are you referring to?
(66 - 67)?
exactly - the condition is already true or false so the if is rendundant
so just the (and...
would suffice?
right
cool! I would never have guessed that and definitely would be confused - if you hadn't just told me - if I saw that in someone elses code ๐
The Programming Languages course that Univ. Washington teaches (on Coursera, as well as on site) has that as one of their early lessons (in Standard ML but it applies to any expression-based language): if a true false
== a
thank you so much. This is one of those many things that I wouldn't even know to ask for help for
line 37 in your code seems redundant -- was it left over from when you were developing/testing? The chars
on its own in the body of the let
with the if
following it?
let
evaluates each expression in the body but returns only the value of the last expression (so it throws away the other values)
ah, yeah, that is not intentional. it's left over from when I was putting it together.
I'm surprised it still worked with that in there
'k... range
has a step
argument so you can replace (reverse (range 2 11))
with (range 10 1 -1)
if you want
Sure, it evaluates chars
and then throws away its value.
(let [a 42] 1 2 3 4 5 a)
=> 42
more gems!
first-9
can be simplified quite a bit: you don't need to make the sequence of pair and then apply *
to each, you could just map *
over those two sequences to start with.
for example (map * (range 10 1 -1) [8 5 6 2 3 4])
In your case (map * (range 10 1 -1) (map #(Character/digit % 10) seq))
so map
can sort of zip two lists together and apply an operator on the pairs?
wow. that's cool
map
can take any number of sequences and applies the function across all of them.
what happens if the input sequences are different lengths?
(map + [1 2 3 4 5] (range 100 110) (repeat 6))
=> (107 109 111 113 115)
-- it stops after the shortest sequence
In the above, (repeat 6)
is an infinite sequence.
very good to know. Man, you're saving me days of learning right now
That's what we're here for ๐
With this exercise, is there anything specified about what should happen if the inputs are not valid?
For example, first-9
could throw an exception if it is passed invalid data?
That's actually the original question I posted above, I'd like to get the whole thing just to evaluate to false
if any of the sub-assemblies don't return valid values
instead, I've just *hacked* in some values that would never work (hopefully)
(try (checking-code ...) (catch Throwable _ false))
@loganpowell: one way that can look is (boolean (some->> input (check-1) (check-2) ... (check-n)))
where each check function returns either a map of bindings (including ones created by previous steps), or nil (to indicate some condition wasn't met and it failed)
Sweet! You guys are the best
@noisesmith is that using function composition (`->>`)?
But you could write
(defn first-9 [digits]
{:pre [(= 9 (count digits)) (every? #(Character/isDigit %) digits)]}
(reduce + (map * (range 10 1 -1) (map #(Character/digit % 10) digits))))
for example, which would throw an AssertionError
if the input (`digits`) wasn't ten characters that represented digits.so, that would avail false
ultimately?
@loganpowell: ->> is not function composition (though the end result is similar) - it's a form rewrite
oh boy, I'm in over my head ๐
some->> is like ->> except it stops if any step returns nil and doesn't run any further steps
fair enough!
let me refactor with all these goodies.
@seancorfield: one gotcha there is that catch Exception will not catch a precondition
cough Throwable
cough
@noisesmith is there a term for this (boolean (some->> input (check-1) (check-2) ... (check-n)))
like the convention
does it return 'false`?
some->> is a form rewrite, it doesn't have another name that I know of, and boolean turns nil into false
groovy ๐
(You'd only want the try
/`catch` in your top-level isbn?
function tho')
ok, thank you guys again!!! I'll be back
I just did the above as an example.
ah, cool, I tried that in the sub assemblies and it didn't work. I'll try it at the top!
Anyone using secretary? Is there any way of making it match multiple routes for a single URL?
Hi, how do you spec a vector whose first 3 item is fixed string and can accept a flat sequence of keywords
@mcama200 what would that even mean? the point of a router is to route to one place
i think its common with react-router. From their docs " When a <Route> matches it will render its content and when it does not match, it will render null. " Meaning, it attempts to keep matching unless you specify otherwise. It's useful if you want to render a component or do a specific action for a set of routes