hyrule icon indicating copy to clipboard operation
hyrule copied to clipboard

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

Open gilch opened this issue 7 years ago • 7 comments

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 https://github.com/hylang/hy/pull/1545#issuecomment-376005469

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 hylang/hyrule#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.

gilch avatar May 20 '18 21:05 gilch

Seems reasonable.

Kodiologist avatar May 20 '18 21:05 Kodiologist

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 avatar May 21 '18 18:05 ekaschalk

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.

ekaschalk avatar May 21 '18 19:05 ekaschalk

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

Kodiologist avatar May 21 '18 19:05 Kodiologist

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.

ekaschalk avatar May 21 '18 19:05 ekaschalk

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?

Kodiologist avatar May 21 '18 19:05 Kodiologist

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 #,.

ekaschalk avatar May 21 '18 20:05 ekaschalk