This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-16
Channels
- # babashka (53)
- # beginners (61)
- # biff (2)
- # cherry (15)
- # cider (28)
- # clj-kondo (17)
- # clojure (57)
- # clojure-europe (27)
- # clojure-nl (13)
- # clojure-norway (6)
- # clojure-uk (4)
- # clojurescript (30)
- # core-async (2)
- # data-science (39)
- # datomic (16)
- # docker (34)
- # emacs (4)
- # events (1)
- # figwheel-main (9)
- # guix (5)
- # hiccdown (2)
- # honeysql (5)
- # hyperfiddle (5)
- # interceptors (1)
- # jobs (2)
- # joyride (5)
- # lsp (36)
- # midje (1)
- # minimallist (1)
- # nbb (21)
- # off-topic (45)
- # polylith (42)
- # rum (1)
- # shadow-cljs (24)
- # sql (1)
- # squint (62)
- # vrac (1)
- # xtdb (6)
posted another idea: https://github.com/clavascript/clavascript/issues/22#issuecomment-1216104130
@lilactown @corasaurus-hex I wonder if we should "beautify" the names a bit so core.js
can also be used from other JavaScript projects without typing assoc_BANG!
- I'm just not sure what a proper name for it would be :)
maybe put mutable and immutable under different namespaces?
hmm no then we're just pushing that choice off onto the user
One realization I had later is that using the munged names is actually good if you want to use this stuff from CLJS
I'm not super clear on why?
oh, and it knows how to handle the BANG and underscores. cool
but also... why would you want to use that from cljs?
to work with js structures directly I guess?
yeah, this issue is probably not that important, the primary use case for the lib is to be used from clavascripts...
makes sense, thanks for explaining:)
@lilactown Looking at your PR for a couple of hours now.. Running into this problem: https://clojurians.slack.com/archives/C03S1L9DN/p1660637617050799
I think I might know what's going on, perhaps. It's a weird interaction between advanced compilation and this PLUS function that was added, but perhaps maybe only in the test build...
Instead of 1 + 2 + 3
the compiler now generates 1 _PLUS_ 2 _PLUS_ 3
as if the stringified symbol is optimized to the munged version
i was wondering how special form and function collisions would work. i was happy to see that it both generated infix when it could and used the function when passed as a value in test
found a cute way of getting a "REPL"
echo '' | fzf --print-query --preview './node_cli.js --show -e {q}'
h/t @rayatrahman9 for the fzf life pro tipwell, more like a read-eval loop. still figuring out how to wrap the {q}
in a println
I made it a bit better. showcase: https://asciinema.org/a/at6Gv9D2FfK7S5BeChRlyq9hw
Link to gist or something?
We can extract the preview code to a script that can print something prettier if the code has an error, or something that colors the output if the user has bat
, etc installed
yeah, this was what I ended up going with https://gist.github.com/lilactown/11027faf1f48408e9861be9aed2abc52
Just for fun:
brew install bat
echo '' | fzf --preview './read-eval-print {q}
*| _bat -l javascript_*' --preview-window
Lmk if that looks interesting to ya
I don't really have an opinion on it (I know, I'm helpful)
it would be nice if we could add syntax literals for js maps
there's #<key val>
or #[key val]
or maybe something else?
it's such a pain point
I know I'd use more maps in js if they weren't such a pain to use
a syntax like this might be nice Map#{ key val }
https://esdiscuss.org/topic/map-literal is a very old thread of people talking about map literals for js. it's interesting
I suppose it could just be a macro at that point, really. I just hate (js/Map [[key1 val1] [key2 val2] [key3 val3]])
@corasaurus-hex I'd like to learn more about what people are using Maps for instead of objects. Can you share?
I think we could have a reader macro like #js/map {:k v}
or just #map {:a 1}
or so. Technically this isn't hard, but it's good to discuss stuff to make an informed decision on that
maps are used when you need to use non-string keys, mostly. objects have all sorts of pitfalls around keys like automatic conversion to strings and the potential for prototype pollution, too
> a = {}
{}
> a[1] = 2
2
> a
{ '1': 2 }
> b = new Map()
Map(0) {}
> b.set(1, 2)
Map(1) { 1 => 2 }
> b
Map(1) { 1 => 2 }
I'm just breezing through some calva code realizing that there are probably instances that would be vulnerable to prototype pollution due to the use of objects instead of maps 😬
So, most JS APIs work with objects right? Are you using Maps for like say, internal app data?
yes, exactly that
like in clojure you mostly use maps with string or keyword keys but sometimes you need lookup maps using keys that aren't either of those
(bad example probably since you don't look up arrays by equality but by reference, but just for the idea)
I think #map { key1 val1 key2 val2 key3 val3 }
if that's what you mean
and like you just hinted, you need to be really careful with reference equality
in one of my recent projects we hand-rolled a deep-equals map
we have lodash, but it doesn't give you a deep-equals map (where the keys are compared with deep-equals)
we use isEqual in there
it's gross but it gets the job done (for sufficiently small maps where this nonsense isn't too expensive)