me: I would like to use a linear positional indexed data structure as a key in a map

python: sure, use a tuple

javascript: let's consider the CONCEPT of SAMENESS. I have prepared some CHARTS

for real though is there a way to do this without... like... serializing the array as a string? I can't find an array-like data type in javascript where values belonging to it are considered SameValueZero-wise equal if they contain the same elements in the same order?

@aparrish p sure anything you use as an object key gets stringified anyway

@aeonofdiscord right, but I'm using an ES6 Map (because I really dislike all the weird garbage that you have to deal with when using objects as "maps," e.g., keys getting stringified)

@aparrish ahhh, sorry, I just associated map->hash->object in my head; didn't realise it was an actual thing now

@aparrish I mean, IIRC python is comparing by serializing to string implicitly anyway (running class __repr__ method). Are you annoyed that it'd be slow, or that it would need to be written?

@enkiv2 I'm just annoyed that there doesn't appear to be an explicit way to do this, and I'm left to invent my own protocol. also python dictionary keys use the value from __hash__ not __repr__, don't they? (which doesn't have to be implemented as string serialization, in fact I'm pretty sure it isn't in the case of tuples)

@aparrish @enkiv2 For some reason I thought __hash__ in its default implementation did a string hash on __repr__ output. But I probably have a limited understanding & the default implementation does some more complex set of fallback behaviors.

@aparrish Natively, not that i can think of. However, we built something very similar recently for managing keyed handlers on an object. Internally it makes a tree of maps and does lookup for each element in the key array:

@aparrish oh god, the equality semantics are defined by "ALGORITHMS."

This sounds like one of those up-front refusals to fix the semantics bugs no matter what the problem turns out to be.

Which I suppose is par for the course.

Sign in to participate in the conversation

Follow friends and discover new ones. Publish anything you want: links, pictures, text, video. This server is run by the main developers of the Mastodon project. Everyone is welcome as long as you follow our code of conduct!