Skip to content

Should there be a frozenset macro? #279

@gilch

Description

@gilch

Maybe # should be for frozenset instead of set. Make the right way obvious. When in doubt, frozenset is generally the better choice. Python should have had set and mutableset, and, in fact, that's what's in collections.abc: Set and MutableSet. The frozen type should have also gotten the literal notation and comprehension.

Unfortunately, without the literal notation, frozensets have to compile to a pickle. Maybe this should be special cased, but what should it compile to instead? The CPython disassembly will use a constant frozenset when it can, but it still has to pass it to the frozenset() constructor. I think the best we can do is __import__('builtins').frozenset({-}). But maybe (__import__('builtins').frozenset()|{-}) would work better?

It's weird that sets can't contain sets, when that is absolutely fundamental to set theory. Only frozensets can do that. You only need mutable sets for more efficient deduplication, a rather niche use. Set operations work fine on frozensets and only frozensets can be elements in sets (or other frozensets) or keys in a dict.

You can still use (en#set-), which is a lot shorter than (en#frozenset-), if you need the niche deduplication use. Or we could also give that a macro with a longer name. Maybe ##?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions