Fork me on GitHub
#cursive
<
2016-11-23
>
roelofw08:11:38

Is there a way I can debug this reduce code :

((fn [s] (reduce (fn[acc n] (if (not= n (last acc)) (conj acc n))) [(first s)] s )) [1 1 2 ]) 

roelofw08:11:26

Im expecting that acc is a vector but when I use conj the new entries are placed at front instead of at the end

bfabry08:11:42

((fn [s] (reductions (fn[acc n] (if (not= n (last acc)) (conj acc n))) [(first s)] s )) [1 1 2 ]) => ([1] nil (1) (2 1))

bfabry08:11:56

so acc is [1], then nil (here's the problem), then (1) then (2 1)

roelofw08:11:52

Thanks, never knew that reductions exist

bfabry08:11:05

handy function 🙂

roelofw08:11:10

it seems that I need a else

rauh08:11:04

If you still want to learn how to debug: Break up the function into multiple lines, then set a breakpoint, and then start the debugger with cursive (in the cursive docs)

roelofw08:11:49

I did , but I could not find out how to see it

roelofw08:11:14

but I found another way , use reductions

rauh08:11:20

Yes I see, that'll safe you this time, but it might be better for you to learn the debugger for future problems

Pablo Fernandez17:11:59

Debuggers shouldn’t be line based with a language such as Clojure.

yonatanel19:11:18

@roelofw Or try Sayid for tracing everything: http://bpiel.github.io/sayid/

roelofw19:11:26

@yonatanel Thanks for the tip

katox23:11:38

@pupeno I remember NetBeans having expression based debugging for about a decade, maybe JetBrains should start to think about it as well

Pablo Fernandez23:11:56

@katox really? I never seen an expression based debugger before and I’ve been telling people that’s how it should work for a decade or so… well… since I started playing with Lisps, were lines are not that meaningful. JetBrains tend to be very responsive, so, we should probably ask. But I’d like to as @cfleming if IntelliJ IDEA support is necessary or is it just a Cursive thing.

katox23:11:24

@pupeno I think it was something more limited - like setting a line breakpoint + you could "step over" individual expressions. Still better than a full line which is a lot in Clojure.