Re: standard ranges

2012-08-23 Thread Steven Schveighoffer
Sorry to resurrect this thread, I've been very absent from D, and am just now going through all these old posts. On Wed, 27 Jun 2012 17:41:14 -0400, Timon Gehr wrote: On 06/27/2012 11:11 PM, Steven Schveighoffer wrote: No, druntime, and include minimal utf support. We do the same thing wi

Re: standard ranges

2012-06-28 Thread Roman D. Boiko
My point (and the reason I somehow hijacked this thread) is that such functionality would be useful for random access over narrow strings. Currently random access is missing. Also this approach fits nicely if random access is needed to Unicode characters, not just code points. I don't see mu

Re: standard ranges

2012-06-28 Thread Roman D. Boiko
On Thursday, 28 June 2012 at 14:34:03 UTC, Andrei Alexandrescu wrote: Well of course I've exaggerated a bit. My point is that mentioning "200 ns!!!" sounds to the uninformed ear as good as "2000 ns" or "20 ns", i.e. "an amount of time so short by human scale, it must mean fast". You need to com

Re: standard ranges

2012-06-28 Thread Andrei Alexandrescu
On 6/28/12 8:57 AM, Roman D. Boiko wrote: On Thursday, 28 June 2012 at 12:29:14 UTC, Andrei Alexandrescu wrote: On 6/28/12 5:58 AM, Roman D. Boiko wrote: Pedantically speaking, sheer timings say nothing without the appropriate baselines. Andrei I used results of benchmarks for two such algori

Re: standard ranges

2012-06-28 Thread Christophe Travert
Timon Gehr , dans le message (digitalmars.D:170884), a écrit : >> An I would say I am also entitle to say strings are not normal >> ranges, since they define length, but have isLength as true, > > hasLength as false. Of course, my mistake. > They define length, but it is not part of the range int

Re: standard ranges

2012-06-28 Thread Roman D. Boiko
Timings should not be very different from random access in any UTF-32 string implementation, because of design of these algorithms: * only operations on 64-bit aligned words are performed (addition, multiplication, bitwise and shift operations) * there is no branching except at the very top

Re: standard ranges

2012-06-28 Thread Timon Gehr
On 06/28/2012 11:28 AM, Christophe Travert wrote: Jonathan M Davis , dans le message (digitalmars.D:170872), a écrit : On Thursday, June 28, 2012 08:05:19 Christophe Travert wrote: "Jonathan M Davis" , dans le message (digitalmars.D:170852), a écrit : completely consistent with regards to how

Re: standard ranges

2012-06-28 Thread Roman D. Boiko
On Thursday, 28 June 2012 at 12:29:14 UTC, Andrei Alexandrescu wrote: On 6/28/12 5:58 AM, Roman D. Boiko wrote: Pedantically speaking, sheer timings say nothing without the appropriate baselines. Andrei I used results of benchmarks for two such algorithms, which I like most, taken from here

Re: standard ranges

2012-06-28 Thread Andrei Alexandrescu
On 6/28/12 5:28 AM, Christophe Travert wrote: As a more general comment, I think having a consistent langage is a very important goal to achieve when designing a langage. It makes everything simpler, from langage design to user through compiler and library development. It may not be too late for

Re: standard ranges

2012-06-28 Thread Andrei Alexandrescu
On 6/28/12 5:58 AM, Roman D. Boiko wrote: Pedantically speaking, it is possible to index a string with about 50-51% memory overhead to get random access in 0(1) time. Best-performing algorithms can do random access in about 35-50 nanoseconds per operation for strings up to tens of megabytes. For

Re: standard ranges

2012-06-28 Thread Roman D. Boiko
On Thursday, 28 June 2012 at 09:58:02 UTC, Roman D. Boiko wrote: Pedantically speaking, it is possible to index a string with about 50-51% memory overhead to get random access in 0(1) time. Best-performing algorithms can do random access in about 35-50 nanoseconds per operation for strings up t

Re: standard ranges

2012-06-28 Thread Christophe Travert
"David Nadlinger" , dans le message (digitalmars.D:170875), a écrit : > On Thursday, 28 June 2012 at 09:49:19 UTC, Jonathan M Davis wrote: >>> char[] is not treated as an array by the library, and is not >>> treated as a RandomAccessRange. That is a second >>> inconsistency, and it would be avoid

Re: standard ranges

2012-06-28 Thread Roman D. Boiko
On Thursday, 28 June 2012 at 10:02:59 UTC, Roman D. Boiko wrote: On Thursday, 28 June 2012 at 09:58:02 UTC, Roman D. Boiko wrote: Pedantically speaking, it is possible to index a string with about 50-51% memory overhead to get random access in 0(1) time. Best-performing algorithms can do random

Re: standard ranges

2012-06-28 Thread Roman D. Boiko
On Thursday, 28 June 2012 at 09:58:02 UTC, Roman D. Boiko wrote: Pedantically speaking, it is possible to index a string with about 50-51% memory overhead to get random access in 0(1) time. Best-performing algorithms can do random access in about 35-50 nanoseconds per operation for strings up t

Re: standard ranges

2012-06-28 Thread Roman D. Boiko
On Thursday, 28 June 2012 at 05:10:43 UTC, Jonathan M Davis wrote: On Thursday, June 28, 2012 08:59:32 Gor Gyolchanyan wrote: Currently strings below dstring are only applicable in ForwardRange and below, but not RandomAccessRange as they should be. Except that they shouldn't be, because you

Re: standard ranges

2012-06-28 Thread David Nadlinger
On Thursday, 28 June 2012 at 09:49:19 UTC, Jonathan M Davis wrote: char[] is not treated as an array by the library, and is not treated as a RandomAccessRange. That is a second inconsistency, and it would be avoided is string were a struct. So, it looked to me like you were saying that making

Re: standard ranges

2012-06-28 Thread Jonathan M Davis
On Thursday, June 28, 2012 09:28:52 Christophe Travert wrote: > I never said strings should support length and slicing. I even said > they should not. foreach is inconsistent with the way strings are > treated in phobos, but opIndex, opSlice and length, are inconsistent to. > string[0] and string.f

Re: standard ranges

2012-06-28 Thread Christophe Travert
Jonathan M Davis , dans le message (digitalmars.D:170872), a écrit : > On Thursday, June 28, 2012 08:05:19 Christophe Travert wrote: >> "Jonathan M Davis" , dans le message (digitalmars.D:170852), a écrit : >> > completely consistent with regards to how it treats strings. The _only_ >> > inconsinte

Re: standard ranges

2012-06-28 Thread Jonathan M Davis
On Thursday, June 28, 2012 08:05:19 Christophe Travert wrote: > "Jonathan M Davis" , dans le message (digitalmars.D:170852), a écrit : > > completely consistent with regards to how it treats strings. The _only_ > > inconsintencies are between the language and the library - namely how > > foreach it

Re: standard ranges

2012-06-28 Thread Christophe Travert
"Jonathan M Davis" , dans le message (digitalmars.D:170852), a écrit : > completely consistent with regards to how it treats strings. The _only_ > inconsintencies are between the language and the library - namely how foreach > iterates on code units by default and the fact that while the language

Re: standard ranges

2012-06-27 Thread Jonathan M Davis
On Thursday, June 28, 2012 08:59:32 Gor Gyolchanyan wrote: > On Thu, Jun 28, 2012 at 12:22 AM, Steven Schveighoffer > > wrote: > > On Wed, 27 Jun 2012 15:20:26 -0400, Timon Gehr wrote: > >> There is no reason for anyone to be confused about this endlessly. It > >> is simple to understand. Furthe

Re: standard ranges

2012-06-27 Thread Gor Gyolchanyan
On Thu, Jun 28, 2012 at 12:22 AM, Steven Schveighoffer wrote: > On Wed, 27 Jun 2012 15:20:26 -0400, Timon Gehr wrote: > >> There is no reason for anyone to be confused about this endlessly. It >> is simple to understand. Furthermore, think about the implications of a >> library-defined string typ

Re: standard ranges

2012-06-27 Thread Jonathan M Davis
On Wednesday, June 27, 2012 23:41:14 Timon Gehr wrote: > On 06/27/2012 11:11 PM, Steven Schveighoffer wrote: > > When most string functions take strings, why would you want to use > > immutable(char)[] everywhere? > > Because the proposed 'string' interface is inconvenient to use and > useless. It

Re: standard ranges

2012-06-27 Thread Timon Gehr
On 06/27/2012 11:11 PM, Steven Schveighoffer wrote: On Wed, 27 Jun 2012 16:55:49 -0400, Timon Gehr wrote: On 06/27/2012 10:22 PM, Steven Schveighoffer wrote: On Wed, 27 Jun 2012 15:20:26 -0400, Timon Gehr wrote: There is no reason for anyone to be confused about this endlessly. It is simpl

Re: standard ranges

2012-06-27 Thread Jonathan M Davis
On Wednesday, June 27, 2012 17:11:56 Steven Schveighoffer wrote: > On Wed, 27 Jun 2012 16:55:49 -0400, Timon Gehr wrote: > > On 06/27/2012 10:22 PM, Steven Schveighoffer wrote: > >> On Wed, 27 Jun 2012 15:20:26 -0400, Timon Gehr > >> > >> wrote: > >>> There is no reason for anyone to be confused

Re: standard ranges

2012-06-27 Thread Steven Schveighoffer
On Wed, 27 Jun 2012 16:55:49 -0400, Timon Gehr wrote: On 06/27/2012 10:22 PM, Steven Schveighoffer wrote: On Wed, 27 Jun 2012 15:20:26 -0400, Timon Gehr wrote: There is no reason for anyone to be confused about this endlessly. It is simple to understand. Furthermore, think about the impli

Re: standard ranges

2012-06-27 Thread Jonathan M Davis
On Wednesday, June 27, 2012 22:54:28 Gor Gyolchanyan wrote: > On Wed, Jun 27, 2012 at 10:42 PM, Jonathan M Davis wrote: > > On Wednesday, June 27, 2012 22:29:25 Gor Gyolchanyan wrote: > >> Agreed. Having struct strings (with slices and everything) will set > >> the record straight. > > > > Excep

Re: standard ranges

2012-06-27 Thread Timon Gehr
On 06/27/2012 10:22 PM, Steven Schveighoffer wrote: On Wed, 27 Jun 2012 15:20:26 -0400, Timon Gehr wrote: There is no reason for anyone to be confused about this endlessly. It is simple to understand. Furthermore, think about the implications of a library-defined string type: it just introduce

Re: standard ranges

2012-06-27 Thread Steven Schveighoffer
On Wed, 27 Jun 2012 15:20:26 -0400, Timon Gehr wrote: There is no reason for anyone to be confused about this endlessly. It is simple to understand. Furthermore, think about the implications of a library-defined string type: it just introduces the problem of what the type of built-in string lit

Re: standard ranges

2012-06-27 Thread Timon Gehr
On 06/27/2012 08:54 PM, Gor Gyolchanyan wrote: On Wed, Jun 27, 2012 at 10:42 PM, Jonathan M Davis wrote: On Wednesday, June 27, 2012 22:29:25 Gor Gyolchanyan wrote: Agreed. Having struct strings (with slices and everything) will set the record straight. Except that they couldn't have slicing

Re: standard ranges

2012-06-27 Thread Timon Gehr
On 06/27/2012 08:09 PM, Steven Schveighoffer wrote: On Wed, 27 Jun 2012 13:30:48 -0400, Jonathan M Davis wrote: I don't see why having the literal be a string would make anything confusing. The fact that a string is considered a range of dchar rather than char could be, but I don't see why ha

Re: standard ranges

2012-06-27 Thread Gor Gyolchanyan
On Wed, Jun 27, 2012 at 10:42 PM, Jonathan M Davis wrote: > On Wednesday, June 27, 2012 22:29:25 Gor Gyolchanyan wrote: >> Agreed. Having struct strings (with slices and everything) will set >> the record straight. > > Except that they couldn't have slicing, because it would be very inefficient. >

Re: standard ranges

2012-06-27 Thread Jonathan M Davis
On Wednesday, June 27, 2012 22:29:25 Gor Gyolchanyan wrote: > Agreed. Having struct strings (with slices and everything) will set > the record straight. Except that they couldn't have slicing, because it would be very inefficient. You'd have to get at the actual array of code units to slice anyth

Re: standard ranges

2012-06-27 Thread Gor Gyolchanyan
On Wed, Jun 27, 2012 at 10:09 PM, Steven Schveighoffer wrote: > On Wed, 27 Jun 2012 13:30:48 -0400, Jonathan M Davis > wrote: > > >> I don't see why having the literal be a string would make anything >> confusing. >> The fact that a string is considered a range of dchar rather than char >> could

Re: standard ranges

2012-06-27 Thread Steven Schveighoffer
On Wed, 27 Jun 2012 13:30:48 -0400, Jonathan M Davis wrote: I don't see why having the literal be a string would make anything confusing. The fact that a string is considered a range of dchar rather than char could be, but I don't see why having a string literal be a dstring instead of a

Re: standard ranges

2012-06-27 Thread Jonathan M Davis
On Wednesday, June 27, 2012 19:54:12 Gor Gyolchanyan wrote: > On Wed, Jun 27, 2012 at 7:49 PM, Jonathan M Davis wrote: > > On Wednesday, June 27, 2012 19:47:41 Gor Gyolchanyan wrote: > > > On Wed, Jun 27, 2012 at 7:41 PM, Jonathan M Davis > > > > wrote: > > > > On Wednesday, June 27, 2012 17:58:4

Re: standard ranges

2012-06-27 Thread Timon Gehr
On 06/27/2012 05:54 PM, Gor Gyolchanyan wrote: On Wed, Jun 27, 2012 at 7:49 PM, Jonathan M Davis mailto:jmdavisp...@gmx.com>> wrote: _All_ strings are considered to be ranges of dchar. That's why string and wstring are not random access ranges and hasLength is false for them. -

Re: standard ranges

2012-06-27 Thread Gor Gyolchanyan
On Wed, Jun 27, 2012 at 7:49 PM, Jonathan M Davis wrote: > On Wednesday, June 27, 2012 19:47:41 Gor Gyolchanyan wrote: > > On Wed, Jun 27, 2012 at 7:41 PM, Jonathan M Davis > wrote: > > > On Wednesday, June 27, 2012 17:58:46 Gor Gyolchanyan wrote: > > > > I tested it out and the string literal wit

Re: standard ranges

2012-06-27 Thread Jonathan M Davis
On Wednesday, June 27, 2012 19:47:41 Gor Gyolchanyan wrote: > On Wed, Jun 27, 2012 at 7:41 PM, Jonathan M Davis wrote: > > On Wednesday, June 27, 2012 17:58:46 Gor Gyolchanyan wrote: > > > I tested it out and the string literal without qualifiers counts as a > > > dstring. > > > > That depends en

Re: standard ranges

2012-06-27 Thread Gor Gyolchanyan
On Wed, Jun 27, 2012 at 7:41 PM, Jonathan M Davis wrote: > On Wednesday, June 27, 2012 17:58:46 Gor Gyolchanyan wrote: > > I tested it out and the string literal without qualifiers counts as a > > dstring. > > That depends entirely on what you assign it to. > writeln(typeof("hello").stringof) prin

Re: standard ranges

2012-06-27 Thread Jonathan M Davis
On Wednesday, June 27, 2012 17:58:46 Gor Gyolchanyan wrote: > I tested it out and the string literal without qualifiers counts as a > dstring. That depends entirely on what you assign it to. writeln(typeof("hello").stringof) prints string, not dstring. So, the literal by itself is a string by de

Re: standard ranges

2012-06-27 Thread Gor Gyolchanyan
On Wed, Jun 27, 2012 at 5:38 PM, Timon Gehr wrote: > On 06/27/2012 03:25 PM, Gor Gyolchanyan wrote: > >> Are there functions, which wrap arbitrary range types into standard >> range interfaces? >> I looked at the docs, but couldn't find anything. >> Use case: >> >> RandomAccessRange!dchar s = ???

Re: standard ranges

2012-06-27 Thread Timon Gehr
On 06/27/2012 03:25 PM, Gor Gyolchanyan wrote: Are there functions, which wrap arbitrary range types into standard range interfaces? I looked at the docs, but couldn't find anything. Use case: RandomAccessRange!dchar s = ???("Hello, world!"); -- Bye, Gor Gyolchanyan. A narrow string is not a

standard ranges

2012-06-27 Thread Gor Gyolchanyan
Are there functions, which wrap arbitrary range types into standard range interfaces? I looked at the docs, but couldn't find anything. Use case: RandomAccessRange!dchar s = ???("Hello, world!"); -- Bye, Gor Gyolchanyan.