This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-22
Channels
- # arachne (8)
- # bangalore-clj (1)
- # beginners (72)
- # boot (95)
- # braveandtrue (5)
- # business (1)
- # capetown (1)
- # cider (180)
- # cljs-dev (8)
- # cljsrn (20)
- # clojure (104)
- # clojure-art (1)
- # clojure-brasil (8)
- # clojure-czech (1)
- # clojure-greece (15)
- # clojure-korea (13)
- # clojure-poland (2)
- # clojure-russia (53)
- # clojure-sg (5)
- # clojure-spec (60)
- # clojure-uk (35)
- # clojurescript (186)
- # community-development (3)
- # core-async (24)
- # cursive (18)
- # datascript (11)
- # datomic (39)
- # devcards (4)
- # emacs (2)
- # events (1)
- # funcool (23)
- # hoplon (148)
- # juxt (1)
- # ldnclj (2)
- # luminus (1)
- # off-topic (22)
- # om (27)
- # onyx (35)
- # overtone (2)
- # pedestal (7)
- # perun (8)
- # protorepl (2)
- # rdf (6)
- # re-frame (15)
- # reagent (2)
- # ring-swagger (10)
- # untangled (54)
Is this a good tutorial of doing first steps on compojure : https://kendru.github.io/restful-clojure/2014/02/19/getting-a-web-server-up-and-running-with-compojure-restful-clojure-part-2/
(take 3 [8 2 6 3 0 0 0 9 0])
will return the first three numbers of a vector - how would I do the same for the middle three numbers?
for now I’ve put it down as a function - pretty happy with this but any 2 cents will be appreciated 🙂
(defn take-at-point [point n col]
(take n (last (split-at point col))))
(take-at-point 3 3 [8 2 6 3 0 0 0 9 0])
@roelofw the best thing that I have done to make webapps in clojure and learn is to run lein new compojure <appname>
then when something advocates a different way, you might be in a position to evaluate if you think that that is good advice based on experience
but you can always learn from tutorials, even if you learn that that style/technique is bad, etc
@mikepjb I would combine drop
and take
:
(take 3 (drop 3 [8 2 6 3 0 0 0 9 0]))
Though if your input list is very long, and you know it’s a vector (as opposed to some kind of sequence), subvec
is better, since drop
actually reads through (and discards) the first N values.
subvec is O(1) b/c it just creates a view on the original vector, so prob preferred a) if you are using only vectors and b) you understand that this can potentially cause memory problems (as the full old vector is still reachable as live objects)
okay thanks @tokenshift and @alexmiller I haven’t come across subvec
before
@alexmiller I didn’t realize subvec
kept the original vector around (though that makes sense, since everything’s immutable); thanks.
Is there a good way to duplicate (part of) a sequence to break that link?
Like (dup (subvec [8 2 6 3 0 0 0 9 0] 3 6))
, returning a new sequence (no longer a view of the input vector)
I suspect calling vector
on the result would do the trick, not sure how to test that though.
you could apply vector to it
(but not vec
- that optimizes by just returning what you give it if it satisfies)
I had to re-implement range :
(fn [begin end] (take (- end begin) (iterate inc begin)))
. How can I improve this one ?I could , but the 4clojure challenge gives a starting point which can be other then zero
@roelofw if you need to view something quickly, you can message the cljbot from your direct message with slackbot
(map str '(\a \b \c))
I have to delete duplicates in a seq so ( "aaabbbccc") will be ("abc"). I thought about using set but I think I can better use another approach
I don’t think 4clojure is using a new enough version of Clojure, but there is now dedupe
user=> (dedupe "aaabbbccc")
(\a \b \c)
@alexmiller thanks, why do I see this error message : ClassCastException java.lang.String cannot be cast to clojure.lang.IFn user/eval1496 (form-init1114920531766215249.clj:1)
after the right answer
looks like you’re using a list with a string as the first element and it’s trying to invoke it
If you copied the (”a” “b” “c”) part, that was the result, not part of the answer
and it would yield that
if you want to see it rewritten, use macroexpand: (macroexpand '(->> “aaaaaabbbbbbbcccccc” seq distinct (map str)))
@alexmiller I think I see another macro : (clojure.core/->> "aaaaaabbbbbbbcccccc" clojure.core/seq clojure.core/distinct (clojure.core/map clojure.core/str))))
Well, that's not what i get :)