Re: Formatted output ranges

2015-04-20 Thread Dennis Ritchie via Digitalmars-d-learn

On Monday, 20 April 2015 at 17:16:21 UTC, Ivan Kazmenko wrote:

writeln(wrap(a, 30, ;; , ;; ));

Works with dmd 2.066.1 and 2.067.0.


Thanks.


Re: Formatted output ranges

2015-04-20 Thread Ivan Kazmenko via Digitalmars-d-learn
Yes, it's a lot better but I did not get to concatenate the 
string ;; in each paragraph:


-
import std.conv, std.stdio, std.range, std.string;

void main() {

auto a = iota(10, 1101).text;

a = a[1 .. $ - 1], a ~= '.';

writeln(wrap(a, 30));
}
-
http://ideone.com/jsSbKj


writeln(wrap(a, 30, ;; , ;; ));

Works with dmd 2.066.1 and 2.067.0.


Re: Formatted output ranges

2015-04-17 Thread Ivan Kazmenko via Digitalmars-d-learn

On Saturday, 11 April 2015 at 22:45:39 UTC, Dennis Ritchie wrote:
I also want to know whether it is possible to D somehow set the 
maximum width of the print string in characters?


-
void main() {
import std.stdio, std.range;
writefln(;; %(%s, %))., iota(10, 1101));
}
-

For example, here's the code to Common Lisp which is given by 
the width of the line is 30 characters:

-
(let ((a (loop :for i :from 10 :to 1100 :collect i)))
(format t ~%;;~{ ~~%;; ~1,30:;~S~~^,~}.~% a))
-
http://ideone.com/hGguge


Looks like there's std.string.wrap to do that:
http://forum.dlang.org/thread/mgqiji$727$1...@digitalmars.com


Re: Formatted output ranges

2015-04-17 Thread Dennis Ritchie via Digitalmars-d-learn

On Friday, 17 April 2015 at 09:25:43 UTC, Ivan Kazmenko wrote:
On Saturday, 11 April 2015 at 22:45:39 UTC, Dennis Ritchie 
wrote:
I also want to know whether it is possible to D somehow set 
the maximum width of the print string in characters?


-
void main() {
import std.stdio, std.range;
writefln(;; %(%s, %))., iota(10, 1101));
}
-

For example, here's the code to Common Lisp which is given by 
the width of the line is 30 characters:

-
(let ((a (loop :for i :from 10 :to 1100 :collect i)))
(format t ~%;;~{ ~~%;; ~1,30:;~S~~^,~}.~% a))
-
http://ideone.com/hGguge


Looks like there's std.string.wrap to do that:
http://forum.dlang.org/thread/mgqiji$727$1...@digitalmars.com


Yes, it's a lot better but I did not get to concatenate the 
string ;; in each paragraph:


-
import std.conv, std.stdio, std.range, std.string;

void main() {

auto a = iota(10, 1101).text;

a = a[1 .. $ - 1], a ~= '.';

writeln(wrap(a, 30));
}
-
http://ideone.com/jsSbKj


Re: Formatted output ranges

2015-04-11 Thread Dennis Ritchie via Digitalmars-d-learn

On Saturday, 11 April 2015 at 20:37:17 UTC, anonymous wrote:
On Saturday, 11 April 2015 at 20:10:49 UTC, Dennis Ritchie 
wrote:

writefln(%(;; %(%s, %),\n%)., [
a[0 .. 15],
a[15 .. 30],
a[30 .. 45],
a[45 .. 60],
a[60 .. 75],
a[75 .. 90],
a[90 .. $]
]);


writefln(%(;; %(%s, %),\n%)., a.chunks(15));


Thanks.


Re: Formatted output ranges

2015-04-11 Thread anonymous via Digitalmars-d-learn

On Saturday, 11 April 2015 at 20:10:49 UTC, Dennis Ritchie wrote:

writefln(%(;; %(%s, %),\n%)., [
a[0 .. 15],
a[15 .. 30],
a[30 .. 45],
a[45 .. 60],
a[60 .. 75],
a[75 .. 90],
a[90 .. $]
]);


writefln(%(;; %(%s, %),\n%)., a.chunks(15));


Re: Formatted output ranges

2015-04-11 Thread Dennis Ritchie via Digitalmars-d-learn
I also want to know whether it is possible to D somehow set the 
maximum width of the print string in characters?


-
void main() {
import std.stdio, std.range;
writefln(;; %(%s, %))., iota(10, 1101));
}
-

For example, here's the code to Common Lisp which is given by the 
width of the line is 30 characters:

-
(let ((a (loop :for i :from 10 :to 1100 :collect i)))
(format t ~%;;~{ ~~%;; ~1,30:;~S~~^,~}.~% a))
-
http://ideone.com/hGguge


Re: Formatted output ranges

2015-04-11 Thread Dennis Ritchie via Digitalmars-d-learn

On Saturday, 11 April 2015 at 22:45:39 UTC, Dennis Ritchie wrote:
I also want to know whether it is possible to D somehow set the 
maximum width of the print string in characters?


I got to do this:

-
import std.stdio, std.range, std.conv, std.array;

void formatWidthIotaToStr(ref string formatStr, int[] inputRange) 
{


formatStr ~= ;;;
int formatWidth = 30, lenStr = formatStr.length;

foreach (e; inputRange) {
lenStr += e.text.length;
if (lenStr  formatWidth) {
lenStr += 2;
formatStr ~= ' ', formatStr ~= e.text, formatStr ~= ',';
}
else {
formatStr ~= \n;; , formatStr ~= e.text, formatStr ~= 
',';
lenStr = e.text.length + 5;
}
}

formatStr.length -= 1;
formatStr ~= '.';
}

void main() {

auto a = iota(10, 1101).array;

string s;

formatWidthIotaToStr(s, a);

writeln(s);
}
-
http://ideone.com/Yoohbk