Fork me on GitHub
#beginners
<
2017-05-06
>
camdenclark04:05:38

I’m trying to take 7 from a shuffled vector and put it into another vector

camdenclark04:05:56

Is (into [] taken_list) the only way to do this?

noisesmith04:05:53

you can also put the take into the into call (into v2 (take 7) (shuffle v1))

noisesmith04:05:01

where v2 is the destination, and v1 is the source

noisesmith04:05:42

v2 can be [], but can be any collection you like

matan09:05:41

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

matan09:05:11

don't we have simple logical or in clojure after all?

noisesmith12:05:58

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)

noisesmith13:05:11

@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...)

matan09:05:49

noisesmith: this is still somewhat a source of perplexity to me. Of course practically can always every? on collections.

matan09:05:29

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.

noisesmith15:05:38

and special forms are even more restrictive than macros

noisesmith15:05:07

they include all the restrictions on macros, plus more (since they aren’t even defined via the lisp layer)

noisesmith15:05:17

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.

timo13:05:16

how do I load a namespace from repl figwheel? any resources to read on repl/figwheel?

noisesmith13:05:43

@timok same way as a regular repl, using require and then in-ns

lepistane17:05:04

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?

sveri17:05:17

@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

lepistane17:05:59

@sveri thank you for reply. which 2 books if i may ask?

sveri17:05:54

@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.

sveri17:05:19

but that was more than three years ago, I am not up to date what would be a good fit now

lepistane17:05:39

my guess same books. clojure doesnt seem to change much. it doesnt reinvent itself all the time. thank you

noisesmith18:05:39

joy of clojure is more advanced, but an excellent book

lepistane18:05:54

so i've heard. are there books that you would recommend that focus on basics like SICP?