Fork me on GitHub
#clojure
<
2022-06-21
>
jumar07:06:32

I created a couple of new channels • #performance#idioms Please join if you are interested!

🎉 6
plexus13:06:35

You might want to cross post in #new-channels

pinkfrog13:06:06

Looking at the source of clojure.zip, https://github.com/clojure/clojure/blob/35bd89f05f8dc4aec47001ca10fe9163abc02ea6/src/clj/clojure/zip.clj#L32

{:added "1.0"}
  [branch? children make-node root]
    ^{:zip/branch? branch? :zip/children children :zip/make-node make-node}
    [root nil])
It uses metadata to store the information such as branch function and such. Isn’t using defrecord to define a newtype to be more straightforward?

Ferdinand Beyer13:06:46

defrecord was added in 1.2, zip in 1.0 🙂

Ed13:06:49

clojure.zip predates defrecord iirc

pinkfrog13:06:56

If it were written today, is using meta still a more sensible choice compared with defrecord?

Ferdinand Beyer16:06:09

Hard to say. Actually my first approach would be to just use a map. But other than Rich I did not study any literature on zippers, maybe it is more natural to represent it as a tuple?

Ferdinand Beyer16:06:17

The zipper structure seems to have two aspects: “Static” definition functions, stored in the metadata, and a state/cursor in the tree. The metadata never changes. So this could be an elegant solution, and allows you to print the “state” without the clutter (metadata)

chrisblom21:06:08

Not sure if metadata would be the way to go if clojure.zip were written now, it is not the most performant solution. There are several alternative zipper libraries based on deftype with better perf, like https://github.com/akhudek/fast-zip

plexus05:06:39

I don't think there's really a consensus about what you should and shouldn't do with metadata. I wouldn't say this is typical, and as pointed out there are more performant ways to do this now. Metadata is always a bit of a gray zone... It can be a convenient escape hatch, but a bunch of caveats apply.

pinkfrog13:06:35

@U07FP7QJ0 Unrelated to this, and a little bit off topic. I watched the clojure.zip video you presented back in 2018. Great presentation skills. Any advice/recommendation on how to practice these skills?

plexus13:06:04

Oof that's a tough one... I've been doing these things for so long. Local user groups are great for practicing presentation skills. Even better if you can get a more experienced speaker to help you prepare and give feedback.

pinkfrog13:06:03

I think so. Reading books might not help, only first-hand practice makes a more difference.

plexus13:06:13

Yeah I can really recommend finding a mentor, I've been part of some conferences that assign a mentor to each speaker. They help brainstorm the talk, help structure the slides, and then finally provide a test audience that can give you feedback. All of those kinds of input are valuable.

plexus13:06:04

The other tip I would give you is to practice your presentations out loud. Stand up, grab your clicker, and just do the talk for yourself, many, many times.

thanks3 1