This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-06
Channels
- # bangalore-clj (2)
- # beginners (24)
- # boot (18)
- # cider (21)
- # cljs-dev (11)
- # clojars (3)
- # clojure (99)
- # clojure-brasil (1)
- # clojure-dusseldorf (2)
- # clojure-france (9)
- # clojure-greece (3)
- # clojure-russia (1)
- # clojure-spec (5)
- # clojure-uk (5)
- # clojurescript (205)
- # core-logic (2)
- # cursive (24)
- # datomic (13)
- # figwheel (1)
- # gsoc (1)
- # jobs (1)
- # jobs-discuss (7)
- # lambdaisland (5)
- # leiningen (4)
- # om (2)
- # pedestal (2)
- # proton (2)
- # re-frame (7)
- # reagent (5)
I’m trying to take 7 from a shuffled vector and put it into another vector
Is (into [] taken_list) the only way to do this?
you can also put the take into the into call (into v2 (take 7) (shuffle v1))
where v2 is the destination, and v1 is the source
v2 can be [], but can be any collection you like
sometimes macros just feel a little toxic, to the lisp neophyte writing this message at least > java.lang.RuntimeException: Can't take value of a macro
macros aren't first class because they emit code, and clojure isn't interpreted it's compiled. If you need it you can use #(or %1 %2)
, or even (reduce #(or %1 %2) false coll)
@matan once again it's about short-circuiting, or couldn't short-circuit evaluation if it weren't a macro, and how can you pass something to a function first class that changes the evaluation rules at runtime (in compiled code at least...)
noisesmith: this is still somewhat a source of perplexity to me. Of course practically can always every?
on collections.
As to a lisp being unable to change evaluation at runtime, I observe that the clojure if
is not a macro but a special form.
and special forms are even more restrictive than macros
they include all the restrictions on macros, plus more (since they aren’t even defined via the lisp layer)
and yes, you can use every? on a collection, and if it is lazy you can kind of short circuit, but laziness as a way of controlling side effects is a bad idea. For example many collections are chunked, which means elements are always realized one group of 32 at a time.
@timok same way as a regular repl, using require and then in-ns
guys how did you learn functional programming? what's your way of doing things? find blogs/tutorials and hack your way on that or read books?
@lepistane My way was to read two books about clojure, try web stuff in clojure and at the same time soak up everything I found in the internet about functional programming
@lepistane The first was: http://shop.oreilly.com/product/0636920013754.do then I think I bought the book on recipes for functional programming. I also read a book about clojurescript and clojure for machine learning later.
but that was more than three years ago, I am not up to date what would be a good fit now
my guess same books. clojure doesnt seem to change much. it doesnt reinvent itself all the time. thank you
joy of clojure is more advanced, but an excellent book