Skip to content

Interest for #, (comma tuple) tag macro in core? #44

@gilch

Description

@gilch

I'm proposing

(deftag , [form]
  `(tuple ~form))

Usage,

=> #,(range 6)
tuple(range(6))

(0, 1, 2, 3, 4, 5)

Python3 uses lazy iterators a lot more than Python2 did, so realizing one into a tuple, either for

  1. display in the repl or
  2. re-use of the sequence,

is something we do really often.

@vodik expressed interest after my initial suggestion at hylang/hy#1545 (comment)

I also noticed @ekaschalk using a #t for the same thing in jedhy. I like #, better, since I think it would be nice to reserve the lowercase single-letter tags for the end user, and our tuple display form (, 1 2 3) is already using a comma.

Is there something else we'd want to use #, for?

While there are a number of other Python builtins that take an iterable, I don't really think we need a tag macro for the others.

On the other hand, adding the seq abstraction #32 might be a better choice for the use case of re-using a lazy iterator, since a seq is still lazy. But we actually might want to use #, to both realize and display a seq in one shot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions