This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
Thanks @pez for adding more clojure.set functions. See map-invert
in action https://squint-cljs.github.io/squint/?repl=true&src=KHJlcXVpcmUgJ1tjbG9qdXJlLnNldCA6YXMgc2V0XSkKKHNldC9tYXAtaW52ZXJ0IHs6YSAxfSkKKHNldC9tYXAtaW52ZXJ0IChuZXcganMvTWFwIChzZXEgezphIDF9KSkp
I discovered yesterday that the bloomberg polyfill for TC39 records and tuples makes equality work by interning all immutable objects in a weakmap, so they are really one and the same when you instantiate a second one. Now I get why they say "explicitly not for production" đ
when creating an immutable object, they check if there is already one like it in their weakmap and then return that one, else create it for the first time
a weakmap is a map whose elements can be garbage collected if necessary (when memory runs out)
it's fine for doing AOC puzzles and some other cases, but it's good to be aware of this implementation which is not the most efficient
I think I saw somewhere that Rich Hickey explained a bit how value equality is tested for in Clojure. Canât recall where right now, and not the details either, but I remember it sounded very sensible and efficient.
yes, but the issue in JS is that you can't override =
so I think they didn't have much choice in this polyfill
https://squint-cljs.github.io/squint/?repl=true&src=KGRlZiByZWdpc3RyeSB7fSkKCihkZWZuIHR1cGxlIFt4IHldCiAgKGxldCBbayAoc3RyIHggIiwiIHkpXQogICAgKG9yIChnZXQgcmVnaXN0cnkgaykKICAgICAgKGxldCBbdiBbeCB5XV0KICAgICAgICAoZG8gKGFzZXQgcmVnaXN0cnkgayB2KQogICAgICAgICAgdikpKSkpCgooPSAodHVwbGUgMSAyKSAodHVwbGUgMSAyKSkgOzsgdHJ1ZQoKKGRlZiB0dXBsZS0%2BbmFtZSAobmV3IGpzL01hcCBbWyh0dXBsZSAxIDIpIDpkdWRlICh0dXBsZSA0IDUpIDpmb29dXSkpCihnZXQgdHVwbGUtPm5hbWUgKHR1cGxlIDEgMikpIDs7IGR1ZGU%3D Although I find the API of WeakMap a bit strange and couldn't figure out how to do it with that
btw @pez I found a bug with select
, I'll push a fix shortly
https://squint-cljs.github.io/squint/?repl=true&src=KHJlcXVpcmUgJ1tjbG9qdXJlLnNldCA6YXMgc2V0XSkKCihzZXQvc2VsZWN0IGlkZW50aXR5ICN7MCAxIDIgM30p
Fore clojure.set
there is index
and join
left to implement. I started with index
to build my self confidence. However, given how we do not have value semantics I wonder⊠And my first straight port fails in a predictable way. -> đ§”
(set/index #{{:name :betsy :weight 1000}
{:name :jake :weight 756}
{:name :shyq :weight 1000}}
[:weight])
=>
Map(3) {
{ weight: 1000 } => Set(1) { { name: 'betsy', weight: 1000 } },
{ weight: 756 } => Set(1) { { name: 'jake', weight: 756 } },
{ weight: 1000 } => Set(1) { { name: 'shyq', weight: 1000 } }
}
This is the code:
export function index(xrel, ...ks) {
return core.reduce((m, x) => {
const ik = core.select_keys(x, ...ks);
const xs = core.get(m, ik, new Set());
return core.assoc(m, ik, core.conj(xs, x));
}, new Map(), xrel);
}
Sorry, it is supposed to group by weight. https://clojuredocs.org/clojure.set/index#example-542692d0c026201cdc326ef1
yeah this isn't suited for JS collections. To be fair, I've never used set/index anywhere, let's just leave it out to not create a trap
keywords in squint are just strings and toFn turns a string into #(get % the-string)
join
is joining! https://github.com/squint-cljs/squint/pull/431 đ
@pez cool. I made another PR with some optimizations https://github.com/squint-cljs/squint/pull/433
Whatâs up with quote
?
(quote foo) => TypeError: Cannot read properties of undefined (reading 'core')
Iâm not suggesting symbols should exist, Iâm merely trying to reprogram my brain which insists on symbols being a thing.
Is flatten
missing from squint?
I just read the squint readme, I had no idea of what I was using until now, for me it was just like clojurescript. Now @borkdude message about sets on a #C0GLTDB2T thread makes sense đ
flatten
is nearly always the "wrong" answer so maybe it's good that it isn't present? :rolling_on_the_floor_laughing:
@U04V70XH6 not for advent of code đ
@U05094X3J if you change /squint/
in the url bar to /cherry/
then you will switch to cherry and this has flatten