gracelang / language

Design of the Grace language and its libraries
GNU General Public License v2.0
6 stars 1 forks source link

Should .. work on strings? #128

Open apblack opened 7 years ago

apblack commented 7 years ago

The range notation a..b works only for numbers, not (right now) for Strings. Students seem to expect it to.

While the meaning of "a".."z" seems obvious, the meaning of "wombat".."kangaroo" is less so. We could define .. just for single-character strings. Is this a bad idea?

The .. operator on Numbers is defined only for integers — it's not total on all numbers. So it would not be inconsistent to make .. partial on Strings.

kjx commented 7 years ago

While the meaning of "a".."z" seems obvious, the meaning of "wombat".."kangaroo" is less so. We could define .. just for single-character strings. Is this a bad idea?

there are other things like "code" that look at only the first character of the string.

Perl has semantics for string ranges (well string++) that are... interesting:

if the string matches /^[a-zA-Z][0-9]\z/ ), then in it increments it otherwise just returns the first element of the range.

J

KimBruce commented 7 years ago

Seems fine to have it restricted to single character strings.

Kim

On Jun 7, 2017, at 5:17 PM, Andrew Black notifications@github.com wrote:

The range notation a..b works only for numbers, not (right now) for Strings. Students seem to expect it to.

While the meaning of "a".."z" seems obvious, the meaning of "wombat".."kangaroo" is less so. We could define .. just for single-character strings. Is this a bad idea?

The .. operator on Numbers is defined only for integers — it's not total on all numbers. So it would not be inconsistent to make .. partial on Strings.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/gracelang/language/issues/128, or mute the thread https://github.com/notifications/unsubscribe-auth/ABuh-mbggmBvKH2AgIMbxi_T7B1--_aaks5sBz2CgaJpZM4Nzbtn.

apblack commented 7 years ago

I think that we should implement .. for single-character strings. I don't think that James is really suggesting that we follow the example of Perl, so I won't worry about that issue.