Fork me on GitHub
#clojure
<
2018-12-02
>
sova-soars-the-sora05:12:59

is there a name for a map indexed by ID

sova-soars-the-sora05:12:48

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

macrobartfast07:12:28

just a reminder it's the start of the Advent of Code https://adventofcode.com/

clj 4
orestis07:12:38

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

kulminaator11:12:46

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

kulminaator11:12:20

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 😞

eraserhd15:12:35

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

eraserhd14:12:43

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

dangercoder15:12:19

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.

dangercoder15:12:35

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

valerauko15:12:01

why not use spec for that?

dangercoder15:12:16

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

dangercoder15:12:41

aka with Instrumentation on

valerauko15:12:47

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

valerauko15:12:55

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

valerauko15:12:15

at least that's how i feel about it

dangercoder15:12:03

thank you for the advice @vale

shaun-mahood15:12:30

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

shaun-mahood15:12:13

@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

dangercoder17:12:18

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

💯 4
dangercoder19:12:26

Also going to have a look at https://github.com/bhb/expound, but before that I will check out Spec in Clojure 1.10.

slipset17:12:40

Am I wrong in being surprised by this?

slipset17:12:43

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

slipset17:12:28

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

noisesmith17:12:25

contains? only checks indexes

noisesmith17:12:00

lists don't have indexes

noisesmith17:12:39

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

noisesmith17:12:49

the docs are clear about this

:user=> (doc contains?)
-------------------------
clojure.core/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'.
nil

noisesmith17:12:39

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

mpcarolin22:12:36

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.

lilactown22:12:46

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

lilactown22:12:54

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

mpcarolin22:12:36

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

lilactown22:12:13

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

lilactown22:12:12

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

lilactown22:12:59

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

lilactown22:12:44

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

mpcarolin22:12:41

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

andrea.crotti23:12:26

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

andrea.crotti23:12:42

Useful when you rename tests for example

mpcarolin23:12:46

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
devn23:12:17

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

devn23:12:02

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

devn23:12:11

but i wondered about classfile generation, aot, etc.

noisesmith16:12:10

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

dpsutton23:12:17

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

devn23:12:38

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

devn23:12:26

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

devn23:12:44

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 😄

devn23:12:10

funny/sick/convenient/however-you-wanna-think-about-it

dpsutton23:12:12

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

victorb00:12:21

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 https://www.reddit.com/r/adventofcode/comments/7idn6k/question_why_does_the_difficulty_vary_so_much/dqy08tk/ cc @U06DQC6MA

devn23:12:44

thanks for the heads up

ackerleytng23:12:36

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

noisesmith16:12:17

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?

noprompt16:12:10

You can look at the meta

(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[clojure.zip/seq-zip/fn--9294]}

👍 4
noprompt16:12:04

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. 🙂

noisesmith17:12:03

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

noisesmith17:12:29

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