Fork me on GitHub
#beginners
<
2016-04-12
>
dancrumb01:04:45

so, I have the following form in some code I wrote:

(let [[rightOperand operands] (pop operands)]
     (let [[leftOperand operands] (pop operands)]
           (recur operators (push operands ( list operator leftOperand rightOperand)))
     ))

dancrumb01:04:39

is this pattern of nested lets a code smell or a common pattern?

dancrumb01:04:50

FWIW: (defn pop [c] [(first c) (rest c)])

donaldball01:04:30

It’s not common; let forms allow multiple bindings that are evaluated in order and can refer to prior bindings

donaldball01:04:44

The rebinding of operands might be confusing, but it could be a reasonable choice

dancrumb01:04:18

so

(let [[rightOperand operands] (pop operands)
[leftOperand operands] (pop operands)] … )

dancrumb01:04:32

would be OK?

dancrumb01:04:51

in this case, the rebind makes sense… i’m trying to implement the pop off a stack

dancrumb01:04:59

so returning the popped value and the new stack

dancrumb01:04:23

thanks, by the way simple_smile

donaldball02:04:17

Yeah, that should work

dancrumb02:04:35

working through Clojure for the Brave & True and finally completed the infix->prefix converter in Chapter 7

zzamboni09:04:02

@dancrumb: that was the hardest exercise so far for me 😉 I even had to look up the shunting-yard algorithm

dancrumb14:04:16

@zzamboni: yeah! i’d actually heard of the algorithm and dug out a really nice SO answer that described it. implementing it was… interesting… but really satisfying once i got there

dorab21:04:48

crontab l