Higher level built-in strings

2010-07-18 Thread bearophile
This odd post comes from reading the nice part about strings of chapter 4 of TDPL. In the last few years I have seen changes in how D strings are meant and managed, changes that make them less and less like arrays (random-access sequences of mutable code units) and more and more what they are at

Re: Higher level built-in strings

2010-07-19 Thread %u
> 5) foreach(c; s1) yields a code point dchars regardless if s1 is string, dstring, wstring. > But you can use foreach(char c; s1) if s1 is a string and you are sure s1 uses only 7 bit chars. But in such cases you can also use a immutable(ubyte)[]. Python3 does something similar, its has a str typ

Re: Higher level built-in strings

2010-07-19 Thread bearophile
%u: > When you are working with individual characters you almost always want either > a > dchar or a byte. A dchar and an ubyte are better. This is almost what Python3 does and I think it can be good. Maybe other people will give their opinions about my original post. Bye, bearophile

Re: Higher level built-in strings

2010-07-19 Thread Walter Bright
bearophile wrote: This odd post comes from reading the nice part about strings of chapter 4 of TDPL. In the last few years I have seen changes in how D strings are meant and managed, changes that make them less and less like arrays (random-access sequences of mutable code units) and more and more

Re: Higher level built-in strings

2010-07-19 Thread dsimcha
== Quote from Walter Bright (newshou...@digitalmars.com)'s article > bearophile wrote: > > This odd post comes from reading the nice part about strings of chapter 4 of > > TDPL. In the last few years I have seen changes in how D strings are meant > > and managed, changes that make them less and les

Re: Higher level built-in strings

2010-07-19 Thread Steven Schveighoffer
On Mon, 19 Jul 2010 16:04:21 -0400, Walter Bright wrote: bearophile wrote: This odd post comes from reading the nice part about strings of chapter 4 of TDPL. In the last few years I have seen changes in how D strings are meant and managed, changes that make them less and less like arrays

Re: Higher level built-in strings

2010-07-19 Thread bearophile
Walter Bright: > 1. most string operations, such as copying and searching, even regular > expressions, work just fine using regular indices. > > 2. doing the operations in (1) using code points and having to continually > decode the strings would result in disastrously slow code. In my original

Re: Higher level built-in strings

2010-07-19 Thread Marianne Gagnon
Pragmatically, I seem to have noted that in languages with low level strings, people invariably come up with librairies that provide higher-level strings. C/C++ provided low-level strings only initially, then a not-so-powerful std::string; and we saw QString, wxString, irr::string, BetterString,

Re: Higher level built-in strings

2010-07-19 Thread Jesse Phillips
What about: struct String { string items; alias items this; } And add the needed functions you wish to have in string and it will still work in existing functions that operate on immutable(char)[]

Re: Higher level built-in strings

2010-07-19 Thread Jonathan M Davis
On Monday, July 19, 2010 16:49:58 Marianne Gagnon wrote: > Pragmatically, I seem to have noted that in languages with low level > strings, people invariably come up with librairies that provide > higher-level strings. C/C++ provided low-level strings only initially, > then a not-so-powerful std::st

Re: Higher level built-in strings

2010-07-19 Thread Andrei Alexandrescu
On 07/19/2010 06:51 PM, Jesse Phillips wrote: What about: struct String { string items; alias items this; } And add the needed functions you wish to have in string and it will still work in existing functions that operate on immutable(char)[] Fortunately you can essentially a

Re: Higher level built-in strings

2010-07-19 Thread Walter Bright
bearophile wrote: Walter Bright: 1. most string operations, such as copying and searching, even regular expressions, work just fine using regular indices. 2. doing the operations in (1) using code points and having to continually decode the strings would result in disastrously slow code. In

Re: Higher level built-in strings

2010-07-19 Thread Walter Bright
Steven Schveighoffer wrote: On Mon, 19 Jul 2010 16:04:21 -0400, Walter Bright wrote: Strings in D are deliberately meant to be arrays, not special things. Other languages make them special because they have insufficiently powerful arrays. Andrei is changing that. Already, isRandomAccessRang

Re: Higher level built-in strings

2010-07-19 Thread Andrei Alexandrescu
On 07/19/2010 11:31 PM, Walter Bright wrote: Steven Schveighoffer wrote: On Mon, 19 Jul 2010 16:04:21 -0400, Walter Bright wrote: Strings in D are deliberately meant to be arrays, not special things. Other languages make them special because they have insufficiently powerful arrays. Andrei i

Re: Higher level built-in strings

2010-07-19 Thread Andrei Alexandrescu
On 07/19/2010 11:29 PM, Walter Bright wrote: bearophile wrote: Walter Bright: 1. most string operations, such as copying and searching, even regular expressions, work just fine using regular indices. 2. doing the operations in (1) using code points and having to continually decode the strings

Re: Higher level built-in strings

2010-07-20 Thread Rory McGuire
On Tue, 20 Jul 2010 01:51:51 +0200, Jesse Phillips wrote: What about: struct String { string items; alias items this; } And add the needed functions you wish to have in string and it will still work in existing functions that operate on immutable(char)[] You shouldn't ne

Re: Higher level built-in strings

2010-07-20 Thread bearophile
Walter: >As it turns out, indexing by byte is *far* more common than indexing by code >unit, in fact, I've never ever needed to index by code unit.< OK. >Probably too late to change that one. There is very little D2 code around, so little changes as this one are possible still. As alternativ

Re: Higher level built-in strings

2010-07-20 Thread Michel Fortin
On 2010-07-20 00:31:34 -0400, Walter Bright said: Steven Schveighoffer wrote: I agree here. Anything that uses indexing to perform a linear operation is bound for the scrap heap. But what about this: foreach(c; str) which types c as char (or immutable char), not dchar. Probably too late

Re: Higher level built-in strings

2010-07-20 Thread DCoder
== Quote from Michel Fortin (michel.for...@michelf.com)'s article > On 2010-07-20 00:31:34 -0400, Walter Bright said: > > Steven Schveighoffer wrote: > >> I agree here. Anything that uses indexing to perform a linear > >> operation is bound for the scrap heap. But what about this: > >> > >> fore

Re: Higher level built-in strings

2010-07-20 Thread Steven Schveighoffer
On Mon, 19 Jul 2010 20:26:47 -0400, Andrei Alexandrescu wrote: On 07/19/2010 06:51 PM, Jesse Phillips wrote: What about: struct String { string items; alias items this; } And add the needed functions you wish to have in string and it will still work in existing functions

Re: Higher level built-in strings

2010-07-20 Thread Rory McGuire
On Tue, 20 Jul 2010 16:08:06 +0200, Jesse Phillips wrote: But then you can't overload operators. On Tue, Jul 20, 2010 at 12:54 AM, Rory McGuire wrote: On Tue, 20 Jul 2010 01:51:51 +0200, Jesse Phillips wrote: What about: struct String { string items; alias items this; }

Re: Higher level built-in strings

2010-07-20 Thread Rory McGuire
On Tue, 20 Jul 2010 16:51:57 +0200, Rory McGuire wrote: On Tue, 20 Jul 2010 16:08:06 +0200, Jesse Phillips wrote: But then you can't overload operators. On Tue, Jul 20, 2010 at 12:54 AM, Rory McGuire wrote: On Tue, 20 Jul 2010 01:51:51 +0200, Jesse Phillips wrote: What about: st

Re: Higher level built-in strings

2010-07-20 Thread Sean Kelly
Steven Schveighoffer Wrote: > > How do we make this work? > > auto str = "hello world"; > foreach(c; str) > assert(is(typeof(c) == dchar)); foreach (dchar c; str) assert(...); This feature has been in D for years.

Re: Higher level built-in strings

2010-07-20 Thread Sean Kelly
Walter Bright Wrote: > bearophile wrote: > > Walter Bright: > >> 1. most string operations, such as copying and searching, even regular > >> expressions, work just fine using regular indices. > >> > >> 2. doing the operations in (1) using code points and having to continually > >> decode the st

Re: Higher level built-in strings

2010-07-20 Thread Simen kjaeraas
Rory McGuire wrote: [snip] Rory, is there something wrong with your newsreader? I keep seeing your posts as replies only to the top post. -- Simen

Re: Higher level built-in strings

2010-07-20 Thread Jérôme M. Berger
Sean Kelly wrote: > Steven Schveighoffer Wrote: >> How do we make this work? >> >> auto str = "hello world"; >> foreach(c; str) >> assert(is(typeof(c) == dchar)); > > foreach (dchar c; str) > assert(...); > > This feature has been in D for years. And what about this one: void fu

Re: Higher level built-in strings

2010-07-20 Thread Jesse Phillips
Simen kjaeraas Wrote: > Rory McGuire wrote: > > [snip] > > Rory, is there something wrong with your newsreader? I keep seeing your > posts as replies only to the top post. > > -- > Simen Actually I'm getting his messages as emails, and just thought he was only sending to me.

Re: Higher level built-in strings

2010-07-20 Thread awishformore
Am 20.07.2010 19:15, schrieb Jesse Phillips: Simen kjaeraas Wrote: Rory McGuire wrote: [snip] Rory, is there something wrong with your newsreader? I keep seeing your posts as replies only to the top post. -- Simen Actually I'm getting his messages as emails, and just thought he was only

Re: Higher level built-in strings

2010-07-20 Thread Steven Schveighoffer
On Tue, 20 Jul 2010 11:02:57 -0400, Sean Kelly wrote: Steven Schveighoffer Wrote: How do we make this work? auto str = "hello world"; foreach(c; str) assert(is(typeof(c) == dchar)); foreach (dchar c; str) assert(...); This feature has been in D for years. The omission of dchar

Re: Higher level built-in strings

2010-07-20 Thread Jonathan M Davis
On Tuesday, July 20, 2010 05:30:51 DCoder wrote: > I'm wondering how bad would it be introduce a schar (short char, 1 > byte) type and then let char simply map to a "default" char type: > dchar, wchar, or whatever we tell the compiler. By default, char > would map to dchar. > > alias char dchar; >

Re: Higher level built-in strings

2010-07-20 Thread Walter Bright
Andrei Alexandrescu wrote: I think otherwise. In fact I confess I am extremely excited. The current state of affairs described built-in strings very accurately: they are formally bidirectional ranges, yet they offer random access for code units that you can freely use if you so wish. It's model

Re: Higher level built-in strings

2010-07-20 Thread Walter Bright
bearophile wrote: Probably too late to change that one. There is very little D2 code around, so little changes as this one are possible still. It's a D1 feature, and has been there since nearly the beginning.

Re: Higher level built-in strings

2010-07-20 Thread Walter Bright
Michel Fortin wrote: As for the "too late to change" stance, I'm not sure. It'll certainly be to late to change in a year, but right now D2 is still pretty new. What makes you say it's too late? As I said to bearophile, it's a D1 feature.

Re: Higher level built-in strings

2010-07-20 Thread Rory McGuire
On Tue, 20 Jul 2010 18:35:12 +0200, Simen kjaeraas wrote: Rory McGuire wrote: [snip] Rory, is there something wrong with your newsreader? I keep seeing your posts as replies only to the top post. I'm using opera mail. Any suggestions for Linux+Windows, excluding thunderbird(slow)?

Re: Higher level built-in strings

2010-07-20 Thread Steven Schveighoffer
On Tue, 20 Jul 2010 14:29:43 -0400, Walter Bright wrote: bearophile wrote: Probably too late to change that one. There is very little D2 code around, so little changes as this one are possible still. It's a D1 feature, and has been there since nearly the beginning. Since when did we c

Re: Higher level built-in strings

2010-07-20 Thread Walter Bright
Sean Kelly wrote: I've had the same experience. The proposed changes would make string useless to me, even for Unicode work. I'd end up using ubyte[] instead. At this point, the experience with D strings is that D gets it right. To change it would require someone who has spent a *lot* of hou

Re: Higher level built-in strings

2010-07-20 Thread Walter Bright
Jérôme M. Berger wrote: And what about this one: void func(T) (T range) { foreach (elem; range) assert (is (typeof (elem) == ElementType!(T))); } func ("azerty"); auto a = [ 1, 2, 3, 4, 5]; func (a); You can specialize the template for strings: void func(T:string)(T range

Re: Higher level built-in strings

2010-07-20 Thread Walter Bright
Steven Schveighoffer wrote: The omission of dchar is on purpose. Phobos has characterized string as a bidirectional range of dchars. For every range where I do: foreach(e; range) e is of the type of the range. Except for char and wchar. This schizophrenia of type induction is very bad for

Re: Higher level built-in strings

2010-07-20 Thread Steven Schveighoffer
On Tue, 20 Jul 2010 15:21:34 -0400, Walter Bright wrote: Steven Schveighoffer wrote: The omission of dchar is on purpose. Phobos has characterized string as a bidirectional range of dchars. For every range where I do: foreach(e; range) e is of the type of the range. Except for char an

Re: Higher level built-in strings

2010-07-20 Thread Jérôme M. Berger
Walter Bright wrote: > Jérôme M. Berger wrote: >> And what about this one: >> >> void func(T) (T range) { >> foreach (elem; range) >> assert (is (typeof (elem) == ElementType!(T))); >> } >> >> func ("azerty"); >> auto a = [ 1, 2, 3, 4, 5]; >> func (a); > > You can specialize the te

Re: Higher level built-in strings

2010-07-20 Thread Jérôme M. Berger
Jesse Phillips wrote: > Simen kjaeraas Wrote: > >> Rory McGuire wrote: >> >> [snip] >> >> Rory, is there something wrong with your newsreader? I keep seeing your >> posts as replies only to the top post. >> >> -- >> Simen > > Actually I'm getting his messages as emails, and just thought he was

Re: Higher level built-in strings

2010-07-20 Thread Walter Bright
Steven Schveighoffer wrote: On Tue, 20 Jul 2010 14:29:43 -0400, Walter Bright wrote: It's a D1 feature, and has been there since nearly the beginning. Since when did we care about D1 compatibility? We care about incompatibilities that silently break code. const, inout, array appending, fi

Re: Higher level built-in strings

2010-07-20 Thread Walter Bright
Steven Schveighoffer wrote: On Tue, 20 Jul 2010 15:21:34 -0400, Walter Bright wrote: Steven Schveighoffer wrote: The omission of dchar is on purpose. Phobos has characterized string as a bidirectional range of dchars. For every range where I do: foreach(e; range) e is of the type of the

Re: Higher level built-in strings

2010-07-20 Thread Walter Bright
Jérôme M. Berger wrote: Walter Bright wrote: You can specialize the template for strings: void func(T:string)(T range) { ... } Sure, i can also not use a template and write however many overloaded functions I need. So what are templates for? The overloaded template specialization ca

Re: Higher level built-in strings

2010-07-20 Thread Walter Bright
Rory McGuire wrote: I'm using opera mail. Any suggestions for Linux+Windows, excluding thunderbird(slow)? I use thunderbird on both windows & linux, haven't noticed speed problems other than my slow internet connection. I have noticed that thunderbird uses multithreading fairly effectively t

Re: Higher level built-in strings

2010-07-20 Thread Andrei Alexandrescu
Walter Bright wrote: Steven Schveighoffer wrote: On Tue, 20 Jul 2010 14:29:43 -0400, Walter Bright wrote: It's a D1 feature, and has been there since nearly the beginning. Since when did we care about D1 compatibility? We care about incompatibilities that silently break code. const, inou

Re: Higher level built-in strings

2010-07-20 Thread Andrei Alexandrescu
Walter Bright wrote: Steven Schveighoffer wrote: On Tue, 20 Jul 2010 15:21:34 -0400, Walter Bright wrote: Steven Schveighoffer wrote: The omission of dchar is on purpose. Phobos has characterized string as a bidirectional range of dchars. For every range where I do: foreach(e; range) e

Re: Higher level built-in strings

2010-07-20 Thread Jonathan M Davis
On Tuesday, July 20, 2010 11:45:41 Rory McGuire wrote: > On Tue, 20 Jul 2010 18:35:12 +0200, Simen kjaeraas > > wrote: > > Rory McGuire wrote: > > > > [snip] > > > > Rory, is there something wrong with your newsreader? I keep seeing your > > posts as replies only to the top post. > > I'm usin

Re: Higher level built-in strings

2010-07-20 Thread Fawzi Mohamed
I did not read all the discussion in detail, but in my opinion something that would be very useful in a library is struct String{ void *ptr; size_t _l; enum :size_t { MaskLen=((~cast(size_t)0)>>2) } enum :int { BitsLen=8*si

Re: Higher level built-in strings

2010-07-21 Thread Aelxx
"Walter Bright" ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ: news:i24st1$12u...@digitalmars.com... > Jerome M. Berger wrote: >> And what about this one: >> >> void func(T) (T range) { >> foreach (elem; range) >> assert (is (typeof (elem) == ElementType!(T))); >> } >> >> func ("azerty"); >>

Re: Higher level built-in strings

2010-07-26 Thread Bruno Medeiros
On 20/07/2010 20:41, "Jérôme M. Berger" wrote: Jesse Phillips wrote: Simen kjaeraas Wrote: Funny thing is I don't have any problem with his messages but yours does appear as a reply to the top post... Jerome In my client (Thunderbird 3), it appears as a top level post. Its b