This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-28
Channels
- # beginners (67)
- # boot (31)
- # cider (1)
- # cljs-dev (12)
- # cljsjs (1)
- # cljsrn (23)
- # clojure (86)
- # clojure-russia (2)
- # clojure-spec (6)
- # clojure-uk (12)
- # clojurescript (171)
- # core-async (2)
- # core-matrix (1)
- # cursive (3)
- # events (1)
- # lumo (6)
- # off-topic (118)
- # om (51)
- # onyx (16)
- # perun (3)
- # re-frame (14)
- # reagent (19)
- # uncomplicate (5)
- # unrepl (6)
- # untangled (6)
@lepistane: I've done similar things by just having a parameter in the rendering code - then if they don't have access you can hide the UI that they can't use. I prefer it to changing CSS. Do you get to design the whole front end but the back end is fixed?
@shaun-mahood i am doing both but requirement from client is he wants to show info the the user, see comments etc. once he is logged in he can edit comments which are his. i have if in my code. if logged in - include options for frontend not - not included options (they dont exist, arent just hidden) and also i prevented on server side if some hackers shows up so he cant edit comments that are not his or if not logged in
@vitruvia Nice implementation of tails ! I found (sequence nil)
a little bit unfamiliar, you can replace it with '()
, which is the empty list.
Also, you don't need to (seq a-seq)
, as a-seq
is already a sequence. seq
is useful when you need to transform something to a sequence (seq "foo") ;; => (\f \o \o )
.
So you could rewrite
(defn tails [a-seq]
(if (empty? a-seq)
(cons '() a-seq)
(cons a-seq (tails (rest a-seq)))))
You might think "If a-seq is nil, then (cons a-seq …) will fail." but the (empty? a-seq)
will prevent it, because (empty? nil) ;; => true
if you want to have some fun, you can write
(def inits (comp (partial map reverse) reverse tails reverse))
But a loop/recursion-based implementation would be better if you care about performances or stack overflows 😉@ggaillard there is never a reason to use '(), you can just use ()
@noisesmith I took the habit to quote list literals to distinguish them from calls, I didn't knew it worked. Thank you !
it's unambiguous, so it's a special case () can't possibly be calling anything
@lepistane: Sounds like a good way to do things to me
Can anyone let me know if this is the right way to do Java interop, I'm getting an error and I'm not sure if it's just my syntax. Original Java:
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
Clojure Version:
(doto (ChromeOptions.)
(.addArguments "start-maximized"))
@nimblerabit that is the right way to use doto
Is there any reason I might be getting this error on the code above?:
IllegalArgumentException No matching method found: addArguments for class org.openqa.selenium.chrome.ChromeOptions clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)
@nimblerabit What error are you getting?
what happens if you explicitly type-hint the args? i believe i've come across similar, where adding a type hint helps the compiler figure out what to do.
@nimblerabit the first thing to check is if you are doing varargs properly - that's a varargs method
what does your call look like?
@mobileink it takes string varargs, type hints won't help there - it knows the class the method is being called on
the common error here is to see that Foo.bar takes String* so you call it (.bar (Foo.) "a" "b" "c") where actual varargs looks like (.bar (Foo.) (into-array String ["a" "b" "c"]))
it needs an array
oh - that method can also take List
and a clojure vector is a List, so that's the easier way to do it
in any case, Clojure can't figure out what to do with the arg, type-wise, so it can't match a method. yeah?
the type doesn't match anything defined for the method, and clojure doesn't do very much implicit type coercion to match methods
Doesn't it also take a String? Or does the ... arguments
in java.lang.String... arguments
mean that it is still a varargs?
pretty much "try Int or int or long if passed a Long"
@john it doesn't have a non-optional string arg
so it can only take strings via varargs
@mobileink java wouldn't really help you coerce arg types to match a method either iirc, I think it's just a vm thing (except varargs, the java compiler is much more friendly about that)
@noisesmith and it is the ... arguments
in the signature that tells you it must take the strings via varargs?
Foo... means 0 or more foos, all are varargs
you are parsing it wrong, it's String... (named "arguments")
the ... parameterizes String
exactly
or, even more specifically, a String array (an array of Object wouldn't work, even if it had Strings in it)
and an array is always 0 or more items
one of the first probs i had starting with clojure: calling a java method that takes varargs. into-array did the trick.
noisesmith: more precisely: String... means "java arrayof 0 or more strings"?
@nimblerabit any luck?
Yes, I got it working. Whoever said I needed to put the arguments in a vector was correct, that fixed it.
@nimblerabit it takes two types of arg - List (which is matched by a vector) or var strings (which works with into-array)
but yeah, the vector is definitely the way to go
So I understand the list one (in fact I had tried using a list myself, didn't realize it needed to be a vector), but I don't get the var strings
How did you know that's what it took, and what does the syntax to do that look like?
varargs are implemented on a vm level as an array
(into-array Foo [list of foos])
Foo being the type that the varargs asks for
ohhhhhhh
This makes sense now, thanks a ton for the help
varargs is extremely confusing to a newbie T_T
yes, it is. Have you looked at the http://clojure.org doc page on interop? it's well written
oh wow - it doesn't mention arrays for var args - I think it should
Yeah I did read that page, didn't see any var arg stuff there. Luckily you were here! Thanks again for the help
@ggaillard Thanks! If I don't use (seq a-seq)
the first element of the result becomes a vector, for example (tails [1 2 3 4]
becomes ([1 2 3 4] (2 3 4) (3 4) (4) ())
. The test cases require that all the results are inside parens.
Ah ! Didn't thought about this one! I only tried with quoted lists like (tails '(1 2 3 4))
so I missed it.