digitalmars.D - findSkip signature
- Andrei Alexandrescu (17/17) Jan 16 2011 I just added a useful function to Phobos: findSkip. Refer to
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (7/35) Jan 17 2011 I am not sure where findSkip is useful but can we assume that the caller...
- Andrei Alexandrescu (7/41) Jan 17 2011 findSkip is useful in parsing. One simple case in which it was useful
- Graham St Jack (4/49) Jan 17 2011 --
I just added a useful function to Phobos: findSkip. Refer to http://d-programming-language.org/cutting-edge/phobos/std_algorithm.html#findSkip and http://www.dsource.org/projects/phobos/changeset/2339 I'm unsure about the signature. Currently the function returns Tuple!(R1, "balance", bool, "found"), i.e. the balance of the range being searched and a Boolean telling whether or not the other range was found. The Boolean is necessary because returning an empty range is ambiguous - did you find the needle at the very end of the haystack, or not at all? I think a signature that's easier to use is: bool findSkip(alias pred = "a == b", R1, R2)(ref R1 haystack, R2 needle); i.e. the haystack is passed by reference and modified if the find was successful. This is in keep with skipOver's signature, but not in keep with find's signature. Opinions? Andrei
Jan 16 2011
Andrei Alexandrescu wrote:I just added a useful function to Phobos: findSkip. Refer to http://d-programming-language.org/cutting-edge/phobos/std_alg rithm.html#findSkip and http://www.dsource.org/projects/phobos/changeset/2339 I'm unsure about the signature. Currently the function returns Tuple!(R1, "balance", bool, "found"), i.e. the balance of the range being searched and a Boolean telling whether or not the other range was found. The Boolean is necessary because returning an empty range is ambiguous - did you find the needle at the very end of the haystack, or not at all? I think a signature that's easier to use is: bool findSkip(alias pred = "a == b", R1, R2)(ref R1 haystack, R2 needle); i.e. the haystack is passed by reference and modified if the find was successful. This is in keep with skipOver's signature, but not in keep with find's signature. Opinions? AndreiI am not sure where findSkip is useful but can we assume that the caller is not interested in whether it was found or not? If the callers are interested, they should have the option of calling find and skip separately. If they are always interested, then find and skip should not be merged together. Ali
Jan 17 2011
On 1/17/11 3:21 PM, Ali Çehreli wrote:Andrei Alexandrescu wrote:findSkip is useful in parsing. One simple case in which it was useful was count() that counts how many times a forward range occurs in another. You can't do that with find(). (Try it!) I made the executive decision to pass by reference and return a bool. http://d-programming-language.org/cutting-edge/phobos/std_algorithm.html#findSkip AndreiI just added a useful function to Phobos: findSkip. Refer to http://d-programming-language.org/cutting-edge/phobos/std_algorithm.html#findSkip and http://www.dsource.org/projects/phobos/changeset/2339 I'm unsure about the signature. Currently the function returns Tuple!(R1, "balance", bool, "found"), i.e. the balance of the range being searched and a Boolean telling whether or not the other range was found. The Boolean is necessary because returning an empty range is ambiguous - did you find the needle at the very end of the haystack, or not at all? I think a signature that's easier to use is: bool findSkip(alias pred = "a == b", R1, R2)(ref R1 haystack, R2 needle); i.e. the haystack is passed by reference and modified if the find was successful. This is in keep with skipOver's signature, but not in keep with find's signature. Opinions? AndreiI am not sure where findSkip is useful but can we assume that the caller is not interested in whether it was found or not? If the callers are interested, they should have the option of calling find and skip separately. If they are always interested, then find and skip should not be merged together.
Jan 17 2011
On 18/01/11 08:04, Andrei Alexandrescu wrote:On 1/17/11 3:21 PM, Ali Çehreli wrote:vote++Andrei Alexandrescu wrote:findSkip is useful in parsing. One simple case in which it was useful was count() that counts how many times a forward range occurs in another. You can't do that with find(). (Try it!) I made the executive decision to pass by reference and return a bool.I just added a useful function to Phobos: findSkip. Refer to http://d-programming-language.org/cutting-edge/phobos/std_alg rithm.html#findSkip and http://www.dsource.org/projects/phobos/changeset/2339 I'm unsure about the signature. Currently the function returns Tuple!(R1, "balance", bool, "found"), i.e. the balance of the range being searched and a Boolean telling whether or not the other range was found. The Boolean is necessary because returning an empty range is ambiguous - did you find the needle at the very end of the haystack, or not at all? I think a signature that's easier to use is: bool findSkip(alias pred = "a == b", R1, R2)(ref R1 haystack, R2 needle); i.e. the haystack is passed by reference and modified if the find was successful. This is in keep with skipOver's signature, but not in keep with find's signature. Opinions? AndreiI am not sure where findSkip is useful but can we assume that the caller is not interested in whether it was found or not? If the callers are interested, they should have the option of calling find and skip separately. If they are always interested, then find and skip should not be merged together.http://d-programming-language.org/cutting-edge/phobos/std_alg rithm.html#findSkip Andrei-- Graham St Jack
Jan 17 2011