This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # 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
You might think "If a-seq is nil, then (cons a-seq …) will fail." but the
(defn tails [a-seq] (if (empty? a-seq) (cons '() a-seq) (cons a-seq (tails (rest a-seq)))))
(empty? a-seq)will prevent it, because
(empty? nil) ;; => true
if you want to have some fun, you can write
But a loop/recursion-based implementation would be better if you care about performances or stack overflows 😉
(def inits (comp (partial map reverse) reverse tails reverse))
@noisesmith I took the habit to quote list literals to distinguish them from calls, I didn't knew it worked. Thank you !
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");
(doto (ChromeOptions.) (.addArguments "start-maximized"))
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)
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
@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"]))
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?
@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?
or, even more specifically, a String array (an array of Object wouldn't work, even if it had Strings in it)
one of the first probs i had starting with clojure: calling a java method that takes varargs. into-array did the trick.
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)
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?
yes, it is. Have you looked at the http://clojure.org doc page on interop? it's well written
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.