Re: string initialization question.

2010-08-02 Thread Steven Schveighoffer
On Fri, 30 Jul 2010 19:41:03 -0400, Justin Spahr-Summers wrote: On Fri, 30 Jul 2010 16:30:17 -0700, Jonathan M Davis wrote: On Friday, July 30, 2010 14:13:15 dcoder wrote: > If I'm writing a program that pretty prints tree data, or output of sql, > like Oracle's sqlplus, or postgres equi

Re: string initialization question.

2010-08-02 Thread Steven Schveighoffer
On Sat, 31 Jul 2010 05:37:41 -0400, Jason Spencer wrote: == Quote from Steven Schveighoffer ([email protected])'s article I was wrong, I looked through the runtime and did not find such a function. std.string has a repeat() function. Try: import std.string; void main() { string div

Re: string initialization question.

2010-07-31 Thread Jason Spencer
== Quote from Steven Schveighoffer ([email protected])'s article > I was wrong, I looked through the runtime and did not find such a function. std.string has a repeat() function. Try: import std.string; void main() { string divider = repeat("-", 5); writeln(divider); } Jason

Re: string initialization question.

2010-07-30 Thread Justin Spahr-Summers
On Fri, 30 Jul 2010 16:30:17 -0700, Jonathan M Davis wrote: > On Friday, July 30, 2010 14:13:15 dcoder wrote: > > If I'm writing a program that pretty prints tree data, or output of sql, > > like Oracle's sqlplus, or postgres equivalent, I find having such a > > utility function/constructor a pre

Re: string initialization question.

2010-07-30 Thread Jonathan M Davis
On Friday, July 30, 2010 14:13:15 dcoder wrote: > If I'm writing a program that pretty prints tree data, or output of sql, > like Oracle's sqlplus, or postgres equivalent, I find having such a > utility function/constructor a pretty handy feature. > > I don't know where such a tool should finally

Re: string initialization question.

2010-07-30 Thread Philippe Sigaud
> > > I don't know where such a tool should finally be placed in D, but I having > it > available as a library or as part of the language would be great. It seems > like a > lot of other languages have it like python, perl, C++, and Java. So it > can't be > that useless. > There is fill() in st

Re: string initialization question.

2010-07-30 Thread dcoder
== Quote from Jonathan M Davis ([email protected])'s article > A makeArray() function wouldn't hurt any, but I don't think that it would > really > buy us much. Of course, truth be told, I've always thought that the ability to > construct a string or vector in C++ all of a single value was pre

Re: string initialization question.

2010-07-30 Thread Steven Schveighoffer
On Fri, 30 Jul 2010 16:31:49 -0400, Jonathan M Davis wrote: On Friday, July 30, 2010 13:10:46 Steven Schveighoffer wrote: It's not. The only runtime functions available to the compiler look like this: _d_newarrayT(TypeInfo ti, size_t length); I guess that's one thing that comes of not

Re: string initialization question.

2010-07-30 Thread Jonathan M Davis
On Friday, July 30, 2010 13:10:46 Steven Schveighoffer wrote: > On Fri, 30 Jul 2010 15:56:36 -0400, Jonathan M Davis > > wrote: > > On Friday, July 30, 2010 10:14:45 Steven Schveighoffer wrote: > >> I think a function to do it is fine, like makeArray('-', 5); > > > > Well, creating a function fo

Re: string initialization question.

2010-07-30 Thread Tomek Sowiński
Dnia 30-07-2010 o 22:15:50 Tomek Sowiński napisał(a): writeln('-'.repeat.take(5)); Oh, and if repeat had slicing (as it should)... '-'.repeat[0..5] Still, it's far cry from Python's '-' * 5 Tomek

Re: string initialization question.

2010-07-30 Thread Tomek Sowiński
Dnia 30-07-2010 o 17:24:41 dcoder napisał(a): Is there anyway in D to convenient fill a string variable with a char say X times? If you need to only print, you can: import std.stdio; import std.range; void main() { foreach (c; take(repeat('-'), 5)) write(c); } I know, I know,

Re: string initialization question.

2010-07-30 Thread Steven Schveighoffer
On Fri, 30 Jul 2010 15:56:36 -0400, Jonathan M Davis wrote: On Friday, July 30, 2010 10:14:45 Steven Schveighoffer wrote: I think a function to do it is fine, like makeArray('-', 5); Well, creating a function for producing an array literal and returning it using templates and string mixi

Re: string initialization question.

2010-07-30 Thread bearophile
Jonathan M Davis: > a makeArray() function would have exactly the same tools that you have to > create > an array of all the same value. So, it's not going to be any more efficient > that > what you can do. Doesn't the D2 GC give you a lower level function to GC-allocate uninitialized memory?

Re: string initialization question.

2010-07-30 Thread Jonathan M Davis
On Friday, July 30, 2010 10:14:45 Steven Schveighoffer wrote: > I think a function to do it is fine, like makeArray('-', 5); Well, creating a function for producing an array literal and returning it using templates and string mixins wouldn't be all that hard, but if you want to create a dynamic

Re: string initialization question.

2010-07-30 Thread Steven Schveighoffer
On Fri, 30 Jul 2010 12:46:20 -0400, bearophile wrote: Steven Schveighoffer: > char[] divider = new char[5]; > divider[] = '-'; That assigns 0xff to all divider chars, and then assigns '-'. I think there's a way to do it without the initial assignment. I was wrong, I looked throug

Re: string initialization question.

2010-07-30 Thread bearophile
Steven Schveighoffer: > > char[] divider = new char[5]; > > divider[] = '-'; > > That assigns 0xff to all divider chars, and then assigns '-'. I think > there's a way to do it without the initial assignment. In past there was some way to do that: typedef char mchar = '-'; mchar[] divid

Re: string initialization question.

2010-07-30 Thread Steven Schveighoffer
On Fri, 30 Jul 2010 11:46:32 -0400, Justin Spahr-Summers wrote: On Fri, 30 Jul 2010 11:35:15 -0400, Steven Schveighoffer wrote: If you want to allocate a new array on the heap with '-' in it, I think there is a way, but I'm not sure how to do it. I'm pretty sure there's a runtime funct

Re: string initialization question.

2010-07-30 Thread Justin Spahr-Summers
On Fri, 30 Jul 2010 11:35:15 -0400, Steven Schveighoffer wrote: > > On Fri, 30 Jul 2010 11:24:41 -0400, dcoder wrote: > > > Hello. > > > > Is there anyway in D to convenient fill a string variable with a char > > say X times? > > > > So, I'd like to do something like: > > > > string divider(

Re: string initialization question.

2010-07-30 Thread Steven Schveighoffer
On Fri, 30 Jul 2010 11:24:41 -0400, dcoder wrote: Hello. Is there anyway in D to convenient fill a string variable with a char say X times? So, I'd like to do something like: string divider( size, '-');// C++ notation. $divider = '-' x $size;// perl notation. I thought I cou

string initialization question.

2010-07-30 Thread dcoder
Hello. Is there anyway in D to convenient fill a string variable with a char say X times? So, I'd like to do something like: string divider( size, '-');// C++ notation. $divider = '-' x $size;// perl notation. I thought I could do the following: const char divider[rowstr.length]