digitalmars.D - repeat
- Andrei Alexandrescu (19/19) Jan 17 2011 std.range has a function repeat that repeats one value forever. For
- Andrej Mitrovic (3/3) Jan 17 2011 How about..:
- Andrei Alexandrescu (4/7) Jan 17 2011 If I only told you the library has repeat and reproduce, could you be
- Andrej Mitrovic (3/11) Jan 17 2011 Yeah, I see your point. Other names that come to mind are duplicate,
- Manfred_Nowak (5/6) Jan 17 2011 For native english speakers that point might be in existence; for most o...
- spir (10/19) Jan 17 2011 Aha! For this reason precisely, the one producing "abcabcabc" was first
- Daniel Gibson (6/27) Jan 17 2011 IMHO * (multiply) is not good because in theoretical computer science mu...
- spir (8/11) Jan 17 2011 Weird. Excuse my ignorance, but how can multiply even mean concat? How
- Simon Buerger (11/19) Jan 17 2011 It is that way for formal languages. {a,b}^2 = {aa,ab,ba,bb}, so only
- Daniel Gibson (6/17) Jan 18 2011 Dunno, I'm not a theoretical computer science person, but everyone who h...
- Adam Ruppe (10/10) Jan 17 2011 It seems to me that you actually want two separate functions:
- spir (8/11) Jan 17 2011 Would rather see:
- Jonathan M Davis (9/20) Jan 17 2011 Considering that D add the ~ operator for concatenation because + was to...
- bearophile (23/28) Jan 17 2011 This little Python2 program shows a normal usage of the string multiplic...
- Jesse Phillips (10/16) Jan 17 2011 Are you saying that (sorry not testing, but since this is fictional at t...
- bearophile (9/12) Jan 17 2011 I am saying that repeat() is worse than a multiplication sign. I am awar...
- Andrei Alexandrescu (7/26) Jan 17 2011 I just moved join from string to array, defined multiply to copy a range...
- spir (16/35) Jan 17 2011 Right, I understand your point and agree (will change Text's method
- so (5/15) Jan 18 2011 As always, Adam has the solution!
- Caligo (3/3) Jan 17 2011 How is this:
- Daniel Gibson (9/26) Jan 17 2011 You could only supply repeat, returning ["abc","abc",..]
- Tomek =?ISO-8859-2?Q?Sowi=F1ski?= (5/28) Jan 17 2011 Overload cycle and call it a day?
- Andrei Alexandrescu (4/29) Jan 17 2011 cycle(r, n) already has a meaning: cycle r for a maximum total of n
- Tomek =?ISO-8859-2?Q?Sowi=F1ski?= (5/36) Jan 17 2011 Now I'm confused. The docs say it's an initial index...
- Andrei Alexandrescu (6/39) Jan 17 2011 Sorry, my bad. You're right. Still, cycle(r, n) has a meaning distinct
- Tomek =?ISO-8859-2?Q?Sowi=F1ski?= (15/57) Jan 17 2011 urns
- Gareth Charnock (5/24) Jan 17 2011 Perhaps...
- Walter Bright (5/9) Jan 18 2011 Just a thought:
- Daniel Gibson (2/10) Jan 18 2011 :-)
- Christopher Nicholson-Sauls (4/17) Jan 18 2011 Nah. Too obvious.
- Walter Bright (2/19) Jan 18 2011 Eh, I forgot about join!
- Andrei Alexandrescu (3/22) Jan 18 2011 It's Porsche-uh (and join-er).
- Andrei Alexandrescu (6/15) Jan 18 2011 Actually we already have join. Fortunately repeat in std.range is lazy,
- Aziz K. (6/6) Jan 18 2011 I would prefer it to work like this:
std.range has a function repeat that repeats one value forever. For example, repeat(42) is an infinite range containing 42, 42, 42,... The same module also has a function replicate that repeats one value a specific number of times. In fact, replicate can be expressed as an overload of repeat, so that's what I just did (not committed yet): repeat(42, 100) repeats 42 one hundred times, repeat(42) repeats 42 forever. I'll put replicate on the deprecation chute. So far so good. Now, string has its own repeat. repeat("abc", 2) returns the string "abcabc". I want to generalize the functionality in string's repeat and move it outside std.string. There is an obvious semantic clash here. If you say repeat("abc", 3) did you mean one string "abcabcabc" or three strings "abc", "abc", and "abc"? So we need distinct names for the functions. One repeats one value, the other repeats a range. Moreover, I'm thinking sometimes you want to repeat a range lazily, i.e. instead of producing "abcabc" just return a range that looks like it. Ideas for a good naming scheme are welcome. Andrei
Jan 17 2011
How about..: repeat("abc", 3) -> "abcabcabc" reproduce("abc", 3) -> ["abc", "abc", "abc"]
Jan 17 2011
On 1/17/11 12:25 PM, Andrej Mitrovic wrote:How about..: repeat("abc", 3) -> "abcabcabc" reproduce("abc", 3) -> ["abc", "abc", "abc"]If I only told you the library has repeat and reproduce, could you be able to tell without looking at the documentation? Andrei
Jan 17 2011
On 1/17/11, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:On 1/17/11 12:25 PM, Andrej Mitrovic wrote:Yeah, I see your point. Other names that come to mind are duplicate, replicate, clone, repeatRange..How about..: repeat("abc", 3) -> "abcabcabc" reproduce("abc", 3) -> ["abc", "abc", "abc"]If I only told you the library has repeat and reproduce, could you be able to tell without looking at the documentation? Andrei
Jan 17 2011
Andrej Mitrovic wrote:I see your pointFor native english speakers that point might be in existence; for most of the others every sequence of characters is a pure amalgamation without any semantical connotation. -manfred
Jan 17 2011
On 01/17/2011 07:10 PM, Andrei Alexandrescu wrote:I want to generalize the functionality in string's repeat and move it outside std.string. There is an obvious semantic clash here. If you say repeat("abc", 3) did you mean one string "abcabcabc" or three strings "abc", "abc", and "abc"? So we need distinct names for the functions. One repeats one value, the other repeats a range. Moreover, I'm thinking sometimes you want to repeat a range lazily, i.e. instead of producing "abcabc" just return a range that looks like it. Ideas for a good naming scheme are welcome.Aha! For this reason precisely, the one producing "abcabcabc" was first called 'multiply' in Text. But then, I implemented it as '*' and '*='; seemed rather intuitive --what do you think? (various other operations are implemented as operator overloads) Could you do something similar for some algos where it makes sense (and does not feel forced)? Denis _________________ vita es estrany spir.wikidot.com
Jan 17 2011
Am 17.01.2011 19:45, schrieb spir:On 01/17/2011 07:10 PM, Andrei Alexandrescu wrote:IMHO * (multiply) is not good because in theoretical computer science multiply is used to concatenate two words and thus concatenating a word with itself n times is word^n (pow(word, n) in mathematical terms). Cheers, - DanielI want to generalize the functionality in string's repeat and move it outside std.string. There is an obvious semantic clash here. If you say repeat("abc", 3) did you mean one string "abcabcabc" or three strings "abc", "abc", and "abc"? So we need distinct names for the functions. One repeats one value, the other repeats a range. Moreover, I'm thinking sometimes you want to repeat a range lazily, i.e. instead of producing "abcabc" just return a range that looks like it. Ideas for a good naming scheme are welcome.Aha! For this reason precisely, the one producing "abcabcabc" was first called 'multiply' in Text. But then, I implemented it as '*' and '*='; seemed rather intuitive --what do you think? (various other operations are implemented as operator overloads) Could you do something similar for some algos where it makes sense (and does not feel forced)? Denis _________________ vita es estrany spir.wikidot.com
Jan 17 2011
On 01/17/2011 07:57 PM, Daniel Gibson wrote:IMHO * (multiply) is not good because in theoretical computer science multiply is used to concatenate two words and thus concatenating a word with itself n times is word^n (pow(word, n) in mathematical terms).Weird. Excuse my ignorance, but how can multiply even mean concat? How is this written concretely (example welcome)? Do theoretical computer science people find this syntax a Good Thing? Denis _________________ vita es estrany spir.wikidot.com
Jan 17 2011
On 18.01.2011 01:24, spir wrote:On 01/17/2011 07:57 PM, Daniel Gibson wrote:It is that way for formal languages. {a,b}^2 = {aa,ab,ba,bb}, so only used for sets of strings. It is logical there because * means something like cartesian product which is a concatenation of all combinations of both sets. The notation is not that logical for single strings though. Furthermore, + should mean addition, * should mean multiplication. None of them should stand for concatenation. Similar argument led to the introduction of the ~ operator in D (which is not present in C++/Java) just my point of view, KroxIMHO * (multiply) is not good because in theoretical computer science multiply is used to concatenate two words and thus concatenating a word with itself n times is word^n (pow(word, n) in mathematical terms).Weird. Excuse my ignorance, but how can multiply even mean concat? How is this written concretely (example welcome)? Do theoretical computer science people find this syntax a Good Thing? Denis
Jan 17 2011
Am 18.01.2011 01:24, schrieb spir:On 01/17/2011 07:57 PM, Daniel Gibson wrote:Dunno, I'm not a theoretical computer science person, but everyone who has studied computer science and hasn't completely forgotten the theoretical classes may be confused if multiply is used for repetition :) Cheers, - DanielIMHO * (multiply) is not good because in theoretical computer science multiply is used to concatenate two words and thus concatenating a word with itself n times is word^n (pow(word, n) in mathematical terms).Weird. Excuse my ignorance, but how can multiply even mean concat? How is this written concretely (example welcome)? Do theoretical computer science people find this syntax a Good Thing? Denis _________________ vita es estrany spir.wikidot.com
Jan 18 2011
It seems to me that you actually want two separate functions: repeat("abc", 3) => ["abc", "abc", "abc"] join(repeat("abc", 3)) => "abcabcabc" A join function already exists in std.string and does this, although it expects a second argument for word separator. I'd be ok with adding a default arg to it, the empty string, so this works. Indeed, we could do lazy this same way... have both return the lazy ranges, and if your want the array, just call array() on it. Though I could see that being annoying with strings - the array probably is the common case, but this would be more conceptually pure.
Jan 17 2011
On 01/17/2011 07:53 PM, Adam Ruppe wrote:It seems to me that you actually want two separate functions: repeat("abc", 3) => ["abc", "abc", "abc"] join(repeat("abc", 3)) => "abcabcabc"Would rather see: repeat("abc", 3) => ["abc", "abc", "abc"] "abc" * 3 => "abcabcabc" Denis _________________ vita es estrany spir.wikidot.com
Jan 17 2011
On Monday, January 17, 2011 10:59:16 spir wrote:On 01/17/2011 07:53 PM, Adam Ruppe wrote:Considering that D add the ~ operator for concatenation because + was too ambiguous (e.g. what should "2" + "3" do?), there's no way that overloading * for a function in std.algorithm is going to fly. And since we're dealing with arbitrary range types - not just strings - it definitely isn't going to work. Not to mention, using an operator like that implies that it'sa basic and important operation. However, I'm not sure that I've ever had to use such an operation in my entire life. It needs a normal function, not an overloaded operator. - Jonathan M DavisIt seems to me that you actually want two separate functions: repeat("abc", 3) => ["abc", "abc", "abc"] join(repeat("abc", 3)) => "abcabcabc"Would rather see: repeat("abc", 3) => ["abc", "abc", "abc"] "abc" * 3 => "abcabcabc"
Jan 17 2011
Jonathan M Davis:Considering that D add the ~ operator for concatenation because + was too ambiguous (e.g. what should "2" + "3" do?), there's no way that overloading * for a function in std.algorithm is going to fly.I think D has used the ~ operator to do that, despite the + is much more common for this operation and the ~ character is not present on some keyboards, because the + is normally meant to be a commutative op, while the array/string concatenation is not commutative (3+5==5+3 but "ab"~"cd"!="cd"~"ab"). In the case of * for string/array multiplication it's associative, commutative, distributive and it has both identity and zero elements, so I don't think there are the same problems.However, I'm not sure that I've ever had to use such an operation in my entire life.This little Python2 program shows a normal usage of the string multiplication: n = 6 s = "+---" * n + "+" print s for i in xrange(5): print "| " * n + "|" print s It prints: +---+---+---+---+---+---+ | | | | | | | +---+---+---+---+---+---+ | | | | | | | +---+---+---+---+---+---+ | | | | | | | +---+---+---+---+---+---+ | | | | | | | +---+---+---+---+---+---+ | | | | | | | +---+---+---+---+---+---+ Bye, bearophile
Jan 17 2011
bearophile Wrote:n = 6 s = "+---" * n + "+" print s for i in xrange(5): print "| " * n + "|" print sAre you saying that (sorry not testing, but since this is fictional at this time anyway): auto n = 6; auto s = join(repeat("+---", n), "+"); print s; foreach(i; 0..5) { writeln(join(repeat("| ", n), "|")); writeln(s); } isn't good enough? Maybe there is a performance benefit to not needing join?
Jan 17 2011
Jesse Phillips:Are you saying that (sorry not testing, but since this is fictional at this time anyway):I have printed similar ASCII tables some times, it was an almost real example.isn't good enough?I am saying that repeat() is worse than a multiplication sign. I am aware you are usually able to replace operators with functions. Operators are functions, written using another syntax. Even if people around here keep showing me equivalent ways to do things, I find some Python syntax sugar better than D equivalents. List comprehensions, tuple unpacking syntax, tuple destructuring in function signatures, "in" for presence in a linear collection, etc, and sometimes even string multiplications (among those tuple unpacking syntax is probably the most useful and I still hope to see it in future D. I am losing hope to see array/lazy comprehensions in D).Maybe there is a performance benefit to not needing join?In D I write that with no join (untested): auto s = "+---".repeat(n) ~ "+"; When you want to write an ASCII grid performance is usually not so important. It's more about the amount of cognitive friction, that's here in D is a bit higher. Bye, bearophile
Jan 17 2011
On 1/17/11 2:15 PM, Jonathan M Davis wrote:On Monday, January 17, 2011 10:59:16 spir wrote:I just moved join from string to array, defined multiply to copy a range multiple times into an array, and changed replicate to repeat: http://www.dsource.org/projects/phobos/changeset/2343 http://d-programming-language.org/cutting-edge/phobos/std_array.html http://d-programming-language.org/cutting-edge/phobos/std_string.html AndreiOn 01/17/2011 07:53 PM, Adam Ruppe wrote:Considering that D add the ~ operator for concatenation because + was too ambiguous (e.g. what should "2" + "3" do?), there's no way that overloading * for a function in std.algorithm is going to fly. And since we're dealing with arbitrary range types - not just strings - it definitely isn't going to work. Not to mention, using an operator like that implies that it'sa basic and important operation. However, I'm not sure that I've ever had to use such an operation in my entire life. It needs a normal function, not an overloaded operator.It seems to me that you actually want two separate functions: repeat("abc", 3) => ["abc", "abc", "abc"] join(repeat("abc", 3)) => "abcabcabc"Would rather see: repeat("abc", 3) => ["abc", "abc", "abc"] "abc" * 3 => "abcabcabc"
Jan 17 2011
On 01/17/2011 09:15 PM, Jonathan M Davis wrote:On Monday, January 17, 2011 10:59:16 spir wrote:Right, I understand your point and agree (will change Text's method accordingly when a good name is agreed upon). What about "times"? I had to use this function rather often (else, wouldn't had bothered with it in Text); string types I know from other languages have it builtin as well, so it certainly is a common need (and as you see Andrei provides it as builtin algo as well). About arbitrary ranges, is repeat([1,2,3], 3) supposed to produce [ [1,2,3] , [1,2,3] , [1,2,3] ] ? Denis _________________ vita es estrany spir.wikidot.comOn 01/17/2011 07:53 PM, Adam Ruppe wrote:Considering that D add the ~ operator for concatenation because + was too ambiguous (e.g. what should "2" + "3" do?), there's no way that overloading * for a function in std.algorithm is going to fly. And since we're dealing with arbitrary range types - not just strings - it definitely isn't going to work. Not to mention, using an operator like that implies that it'sa basic and important operation. However, I'm not sure that I've ever had to use such an operation in my entire life. It needs a normal function, not an overloaded operator.It seems to me that you actually want two separate functions: repeat("abc", 3) => ["abc", "abc", "abc"] join(repeat("abc", 3)) => "abcabcabc"Would rather see: repeat("abc", 3) => ["abc", "abc", "abc"] "abc" * 3 => "abcabcabc"
Jan 17 2011
On Mon, 17 Jan 2011 20:53:33 +0200, Adam Ruppe <destructionator gmail.com> wrote:It seems to me that you actually want two separate functions: repeat("abc", 3) => ["abc", "abc", "abc"] join(repeat("abc", 3)) => "abcabcabc" A join function already exists in std.string and does this, although it expects a second argument for word separator. I'd be ok with adding a default arg to it, the empty string, so this works. Indeed, we could do lazy this same way... have both return the lazy ranges, and if your want the array, just call array() on it. Though I could see that being annoying with strings - the array probably is the common case, but this would be more conceptually pure.As always, Adam has the solution! Or maybe overload it like: join("abc", 3)
Jan 18 2011
How is this: repeat("abc", 3) -> ["abc", "abc", "abc"] repeated("abc", 3) -> "abcabcabc"
Jan 17 2011
Am 17.01.2011 19:10, schrieb Andrei Alexandrescu:std.range has a function repeat that repeats one value forever. For example, repeat(42) is an infinite range containing 42, 42, 42,... The same module also has a function replicate that repeats one value a specific number of times. In fact, replicate can be expressed as an overload of repeat, so that's what I just did (not committed yet): repeat(42, 100) repeats 42 one hundred times, repeat(42) repeats 42 forever. I'll put replicate on the deprecation chute. So far so good. Now, string has its own repeat. repeat("abc", 2) returns the string "abcabc". I want to generalize the functionality in string's repeat and move it outside std.string. There is an obvious semantic clash here. If you say repeat("abc", 3) did you mean one string "abcabcabc" or three strings "abc", "abc", and "abc"? So we need distinct names for the functions. One repeats one value, the other repeats a range. Moreover, I'm thinking sometimes you want to repeat a range lazily, i.e. instead of producing "abcabc" just return a range that looks like it. Ideas for a good naming scheme are welcome. AndreiYou could only supply repeat, returning ["abc","abc",..] And also concat (is there really no concat in std.algorithm? Maybe bringToFront.. but a concat that gets a range of ranges may be useful) so people can do something like concat(repeat("abc", 42)) (functional style) Cheers, - Daniel
Jan 17 2011
Andrei Alexandrescu napisa=B3:std.range has a function repeat that repeats one value forever. For=20 example, repeat(42) is an infinite range containing 42, 42, 42,... =20 The same module also has a function replicate that repeats one value a=20 specific number of times. In fact, replicate can be expressed as an=20 overload of repeat, so that's what I just did (not committed yet):=20 repeat(42, 100) repeats 42 one hundred times, repeat(42) repeats 42=20 forever. I'll put replicate on the deprecation chute. =20 So far so good. Now, string has its own repeat. repeat("abc", 2) returns==20the string "abcabc". =20 I want to generalize the functionality in string's repeat and move it=20 outside std.string. There is an obvious semantic clash here. If you say=20 repeat("abc", 3) did you mean one string "abcabcabc" or three strings=20 "abc", "abc", and "abc"? =20 So we need distinct names for the functions. One repeats one value, the=20 other repeats a range. Moreover, I'm thinking sometimes you want to=20 repeat a range lazily, i.e. instead of producing "abcabc" just return a=20 range that looks like it. =20 Ideas for a good naming scheme are welcome.Overload cycle and call it a day? --=20 Tomek
Jan 17 2011
On 1/17/11 1:53 PM, Tomek Sowiński wrote:Andrei Alexandrescu napisał:cycle(r, n) already has a meaning: cycle r for a maximum total of n elements. Andreistd.range has a function repeat that repeats one value forever. For example, repeat(42) is an infinite range containing 42, 42, 42,... The same module also has a function replicate that repeats one value a specific number of times. In fact, replicate can be expressed as an overload of repeat, so that's what I just did (not committed yet): repeat(42, 100) repeats 42 one hundred times, repeat(42) repeats 42 forever. I'll put replicate on the deprecation chute. So far so good. Now, string has its own repeat. repeat("abc", 2) returns the string "abcabc". I want to generalize the functionality in string's repeat and move it outside std.string. There is an obvious semantic clash here. If you say repeat("abc", 3) did you mean one string "abcabcabc" or three strings "abc", "abc", and "abc"? So we need distinct names for the functions. One repeats one value, the other repeats a range. Moreover, I'm thinking sometimes you want to repeat a range lazily, i.e. instead of producing "abcabc" just return a range that looks like it. Ideas for a good naming scheme are welcome.Overload cycle and call it a day?
Jan 17 2011
Andrei Alexandrescu napisa=B3:On 1/17/11 1:53 PM, Tomek Sowi=F1ski wrote:nsAndrei Alexandrescu napisa=B3:std.range has a function repeat that repeats one value forever. For example, repeat(42) is an infinite range containing 42, 42, 42,... The same module also has a function replicate that repeats one value a specific number of times. In fact, replicate can be expressed as an overload of repeat, so that's what I just did (not committed yet): repeat(42, 100) repeats 42 one hundred times, repeat(42) repeats 42 forever. I'll put replicate on the deprecation chute. So far so good. Now, string has its own repeat. repeat("abc", 2) retur=Now I'm confused. The docs say it's an initial index... --=20 Tomek=20 cycle(r, n) already has a meaning: cycle r for a maximum total of n=20 elements.the string "abcabc". I want to generalize the functionality in string's repeat and move it outside std.string. There is an obvious semantic clash here. If you say repeat("abc", 3) did you mean one string "abcabcabc" or three strings "abc", "abc", and "abc"? So we need distinct names for the functions. One repeats one value, the other repeats a range. Moreover, I'm thinking sometimes you want to repeat a range lazily, i.e. instead of producing "abcabc" just return a range that looks like it. Ideas for a good naming scheme are welcome.Overload cycle and call it a day?
Jan 17 2011
On 1/17/11 2:14 PM, Tomek Sowiński wrote:Andrei Alexandrescu napisał:Sorry, my bad. You're right. Still, cycle(r, n) has a meaning distinct from what we might need. Essentially I'm looking for a name for the function array(take(cycle(range), n * range.length)). That's what std.string.repeat does currently. AndreiOn 1/17/11 1:53 PM, Tomek Sowiński wrote:Now I'm confused. The docs say it's an initial index...Andrei Alexandrescu napisał:cycle(r, n) already has a meaning: cycle r for a maximum total of n elements.std.range has a function repeat that repeats one value forever. For example, repeat(42) is an infinite range containing 42, 42, 42,... The same module also has a function replicate that repeats one value a specific number of times. In fact, replicate can be expressed as an overload of repeat, so that's what I just did (not committed yet): repeat(42, 100) repeats 42 one hundred times, repeat(42) repeats 42 forever. I'll put replicate on the deprecation chute. So far so good. Now, string has its own repeat. repeat("abc", 2) returns the string "abcabc". I want to generalize the functionality in string's repeat and move it outside std.string. There is an obvious semantic clash here. If you say repeat("abc", 3) did you mean one string "abcabcabc" or three strings "abc", "abc", and "abc"? So we need distinct names for the functions. One repeats one value, the other repeats a range. Moreover, I'm thinking sometimes you want to repeat a range lazily, i.e. instead of producing "abcabc" just return a range that looks like it. Ideas for a good naming scheme are welcome.Overload cycle and call it a day?
Jan 17 2011
Andrei Alexandrescu napisa=B3:On 1/17/11 2:14 PM, Tomek Sowi=F1ski wrote:aAndrei Alexandrescu napisa=B3:On 1/17/11 1:53 PM, Tomek Sowi=F1ski wrote:Andrei Alexandrescu napisa=B3:std.range has a function repeat that repeats one value forever. For example, repeat(42) is an infinite range containing 42, 42, 42,... The same module also has a function replicate that repeats one value=urnsspecific number of times. In fact, replicate can be expressed as an overload of repeat, so that's what I just did (not committed yet): repeat(42, 100) repeats 42 one hundred times, repeat(42) repeats 42 forever. I'll put replicate on the deprecation chute. So far so good. Now, string has its own repeat. repeat("abc", 2) ret=saythe string "abcabc". I want to generalize the functionality in string's repeat and move it outside std.string. There is an obvious semantic clash here. If you =therepeat("abc", 3) did you mean one string "abcabcabc" or three strings "abc", "abc", and "abc"? So we need distinct names for the functions. One repeats one value, =n aother repeats a range. Moreover, I'm thinking sometimes you want to repeat a range lazily, i.e. instead of producing "abcabc" just retur=I don't think the initial index really useful (even the authors confirm by = not bothering to unittest it:-)) My idea is to dump it in favor of popFront= N (provide a method on Cycle, let the stand-alone popFrontN statically reco= gnize that). Bounding an infinite range is much more frequent. Or, if you're really not keen on the idea, introduce cycleN.=20 Sorry, my bad. You're right. Still, cycle(r, n) has a meaning distinct=20 from what we might need.Now I'm confused. The docs say it's an initial index...cycle(r, n) already has a meaning: cycle r for a maximum total of n elements.range that looks like it. Ideas for a good naming scheme are welcome.Overload cycle and call it a day?Essentially I'm looking for a name for the=20 function array(take(cycle(range), n * range.length)). That's what=20 std.string.repeat does currently.With the above cycleN(range, n * range.length).array() doesn't look that ba= d. What are the use-cases that you want a separate name? --=20 Tomek
Jan 17 2011
On 17/01/11 18:10, Andrei Alexandrescu wrote:std.range has a function repeat that repeats one value forever. For example, repeat(42) is an infinite range containing 42, 42, 42,... The same module also has a function replicate that repeats one value a specific number of times. In fact, replicate can be expressed as an overload of repeat, so that's what I just did (not committed yet): repeat(42, 100) repeats 42 one hundred times, repeat(42) repeats 42 forever. I'll put replicate on the deprecation chute. So far so good. Now, string has its own repeat. repeat("abc", 2) returns the string "abcabc". I want to generalize the functionality in string's repeat and move it outside std.string. There is an obvious semantic clash here. If you say repeat("abc", 3) did you mean one string "abcabcabc" or three strings "abc", "abc", and "abc"? So we need distinct names for the functions. One repeats one value, the other repeats a range. Moreover, I'm thinking sometimes you want to repeat a range lazily, i.e. instead of producing "abcabc" just return a range that looks like it. Ideas for a good naming scheme are welcome. AndreiPerhaps... repeat("abc",3) -> ["abc","abc","abc"] repeatFlatten("abc",3) -> "abcabcabc" or perhaps repeatFlat("abc",3) ?
Jan 17 2011
Andrei Alexandrescu wrote:I want to generalize the functionality in string's repeat and move it outside std.string. There is an obvious semantic clash here. If you say repeat("abc", 3) did you mean one string "abcabcabc" or three strings "abc", "abc", and "abc"?Just a thought: concat(repeat("abc",3)) yields "abcabcabc" ?
Jan 18 2011
Am 18.01.2011 10:07, schrieb Walter Bright:Andrei Alexandrescu wrote::-)I want to generalize the functionality in string's repeat and move it outside std.string. There is an obvious semantic clash here. If you say repeat("abc", 3) did you mean one string "abcabcabc" or three strings "abc", "abc", and "abc"?Just a thought: concat(repeat("abc",3)) yields "abcabcabc" ?
Jan 18 2011
On 01/18/11 03:07, Walter Bright wrote:Andrei Alexandrescu wrote:Nah. Too obvious. On a more serious note, I have no issue with join(repeat("abc",3)). -- Chris N-SI want to generalize the functionality in string's repeat and move it outside std.string. There is an obvious semantic clash here. If you say repeat("abc", 3) did you mean one string "abcabcabc" or three strings "abc", "abc", and "abc"?Just a thought: concat(repeat("abc",3)) yields "abcabcabc" ?
Jan 18 2011
Christopher Nicholson-Sauls wrote:On 01/18/11 03:07, Walter Bright wrote:Eh, I forgot about join!Andrei Alexandrescu wrote:Nah. Too obvious. On a more serious note, I have no issue with join(repeat("abc",3)).I want to generalize the functionality in string's repeat and move it outside std.string. There is an obvious semantic clash here. If you say repeat("abc", 3) did you mean one string "abcabcabc" or three strings "abc", "abc", and "abc"?Just a thought: concat(repeat("abc",3)) yields "abcabcabc" ?
Jan 18 2011
On 1/18/11 3:24 PM, Walter Bright wrote:Christopher Nicholson-Sauls wrote:It's Porsche-uh (and join-er). AndreiOn 01/18/11 03:07, Walter Bright wrote:Eh, I forgot about join!Andrei Alexandrescu wrote:Nah. Too obvious. On a more serious note, I have no issue with join(repeat("abc",3)).I want to generalize the functionality in string's repeat and move it outside std.string. There is an obvious semantic clash here. If you say repeat("abc", 3) did you mean one string "abcabcabc" or three strings "abc", "abc", and "abc"?Just a thought: concat(repeat("abc",3)) yields "abcabcabc" ?
Jan 18 2011
On 1/18/11 3:07 AM, Walter Bright wrote:Andrei Alexandrescu wrote:Actually we already have join. Fortunately repeat in std.range is lazy, which avoid multiple memory allocations. I only need to make join accept general ranges. Question is, do we deprecate std.string.repeat? AndreiI want to generalize the functionality in string's repeat and move it outside std.string. There is an obvious semantic clash here. If you say repeat("abc", 3) did you mean one string "abcabcabc" or three strings "abc", "abc", and "abc"?Just a thought: concat(repeat("abc",3)) yields "abcabcabc" ?
Jan 18 2011
I would prefer it to work like this: repeat("abc", 3) -> "abcabcabc" repeat(["abc"], 3) -> ["abc","abc","abc"] repeat([1,2,3], 3) -> [1,2,3,1,2,3,1,2,3] -- Dil D compiler: http://code.google.com/p/dil/
Jan 18 2011
On 01/18/2011 01:10 PM, Aziz K. wrote:I would prefer it to work like this: repeat("abc", 3) -> "abcabcabc" repeat(["abc"], 3) -> ["abc","abc","abc"] repeat([1,2,3], 3) -> [1,2,3,1,2,3,1,2,3]I find this consistent in that the operation keeps the nesting level constant. But then we need a good name for an operation that nests into a higher-level array ;-) What about arrayOf (T) (T something, uint count=1) ? arrayOf("abc", 3) -> ["abc","abc","abc"] arrayOf(["abc"], 3) -> [["abc"],["abc"],["abc"]] arrayOf([1,2,3], 3) -> [[1,2,3],[1,2,3],[1,2,3]] Denis _________________ vita es estrany spir.wikidot.com
Jan 18 2011
Okay, so your arrayOf() function could be written as: auto arrayOf(T x, uint n){ return repeat([x], n); } Only needs to wrap the argument inside another array literal.
Jan 18 2011