Fork me on GitHub

is there a name for a map indexed by ID


(atom {33 {:id 33, :contents "hax", } 77 {:id 77, contents "ham"}})


just a reminder it's the start of the Advent of Code

clj 4

And also #adventofcode 🙂 Also the Zulip channel allows for discussion of spoilers in a spoiler-free manner!


is there some compiler option that i can teach to leiningein to make redef's within the same file a hard error ?


looked around like an idiot for 10 minutes since i managed to be an idiot in the first place and redefined a test dataset creation in my test 😞


It appears that graal vm doesn’t like the bytecode generated by the locking macro. Can anyone think of a work-around? The best I can think of is a Java helper method.

Alex Miller (Clojure team)15:12:36

there is an old ticket for this that has been through several rounds of discussion (also an issue on dalvik)

Alex Miller (Clojure team)15:12:42

there’s a newer suggestion on there that I think is worth more investigation


Oh, neat. I vaguely remembered this ticket. Let me see if there's anything I can add there.

Alex Miller (Clojure team)15:12:49

testing the approach there with graal and reporting your findings would be super helpful


Do you guys use custom functions to validate data structures (such as parameters from http-request?) I write my own right now, wondering if there are any popular libraries being used.


Not thinking about a schema/spec, but more of a way to say "Password too short".. etc


why not use spec for that?


I always though spec was supposed to "run" during development/testing mode and not in production due to performance


aka with Instrumentation on


of course you're not supposed to instrument everything in prod


but using spec to validate input is what it's for


at least that's how i feel about it


thank you for the advice @vale


Have any of the core data structures been extended with datafy in RC2? If not, is that planned for the final release of 1.10?

Alex Miller (Clojure team)15:12:50

@jarvinenemil you could use spec for validation in this way. if I was going to NOT use spec, I’d probably look at truss which is really just a lot of macro goo to make it easier to write assertions

Alex Miller (Clojure team)15:12:08

@shaun-mahood there are some changes in core, no plans to add more

Alex Miller (Clojure team)15:12:34

note that datafy is not needed if the response is already Clojure data

Alex Miller (Clojure team)15:12:53

so the core data structures don’t need “datafication” - they just fall back on identity

Alex Miller (Clojure team)15:12:55

there are built-in extensions in core though for Throwable, Class, IRef, Namespace

Alex Miller (Clojure team)15:12:43

IRef covers vars, atoms, refs, agents

Alex Miller (Clojure team)15:12:08

happy to take tickets if you think of something else interesting


@alexmiller Oh fantastic - I’ll play with it and see if I can figure it out. Couldn’t get nav working on nested vectors yesterday so I guess I’ll have something to play with on the plane ride home :)

Alex Miller (Clojure team)15:12:13

shouldn’t need anything special for nested colls, but please do let us know if something seems wrong


@alexmiller @vale utilizing spec/valid? solved the problem nicely for me ✌️

💯 4

Also going to have a look at, but before that I will check out Spec in Clojure 1.10.


Am I wrong in being surprised by this?


user> (= (vals {:a 1}) [1])
;; => true
user> (contains? [1] (vals {:a 1}))
;; => false
user> (contains? (vals {:a 1}) [1])
Execution error (IllegalArgumentException) at user/eval3846859 (REPL:1408).
contains? not supported on type: clojure.lang.APersistentMap$ValSeq


probably. The main point is that contains? doesn’t work on lists.


contains? only checks indexes


lists don't have indexes


+user=> (contains? [:a :b :c] 1)
+user=> (get [:a :b :c] 1)


the docs are clear about this

:user=> (doc contains?)
([coll key])
  Returns true if key is present in the given collection, otherwise
  returns false.  Note that for numerically indexed collections like
  vectors and Java arrays, this tests if the numeric key is within the
  range of indexes. 'contains?' operates constant or logarithmic time;
  it will not perform a linear search for a value.  See also 'some'.


there's a good argument the name is easily misleading, but that ship's sailed


Does anyone have any recommendations for keeping the REPL state clean? By clean I mean not polluted with old references to functions and vars. I semi-frequently find myself baffled at why a program isn’t working, only to discover it is because one function somewhere is out of date. Should I just be refreshing my repl regularly? Or are there any tools that help with this? I currently use Atom’s proto-repl.


Hmm. I haven't used proto-repl much. I find CIDER does a pretty good job by letting me evaluate a whole ns in the REPL, which covers the 80% case when my REPL is out of date


Anything past a simple program I usually reach for something like mount to handle the stateful parts of my app though


Hmm, maybe there is a full namespace refresh command that I just overlooked somewhere. What do you mean by mount?


Mount is a library for creating reloadable states that depend on each other


E.g. i can run mount/start and it will start my http server, db connection pool, and read my config files


Reloading those parts of my app after a change is just (mount/stop) (mount/start)


There are many different libraries for doing this. I like mount because it's pretty easy to setup


interesting, I’ll take a look at that. I like the idea of specifying exactly what happens with the state on a refresh


I sometimes just evaluate a ns-unmap to remove something from a namespace in case it was renamed


Useful when you rename tests for example


Good to know! I figured out what my problem this time; I was doing a full namespace refresh, but I just wasn’t seeing a small error thrown early in the file that prevented the rest of the namespace from being evaluated. one function was calling another further down the file, so it hadn’t been declared yet.

👍 4

is src/myproject/1.clj with an ns of myproject.1 valid?


i mean, i jacked in and declared it and all, and that seems fine


but i wondered about classfile generation, aot, etc.


I'd expect AOT and clasffile generation to fail. Luckily you don't need those things.


that's the way my advent project is set up and so far no worries. although i named it 01 so they would sort well


im not planning on deploying this, but wondered if there were any implications


do you know @dpsutton if these problems get harder as time goes on?


i wondered because i think it's kind of funny to make the problems more and more time consuming as people approach time they're supposed to be spending with their families 😄




yes the problems will get harder. if you're not already in #adventofcode you should join


depends on the person 🙂 The puzzles don't actually get harder and harder (if that's what you meant). The author wrote about the difficulty here cc @U06DQC6MA


thanks for the heads up


is there any way of checking if something is a clojure zipper? I'm new to zippers and i seem to keep using zip functions on things that are not zippers


if you look at a zipper it's "just" a hash-map with a specific set of keys. I guess you could make a function that validates that the expected keys are present?


You can look at the meta

  (zip/seq-zip '(1 2 3 (1 2 3))))
;; =>
#:zip{:branch? #function[clojure.core/seq?--5391],
      :children #function[clojure.core/identity],
      :make-node #function[]}

👍 4

You could also check a thing is a vector? with a second element that’s a map? with the keys #{:l, :pnodes, :ppath, :r} but I think the former solution is easier. 🙂


I didn't know about checking the metadata - if you look at what seq-zip returns before you do any traversal, it's just the input followed by nil, so that wouldn't be something you can reasonably test for anyway


so clearly checking the metadata is the reliable thing (or the keys on the metadata, since it's still just a hash-map)