This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-15
Channels
- # beginners (56)
- # boot (4)
- # cider (22)
- # clara (10)
- # cljs-dev (50)
- # cljsrn (27)
- # clojure (27)
- # clojure-conj (4)
- # clojure-dev (3)
- # clojure-italy (17)
- # clojure-nl (12)
- # clojure-norway (3)
- # clojure-spec (10)
- # clojure-uk (137)
- # clojurescript (132)
- # cursive (4)
- # datascript (2)
- # datomic (109)
- # devcards (2)
- # editors (1)
- # emacs (4)
- # euroclojure (2)
- # events (4)
- # figwheel (1)
- # fulcro (15)
- # jobs (1)
- # jobs-discuss (4)
- # juxt (3)
- # leiningen (2)
- # off-topic (21)
- # onyx (13)
- # other-languages (8)
- # pedestal (6)
- # re-frame (22)
- # reagent (5)
- # reitit (1)
- # ring-swagger (3)
- # shadow-cljs (75)
- # sql (6)
- # tools-deps (2)
- # vim (1)
- # yada (8)
no, but next does
oh, wait, yes, and next forces at least two
Clojure 1.9.0
+user=> (def loud-nils (map println (iterate inc 0)))
#'user/loud-nils
+user=> (def r (rest loud-nils))
0
#'user/r
+user=> (def loud-nils' (map println (iterate inc 0)))
#'user/loud-nils'
+user=> (def s (next loud-nils'))
0
1
#'user/s
yes, the head
next also checks the first item of the tail (but you weren't asking about next)
next promises to return nil if the tail is nil, rest can return an empty list instead
the behavior of next is often useful in conditionals
my java interop skills are lacking.. how can i go about passing one of these constants (Regions.EU_WEST_1) into a constructor?https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/regions/Regions.html
never mind, problem solved. 🙂
(import com.amazonaws.regions.Regions)
=> com.amazonaws.regions.Regions
Regions/EU_WEST_1
=> #object[com.amazonaws.regions.Regions 0x2bf311c7 "EU_WEST_1"]
Hi. I'm trying to use thrown?
to check for an exception, but the is
still fails because of it. I get a stack trace even from the example in the documentation: (is (thrown? ArithmeticException (/ 1 0)))
. I'm trying this with vim-fireplace, btw. Any ideas?
I'm getting this as the output:
#error {
:cause "Divide by zero"
:via
[{:type java.lang.ArithmeticException
:message "Divide by zero"
:at [clojure.lang.Numbers divide "Numbers.java" 163]}]
:trace
[[clojure.lang.Numbers divide "Numbers.java" 163]
...
Hi. This raises the above for me:
(deftest foo-test
(testing "foo foo"
(is (thrown? ArithmeticException (/ 1 0)))))
It seems it's vim-fireplace related somehow. Just tried and tests pass on the command line.
@nicki One thing you will often see is or
being used as in
(let [user {:real_name "real" :display_name "my name"}
display-name (:display_name user)
real-name (:real_name user)]
(or (not-empty display-name)
real-name))
one other thing: in real code you’d obviously be given user
and you’d probably want to destructure it like this (let [{:keys [display-name real-name]} user] ...
as for your second question, I think it’s something reasonable people can disagree upon, but I’d say generally code is written with some assumptions about what is inputs are ok. if you write every function defensively your code becomes hideous. you can either add assertions or use spec
or schema
to do some sort of validation to assist in tracking down bugs, though. (this is obviously different if you are doing i/o, when you’d want to write code that is prepared to deal with anything)
Yeah ^ perhaps the use of spec in modern code, in this case constraining the value that :display_name
can take, would be sufficient
I like to make sure there's one and only ever one function that will get you the user information. And then in that function you can put whatever defensive logic you want. Then consumers of the name know that it's been conformed and you don't have to be defensive elsewhere in your code base
Conform in a non technical sense. Whether it's through spec conforming or just custom logic etc
That's why I like (or (not-empty some-string) other-string)
jinx 🙂
@seancorfield TBH, it is not clear to be whether not-empty
is legit to apply to a string
I would be surprised by it. At least at first. I look the blank check because it's very straightforward. No real chances for subtle bugs to lurk
True, it depends on whether you consider an all-whitespace string to be "empty" or not.
oh yeah, gotcha @mfikes, you're right, or
definitely works with non-empty
. i'm mixing my fixes.
If :display-name
is " "
, you'll get different behavior from blank?
vs seq
/`empty?`/`not-empty`
@seancorfield good point. i hadn't thought about " "
, which could happen. in my scenario, i'd actually want to use " "
.
Yes, exactly.
i would make your own function that encodes this logic. (defn display-name [user] ...)
there you can be as clever as you want. clever code that you repeat everywhere can be buggy. clever code once is fine because you can put tests that show its exact behavior
cool, that makes sense
(funnily enough, we have that exact function at work, because our dating site members can choose whether to use their username or their first name + initial on their profile)
haha, yes, i'm playing with the slack api, so very much the same
then in the future this function gets extended to take a user-preferences map, context map, on and on
ah, so you get a different display name based on whether someone chooses to display username or their real name.
yes. also context matters. maybe chat shows nickname but profile page shows full name. on and on. your user shouldn't care. consumer shouldn't care "give me a display name. use all the fancy tricks you like"
Hi, I have a macro that uses a vector to generate some code. But I’d like to reuse that vector somewhere else, so I try tried to define it in a symbol, but then the macro does not work with Don't know how to create ISeq from: clojure.lang.Symbol
. Is there any workaround for this? The vector is going to be constant, so it could be evaluated compile time