Fork me on GitHub
#clojure
<
2023-01-10
>
teodorlu13:01:12

is https://clojure.atlassian.net/browse/CLJ-2123 the closest we have to reference documentation on how :as-alias works right now?

p-himik13:01:05

There's a docstring for require.

๐Ÿ‘ 2
teodorlu13:01:49

including that excerpt from (doc require) here in case others are curious:

> (doc require)
...
  Recognized options:
  :as takes a symbol as its argument and makes that symbol an alias to the
    lib's namespace in the current namespace.
  :as-alias takes a symbol as its argument and aliases like :as, however
    the lib will not be loaded. If the lib has not been loaded, a new
    empty namespace will be created (as with create-ns).
  :refer takes a list of symbols to refer from the namespace or the :all
    keyword to bring in all public vars.

teodorlu13:01:49

and here's a small example.

$ clj
Clojure 1.11.1
user=> (require '[nextjournal.clerk :as-alias clerk])
nil
user=> clerk/serve!
Syntax error compiling at (REPL:0:0).
No such var: clerk/serve!
user=> ::clerk
:user/clerk
user=> ::clerk/thing
:nextjournal.clerk/thing
user=> `clerk/thing
nextjournal.clerk/thing
1. :as-alias was introduced in Clojure 1.11 2. vars are not available 3. but namespaced keywords and sharp-quoted symbols resolve their namespace

Alex Miller (Clojure team)14:01:40

I added a doc issue to expand coverage on clojure site https://github.com/clojure/clojure-site/issues/632

๐Ÿ‘ 4
Nundrum15:01:15

Is there a rule/guide on how large is too large for an atom?

Alex Miller (Clojure team)15:01:04

not sure "large" (size) is relevant

Alex Miller (Clojure team)15:01:27

granularity or "complexity of update" is probably more relevant

Nundrum15:01:42

Ok, good. I was hoping that was the case.

Alex Miller (Clojure team)15:01:31

atoms protect updates to state so there is a tradeoff in granularity / amount of state vs contention to update - that's usually the important thing to consider

Nundrum15:01:53

The updates should all be happening within my Clojure2d drawing thread. I don't expect contention there.

dpsutton15:01:04

@U02UHTG2YH5 what are you putting into your atom that you thought perhaps size would be an issue?

Nundrum15:01:27

All the state needed to draw the frames.

borkdude15:01:55

atoms store only 1 thing, that's the size ๐Ÿ˜‚

Nundrum15:01:09

The largest is probably a set of lines to draw, usually 20ish lines. And then 30 of those sets.

Alex Miller (Clojure team)15:01:25

I would start with one thing until that's not sufficient :)

โ˜๏ธ 2
dpsutton15:01:59

Another point. Size kinda doesnโ€™t matter. But one thing that tracks with size is the number of code paths that try to update the atom because it holds all the data. If 15 threads all hit the atom and change independent parts, you can get into high contention. But by itself the size of the data in the atom is irrelevant.

๐Ÿ‘ 2
Nundrum15:01:29

Thanks, everyone

Alex Miller (Clojure team)15:01:56

and the two main techniques for dealing with it once it's not sufficient are changing atom of map --> map of atoms (for uncoordinated state) or map of refs (for coordinated state)

fabrao19:01:12

is anyone having problems with nvd-clojure?

vemv19:01:00

It has an issue tracker :) I will push the necessary update tonight

vemv19:01:16

Was sick in bed for a few days ๐Ÿ˜ž

fabrao19:01:05

oh, sorry I didn't know that

fabrao19:01:34

best health recovering. Thank you

โค๏ธ 2
fabrao23:01:49

thank you, I'm going to try now

fabrao23:01:45

๐Ÿคž

skuro20:01:28

this was actually surprising:

user> {(random-uuid) 1 (random-uuid) 2}
Syntax error reading source at (REPL:146:66).
Duplicate key: (random-uuid)

escherize22:01:33

(let [r #(rand-nth [1 2 3 4 5 6])]
  {(eval (r)) 1 (r) 2})
thisisfine

jumar04:01:32

I guess it's just better to use hash-map in that case

(hash-map (random-uuid) 1 (random-uuid) 2)

ghadi20:01:11

it's an excellent error message, IMO

ghadi20:01:51

(because it tells you that it happened during the read phase, before the compiler attempts to evaluate forms.)

skuro20:01:03

as far as error messages go, I agree with you ๐Ÿ™‚

ghadi20:01:59

I agree that it is somewhat surprising. most langs don't have map literals, and those that do often have restrictions on the key forms

bronsa21:01:23

it's a testament to clojure being truly homoiconic ๐Ÿ™‚

โค๏ธ 2