Fork me on GitHub
#beginners
<
2017-04-03
>
teodorlu08:04:55

Hello! I'm looking for a way annotate errors without exceptions: Something that evaluates to false and can contain information about why. Any suggestions?

teodorlu08:04:25

Example: a function mk-error that makes this return "nay": (if (mk-error {:message "File not found"}) "yay" "nay")

teodorlu08:04:48

... and still allows accessing :message

teodorlu08:04:58

Or is this a really bad idea?

rauh08:04:02

@teodorlu Don't do that. Bad idea

rauh08:04:18

Just use a error? predicated and call that on your result

rauh08:04:48

Also, you can't. nil and false only evaluate to false and you can't attach data to them. They're constants

teodorlu08:04:54

Just something like (contains? {:error "File not found"} :error)?

rauh09:04:01

@teodorlu Yes, that should be fine

teodorlu09:04:11

@rauh Thanks 🙂

teodorlu13:04:24

Another question. Why use records when we have maps? My gut feeling is that records might be faster in some cases because you can "centralize" the key storage. Thoughts?

Prakash13:04:17

defrecord is definitely faster than a map, among some other differences - https://github.com/plumatic/eng-practices/blob/master/clojure/20130926-data-representation.md

notanon15:04:40

whats the best way to 'subtract' one set from another? I have two lists (or sets or vectors, whatever is easiest) of strings and I want to find items that are in set A but not B

not-raspberry16:04:10

Many functions in clojure.set are garbage-in-garbage-out (types are not checked to minimize bytecode size so JVM considers inlining it even with default settings). Make sure to pass sets where required.

xsyn19:04:06

I miss Prismatic

lepistane19:04:33

What would you recommend to be good read about functional programming and lisps in general for beginners? SICP is great i am doing it right now. i was just wondering what would people here recommend beside that 🙂

schmee19:04:05

it is in F#, but the concepts are general and the explanations are great

roberto19:04:26

That is probably the best FP site out there

roberto19:04:40

I’ve learned a lot from it, and from his talks too.

schmee19:04:22

yeah, they’re all worth watching!

miguelb20:04:42

does anyone have any experience getting custom react components, compiled with webpack working in cljs?

miguelb20:04:13

I’m trying to use foreign-libs but keeps getting compilation errors

miguelb20:04:54

So far I have found out, that compiling js into UMD with webpack was the best way to go but haven’t found either the right webpack config or project.clj config

roberto20:04:43

@miguelb You will probably get answers in the #clojurescript channel

miguelb20:04:10

thanks @roberto, tried that first, didn’t get a response

roberto20:04:48

also, maybe try the #reagent or #re-frame channels

peter.d20:04:15

Are Clojure-mode and cider the 2 basic packages you need to get up and running in emacs? I've installed them both, but I just want to make sure I haven't forgotten anything... 🙂 At least no error messages...

roberto20:04:38

yes, for starters

peter.d21:04:13

excellent 🙂

josh.freckleton22:04:11

Is there a nicer way to write this?

(reduce (fn [c x] (+ c (:a x))) 0
          [{:a 1} {:a 2}])
I was hoping this, but no avail:
(apply (comp + :a) [{:a 1} {:a 2}])

djz22:04:26

@josh.freckleton does that help?

noisesmith23:04:51

it cut off my comment- that's another option

josh.freckleton23:04:08

thanks @djz, that's a start, and I think @noisesmith nailed it, this may be a transduction problem, because then I can compose those transducing fns too

josh.freckleton23:04:25

I feel like I get transducers pretty well, but I need to start seeing when to use them

noisesmith23:04:05

@josh.freckleton I like to ask myself "does this create a lazy seq I never consume?" - if so, there's often a transduce which can replace it

noisesmith23:04:15

never directly consume that is

josh.freckleton23:04:48

you mean I'll never need the list of (map :a ...), so transduce over it?

josh.freckleton23:04:56

does this give an efficiency gain too then?

noisesmith23:04:12

right - same if you see a filter, a concat, etc. in your intermediate calculation that the result doesn't need directly

noisesmith23:04:22

yes - at least a small one

noisesmith23:04:49

I need to make my language more explicit, "there's often a way to use a transducer which can replace the usage of a lazy seq" - it might involve eg. into or core.async/chan or even sequence, where these each use a transducer