Re: "tuple unpacking" with zip?

2015-10-22 Thread Dmitry Olshansky via Digitalmars-d
On 21-Oct-2015 19:21, Shriramana Sharma wrote: Shriramana Sharma wrote: iterating through a string as a range will produce each semantically meaningful Unicode character rather than each UTF-8 or UTF-16 codepoint, it does make sense to do this. Dear me... I meant UTF-8 encoded byte, rather

Re: "tuple unpacking" with zip?

2015-10-22 Thread Dmitry Olshansky via Digitalmars-d
On 21-Oct-2015 20:35, Jacob Carlborg wrote: On 2015-10-21 16:13, Shriramana Sharma wrote: Why is it a mistake? That seems a very sane thing, although somewhat quirky. Since ElementType is a Range primitive, and apparently iterating through a string as a range will produce each semantically

Re: "tuple unpacking" with zip?

2015-10-21 Thread Shriramana Sharma via Digitalmars-d
John Colvin wrote: >> But this is false, no? Since ElementType!string is char and not >> dchar? > > No. char[], wchar[] and dchar[] all have ElementType dchar. > Strings are special for ranges. It's a bad mistake, but it is > what it is and apparently won't be changed. Why is it a mistake? That

Re: "tuple unpacking" with zip?

2015-10-21 Thread Jonathan M Davis via Digitalmars-d
On Wednesday, 21 October 2015 at 14:13:43 UTC, Shriramana Sharma wrote: John Colvin wrote: But this is false, no? Since ElementType!string is char and not dchar? No. char[], wchar[] and dchar[] all have ElementType dchar. Strings are special for ranges. It's a bad mistake, but it is what

Re: "tuple unpacking" with zip?

2015-10-21 Thread Jacob Carlborg via Digitalmars-d
On 2015-10-21 16:13, Shriramana Sharma wrote: Why is it a mistake? That seems a very sane thing, although somewhat quirky. Since ElementType is a Range primitive, and apparently iterating through a string as a range will produce each semantically meaningful Unicode character rather than each

Re: "tuple unpacking" with zip?

2015-10-21 Thread Shriramana Sharma via Digitalmars-d
Shriramana Sharma wrote: > iterating through a > string as a range will produce each semantically meaningful Unicode > character rather than each UTF-8 or UTF-16 codepoint, it does make sense > to do this. Dear me... I meant UTF-8 encoded byte, rather than "codepoint", since all characters have

Re: "tuple unpacking" with zip?

2015-10-21 Thread anonymous via Digitalmars-d
On Wednesday, October 21, 2015 06:21 PM, Shriramana Sharma wrote: > Dear me... I meant UTF-8 encoded byte, rather than "codepoint", Also known as: code unit.

Re: "tuple unpacking" with zip?

2015-10-21 Thread John Colvin via Digitalmars-d
On Wednesday, 21 October 2015 at 10:08:24 UTC, Shriramana Sharma wrote: In Python I can do: ints = [1, 2, 3] chars = ['a', 'b', 'c'] for i, c in zip(ints, chars): print(i, c) Output: 1 a 2 b 3 c But in D if I try: import std.stdio, std.range; void main () { int [] ints = [1, 2, 3];

"tuple unpacking" with zip?

2015-10-21 Thread Shriramana Sharma via Digitalmars-d
In Python I can do: ints = [1, 2, 3] chars = ['a', 'b', 'c'] for i, c in zip(ints, chars): print(i, c) Output: 1 a 2 b 3 c But in D if I try: import std.stdio, std.range; void main () { int [] ints = [1, 2, 3]; char [] chars = ['a', 'b', 'c']; foreach(int i, char c; zip(ints,

Re: "tuple unpacking" with zip?

2015-10-21 Thread John Colvin via Digitalmars-d
On Wednesday, 21 October 2015 at 12:07:12 UTC, Shriramana Sharma wrote: John Colvin wrote: static assert(is(ElementType!string == dchar)); But this is false, no? Since ElementType!string is char and not dchar? No. char[], wchar[] and dchar[] all have ElementType dchar. Strings are

Re: "tuple unpacking" with zip?

2015-10-21 Thread Shriramana Sharma via Digitalmars-d
John Colvin wrote: > static assert(is(ElementType!string == dchar)); But this is false, no? Since ElementType!string is char and not dchar? > foreach(int i, dchar c; zip(ints, chars)) > or > foreach(i, c; zip(ints, chars)) What's the diff betn char and dchar in this particular context? --