March 01, 2012
On 02/29/2012 08:28 PM, James Miller wrote:

> I understand that Appenders aren't arrays, and should not be used as
> such, but you /can/ use an array as an Appender.

Yes you can but whatever you put() into the array is immediately popFront()'ed from the array. ;) You must use a temporary surrogate slice:

import std.stdio;
import std.range;

void main()
{
    int[] array = [ 1, 2, 3 ];
    int[] slice = array;

    put(slice, 100);  // <-- slice shrinks! :)
}

slice.length is 2 and array.length is 3.

> At some point, you
> have to concede design purity to convenience, otherwise you have a
> language that is actively hostile to changing designs.

Agreed.

Ali

March 01, 2012
On 03/01/2012 03:40 AM, Jonathan M Davis wrote:
> On Wednesday, February 29, 2012 21:23:54 bearophile wrote:
>> Jonathan M Davis:
>>>> put is a function on output ranges, and Appender is an output range.
>>>
>>> Also, given that it doesn't define ~ (and it wouldn't really make sense
>>> for it to), it would be very weird IMHO to define ~=.
>>
>> I don't understand why that's weird.
>> In Java you can't overload an append operator, so using a method is right.
>> But for me it's weird that Appender doesn't use the D operator to _append_.
>> I sometimes use "add" instead of "put" by mistake, forgetting the right
>> method name, because I find it quite unnatural. If Appender needs a put,
>> then I suggest to give it both "put" method and "~=" operator.
>
> Would you define += without defining +? Or *= without defining *? It strikes me
> as a misuse of operator overloading if you have an opOpAssign without its
> corresponding opBinary.
>
> - Jonathan M Davis

It is not the same thing. a=a~b has different semantics from a~=b;
March 01, 2012
Am 01.03.2012 03:40, schrieb Jonathan M Davis:
> On Wednesday, February 29, 2012 21:23:54 bearophile wrote:
>> Jonathan M Davis:
>>>> put is a function on output ranges, and Appender is an output range.
>>>
>>> Also, given that it doesn't define ~ (and it wouldn't really make sense
>>> for it to), it would be very weird IMHO to define ~=.
>>
>> I don't understand why that's weird.
>> In Java you can't overload an append operator, so using a method is right.
>> But for me it's weird that Appender doesn't use the D operator to _append_.
>> I sometimes use "add" instead of "put" by mistake, forgetting the right
>> method name, because I find it quite unnatural. If Appender needs a put,
>> then I suggest to give it both "put" method and "~=" operator.
>
> Would you define += without defining +? Or *= without defining *? It strikes me
> as a misuse of operator overloading if you have an opOpAssign without its
> corresponding opBinary.
>
> - Jonathan M Davis

Consider matrix * vector and matrix *= vector for an opposite example.

March 05, 2012
On Wed, 29 Feb 2012 20:25:35 -0500, bearophile <bearophileHUGS@lycos.com> wrote:

> Do you know why std.array.Appender defines a "put" method instead of overloading the "~=" operator?

It should (in addition to put).  I see you have already filed an enhancement.

http://d.puremagic.com/issues/show_bug.cgi?id=4287

-Steve
October 13, 2015
On Monday, 5 March 2012 at 15:35:59 UTC, Steven Schveighoffer wrote:
> On Wed, 29 Feb 2012 20:25:35 -0500, bearophile <bearophileHUGS@lycos.com> wrote:
>
>> Do you know why std.array.Appender defines a "put" method instead of overloading the "~=" operator?
>
> It should (in addition to put).  I see you have already filed an enhancement.
>
> http://d.puremagic.com/issues/show_bug.cgi?id=4287
>
> -Steve

Can I use Appender to add at end of every string my symbol?

	foreach (pointsfile; pointsFiles)
	{
		File file = File(pointsfile, "r");
		string content = file.byLine; // I need to add "+" at at end of every string
	}





October 13, 2015
I tried to use map! but it's look like it do not work with string, becouse I got error: Error: no property 'map' for type 'ByLine!(char, char)'
October 13, 2015
On Tuesday, 13 October 2015 at 13:21:54 UTC, Suliman wrote:
> I tried to use map! but it's look like it do not work with string, becouse I got error: Error: no property 'map' for type 'ByLine!(char, char)'

I suspect you don't have it imported.

import std.algorithm;

or

import std.algorithm : map;
October 13, 2015
On Tuesday, 13 October 2015 at 13:34:02 UTC, John Colvin wrote:
> On Tuesday, 13 October 2015 at 13:21:54 UTC, Suliman wrote:
>> I tried to use map! but it's look like it do not work with string, becouse I got error: Error: no property 'map' for type 'ByLine!(char, char)'
>
> I suspect you don't have it imported.
>
> import std.algorithm;
>
> or
>
> import std.algorithm : map;

Thanks, you are right! Can I add with map some element before and after string? map!(a=> a~=" +") work fine, but how to add before at same time?
October 13, 2015
something like: auto content = file.byLine.map!("start " ~ a=>a ~ " end");
October 13, 2015
On Tuesday 13 October 2015 15:42, Suliman wrote:

> map!(a=> a~=" +") work fine, but how to add before at same time?

Use ~ instead of ~=, like so: map!(a => "+" ~ a ~ "+")