Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gilch opened this issue May 20, 2018 · 7 comments
Open

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

gilch opened this issue May 20, 2018 · 7 comments
Labels
feature New feature or request

Comments

@gilch
Copy link
Member

gilch commented May 20, 2018

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.

@Kodiologist
Copy link
Member

Seems reasonable.

@ekaschalk
Copy link

It never occurred to me to use a comma. Your post gave me the idea for a ,map variant.

Anyway it would be useful for at least me.

@ekaschalk
Copy link

Also FWIW I'm thinking about adding a Hy reciprocal to clojure-enable-fancify-symbols option (by default disabled).

Then the tuple tag macro can look pretty sweet:

tuple_lig

I already do this in my code.

@Kodiologist
Copy link
Member

(defmacro ⦻ [&rest x] `(tuple (~@x)))
(print (⦻ map inc [1 2 3]))

@ekaschalk
Copy link

ekaschalk commented May 21, 2018

But then you have to type (and other's see): instead of #,. If it isn't clear, the commented text is the actual text in the buffer, the below is how it's seen.

@Kodiologist
Copy link
Member

That seems like a feature. Wouldn't you rather see the same sequence of characters everywhere rather than one in Emacs and something different elsewhere?

@ekaschalk
Copy link

Sure I would, but plenty wouldn't, and this way doesn't enforce anything on the reader. Now it's just an option to set on.

Imagine if in github this image of my code was the real text:

my_code

I only bring it up here because of the cool translation to #,.

@allison-casey allison-casey added the feature New feature or request label Mar 24, 2021
@Kodiologist Kodiologist transferred this issue from hylang/hy May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants