Fork me on GitHub
#beginners
<
2019-10-27
>
coder4633418:10:11

Hi everyone! I'm trying to wrap my head around zippers, and it appears that a node can either have 1) a value or 2) children. Therefore this throws an error:

(-> (z/vector-zip [1 2 3])
    (z/down)
    (z/insert-child [7 8 9])
    )
Is there a way to have a node a value AND children? (Maybe some other type of tree structure?)

coder4633421:10:48

I figured it out - instead of using vector-zip I create a custom zipper

Vachi19:10:29

is (future) a sort of async - await?

futuro22:10:33

@vachichng yeah, pretty much. Throw some code in a future, store the value returned by the call to future, then dereference it once you need the value.

Vachi22:10:53

how do you name them? in order to avoid missing derefs

futuro22:10:42

I generally name them after the thing I hope to get back from them.

futuro22:10:29

So something like acct-balance for the name, and @acct-balance when I want to get the value out.

Vachi22:10:50

yeah I mean, do you give it a prefix or something when declaring the binding ? like (def acct-balance (future (get-balance "asd"))

Vachi22:10:16

in that case, later in the function I could forget to deref acct-balance and trigger bugs

futuro22:10:45

It wouldn’t be in a def, since that would be top level. Instead, it’d be in a let binding inside a function.

futuro22:10:17

Since the function where it’s being used is small, I can see that it’s a future.

Vachi22:10:27

ok, so , limit the scope of the binding thank you!

futuro22:10:11

If I have the pass the value off, I’d either deref when calling the next function, or append -future to the parameter name inside the function I’m calling.

futuro22:10:19

Yep, exactly!