Re: What type does byGrapheme() return?

2020-01-06 Thread Alex via Digitalmars-d-learn
On Monday, 6 January 2020 at 08:39:19 UTC, Robert M. Münch wrote: On 2020-01-05 04:18:34 +, H. S. Teoh said: At a minimum, I think we should file a bug report to investigate whether Grapheme.opSlice can be implemented differently, such that we avoid this obscure referential behaviour that

Re: What type does byGrapheme() return?

2020-01-06 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-01-05 04:18:34 +, H. S. Teoh said: At a minimum, I think we should file a bug report to investigate whether Grapheme.opSlice can be implemented differently, such that we avoid this obscure referential behaviour that makes it hard to work with in complex code. I'm not sure if this is

Re: What type does byGrapheme() return?

2020-01-04 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jan 04, 2020 at 08:19:14PM +0100, Robert M. Münch via Digitalmars-d-learn wrote: > On 2019-12-31 21:36:56 +, Steven Schveighoffer said: > > > The fact that a Grapheme's return requires you keep the grapheme in > > scope for operations seems completely incorrect and dangerous IMO > >

Re: What type does byGrapheme() return?

2020-01-04 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-12-31 21:36:56 +, Steven Schveighoffer said: The fact that a Grapheme's return requires you keep the grapheme in scope for operations seems completely incorrect and dangerous IMO (note that operators are going to always have a ref this, even when called on an rvalue). So even

Re: What type does byGrapheme() return?

2019-12-31 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 31, 2019 at 04:36:56PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 12/31/19 4:22 PM, H. S. Teoh wrote: [...] > > import std; > > void main() { > > auto x = "Bla\u0301hbla\u0310h\u0309!"; > > auto r = x.byGrapheme; > >

Re: What type does byGrapheme() return?

2019-12-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/31/19 4:22 PM, H. S. Teoh wrote: On Tue, Dec 31, 2019 at 04:02:47PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: On 12/31/19 2:58 PM, H. S. Teoh wrote: On Tue, Dec 31, 2019 at 09:33:14AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: e.g.: writeln(" Text =

Re: What type does byGrapheme() return?

2019-12-31 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 31, 2019 at 04:02:47PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 12/31/19 2:58 PM, H. S. Teoh wrote: > > On Tue, Dec 31, 2019 at 09:33:14AM -0500, Steven Schveighoffer via > > Digitalmars-d-learn wrote: > > > e.g.: > > > > > > writeln(" Text = ", gr1.map!((ref

Re: What type does byGrapheme() return?

2019-12-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/31/19 2:58 PM, H. S. Teoh wrote: On Tue, Dec 31, 2019 at 09:33:14AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: e.g.: writeln(" Text = ", gr1.map!((ref g) => g[]).joiner.to!string); [...] Unfortunately this doesn't work. Somehow the ref parameter doesn't match whatever

Re: What type does byGrapheme() return?

2019-12-31 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 31, 2019 at 09:33:14AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 12/30/19 6:31 PM, H. S. Teoh wrote: > > On Mon, Dec 30, 2019 at 03:09:58PM -0800, H. S. Teoh via > > Digitalmars-d-learn wrote: [...] > > Haha, it's actually right there in the Grapheme docs for

Re: What type does byGrapheme() return?

2019-12-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/30/19 6:31 PM, H. S. Teoh wrote: On Mon, Dec 30, 2019 at 03:09:58PM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] I suspect the cause is that whatever Grapheme.opSlice returns is going out-of-scope when used with .map, that's why it's malfunctioning. [...] Haha, it's actually

Re: What type does byGrapheme() return?

2019-12-30 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 30, 2019 at 03:31:31PM -0800, H. S. Teoh via Digitalmars-d-learn wrote: > On Mon, Dec 30, 2019 at 03:09:58PM -0800, H. S. Teoh via Digitalmars-d-learn > wrote: > [...] > > I suspect the cause is that whatever Grapheme.opSlice returns is > > going out-of-scope when used with .map,

Re: What type does byGrapheme() return?

2019-12-30 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 30, 2019 at 03:09:58PM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] > I suspect the cause is that whatever Grapheme.opSlice returns is going > out-of-scope when used with .map, that's why it's malfunctioning. [...] Haha, it's actually right there in the Grapheme docs for

Re: What type does byGrapheme() return?

2019-12-30 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Dec 29, 2019 at 01:19:09PM +0100, Robert M. Münch via Digitalmars-d-learn wrote: > On 2019-12-27 19:44:59 +, H. S. Teoh said: [...] > > If you want to add/delete/change graphemes, what you *really* want > > is to use an array of Graphemes: > > > > Grapheme[] editableGraphs; > >

Re: What type does byGrapheme() return?

2019-12-30 Thread Alexandru Ermicioi via Digitalmars-d-learn
On Friday, 27 December 2019 at 17:26:58 UTC, Robert M. Münch wrote: ... There are set of range interfaces that can be used to mask range type. Check for https://dlang.org/library/std/range/interfaces/input_range.html for starting point, and for

Re: What type does byGrapheme() return?

2019-12-29 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-12-27 19:44:59 +, H. S. Teoh said: Since graphemes are variable-length in terms of code points, you can't exactly *edit* a range of graphemes -- you can't replace a 1-codepoint grapheme with a 6-codepoint grapheme, for example, since there's no space in the underlying string to

Re: What type does byGrapheme() return?

2019-12-29 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-12-27 17:54:28 +, Steven Schveighoffer said: This is the rub with ranges. You need to use typeof. There's no other way to do it, because the type returned by byGrapheme depends on the type of Range. Hi, ok, thanks a lot and IMO these are the fundamental important information for

Re: What type does byGrapheme() return?

2019-12-27 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 27, 2019 at 06:26:58PM +0100, Robert M. Münch via Digitalmars-d-learn wrote: > I love these documentation lines in the D docs: > > auto byGrapheme(Range)(Range range) > > How should I know what auto is? Why not write the explicit type so > that I know what to expect? When

Re: What type does byGrapheme() return?

2019-12-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/27/19 12:26 PM, Robert M. Münch wrote: I love these documentation lines in the D docs: auto byGrapheme(Range)(Range range) How should I know what auto is? Why not write the explicit type so that I know what to expect? When declaring a variable as class/struct member I can't use