www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Range with lookaround

reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
May be worth discussing in here: 
https://issues.dlang.org/show_bug.cgi?id=17238 -- Andrei
Mar 01 2017
next sibling parent reply qznc <qznc web.de> writes:
On Thursday, 2 March 2017 at 01:44:19 UTC, Andrei Alexandrescu 
wrote:
 May be worth discussing in here: 
 https://issues.dlang.org/show_bug.cgi?id=17238 -- Andrei
getting the last element, not about some lookahead. When I think about lookahead, I always think of parsers. If the lexer provides an input range of tokens, my recursive descent parser might need 3 tokens lookahead, for example. For the lexer input a "push back a character into my input" is more convenient. Should it give some performance guarantees? I guess, we don't want to refresh the buffers at every popFront, so it would probably be as lazy as possible.
Mar 02 2017
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 3/2/17 7:51 AM, qznc wrote:
 On Thursday, 2 March 2017 at 01:44:19 UTC, Andrei Alexandrescu wrote:
 May be worth discussing in here:
 https://issues.dlang.org/show_bug.cgi?id=17238 -- Andrei
last element, not about some lookahead. When I think about lookahead, I always think of parsers. If the lexer provides an input range of tokens, my recursive descent parser might need 3 tokens lookahead, for example. For the lexer input a "push back a character into my input" is more convenient.
Yah, parsing would be an obvious application. Others such as adjacentFind might also benefit.
 Should it give some performance guarantees? I guess, we don't want to
 refresh the buffers at every popFront, so it would probably be as lazy
 as possible.
Yah, a circular buffer should help here. Andrei
Mar 02 2017
prev sibling next sibling parent reply Dukc <ajieskola gmail.com> writes:
On Thursday, 2 March 2017 at 01:44:19 UTC, Andrei Alexandrescu 
wrote:
 May be worth discussing in here: 
 https://issues.dlang.org/show_bug.cgi?id=17238 -- Andrei
//My understanding of the concept, is this correct? assert(iota(5).lookAhead(1, 2).array == [ [0, 1], [0, 1, 2], [0, 1, 2, 3], [1, 2, 3, 4], [2, 3, 4], [3, 4], [4] ]); I would prefer if the second argument meant length, not distance to look back. So the call equivalent to the one above would be lookAhead(-2, 4).
Mar 03 2017
next sibling parent Dukc <ajieskola gmail.com> writes:
On Friday, 3 March 2017 at 11:22:37 UTC, Dukc wrote:
 [snip]
correction:
 assert(iota(5).lookAhead(1, 2).array ==
 [   [0, 1],
     [0, 1, 2],
     [0, 1, 2, 3],
     [1, 2, 3, 4],
     [2, 3, 4]
 ]);
Mar 03 2017
prev sibling parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 3/3/17 6:22 AM, Dukc wrote:
 iota(5).lookAhead(1, 2)
should be iota(5).lookaround!(1, 2)
Mar 03 2017
prev sibling parent reply Dukc <ajieskola gmail.com> writes:
On Thursday, 2 March 2017 at 01:44:19 UTC, Andrei Alexandrescu 
wrote:
 May be worth discussing in here: 
 https://issues.dlang.org/show_bug.cgi?id=17238 -- Andrei
Almost similar to this: https://github.com/dlang/phobos/pull/4027 Perhaps we should use that as base?
Mar 03 2017
next sibling parent Seb <seb wilzba.ch> writes:
On Friday, 3 March 2017 at 11:56:26 UTC, Dukc wrote:
 On Thursday, 2 March 2017 at 01:44:19 UTC, Andrei Alexandrescu 
 wrote:
 May be worth discussing in here: 
 https://issues.dlang.org/show_bug.cgi?id=17238 -- Andrei
Almost similar to this: https://github.com/dlang/phobos/pull/4027 Perhaps we should use that as base?
My PR even included such a circular buffer until Andrei suggested to move it to a separate PR. However, I think we are all misunderstanding Andrei. He isn't referring to a buffer here - have a look at the issue.
Mar 03 2017
prev sibling parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 3/3/17 6:56 AM, Dukc wrote:
 On Thursday, 2 March 2017 at 01:44:19 UTC, Andrei Alexandrescu wrote:
 May be worth discussing in here:
 https://issues.dlang.org/show_bug.cgi?id=17238 -- Andrei
Almost similar to this: https://github.com/dlang/phobos/pull/4027 Perhaps we should use that as base?
Yes! cc wilzbach
Mar 03 2017