isaacg1 / pyth

Pyth, an extremely concise language. Try it here:
https://pyth.herokuapp.com/
MIT License
263 stars 57 forks source link

Make the sum of an empty array return 0 instead of [] #241

Closed Mr-Xcoder closed 6 years ago

Mr-Xcoder commented 6 years ago

While messing around with sum of arrays, I have noticed that the sum of an empty array returns [] instead of 0. I don't know the reasons behind this, but it isn't really beneficial for golfing. For instance, if I want to get an integer instead of [], I have to use logical or with 0, which I don't consider very intuitive. That wastes even more bytes when mapping, for instance, because it disallows us to use the implicit d.

Demonstration.

jakobkogler commented 6 years ago

Originally sY resulted in 0. It was changed rather recently in commit c374b45f059646503bc426ff0cb47fe567f0514a

I also don't like this change. Adding numbers in a lists is more common than joining lists. On an upside, +FY will still return 0, which is shorter and cleaner than |sY0. Still longer than sY though.

isaacg1 commented 6 years ago

What would you think about making +F and s swapped?

Mr-Xcoder commented 6 years ago

What is the advantage of [] as the sum of a list, no matter if it is used with s or +F? I don't see the point, really. But yeah, I'd much rather prefer +F -> [] and s -> 0.

isaacg1 commented 6 years ago

The advantage is that the sum of [[1], [2]] should be [1, 2], so we would expect that the sum of any list of lists to be a list. But then the sum of [] needs to be [].

isaacg1 commented 6 years ago

I changed this back in 015c875

Mr-Xcoder commented 6 years ago

@isaacg1 Thanks for changing that!