My thoughts & experiences with D so far, as a novice D coder

Jonathan M Davis jmdavisProg at gmx.com
Thu Mar 28 18:13:22 PDT 2013


On Friday, March 29, 2013 00:38:25 Vidar Wahlberg wrote:
> I don't get why you need to drag in std.array.appender() for
> std.bitmanip.append(), when you don't need it for read() and
> write().

Because read and write operate in place, and append doesn't. read and write 
operate on input ranges - read just reads the values from it as it iterates, 
and write overwrites what's there as it iterates. However, append uses an 
output range, because it's appending rather than overwriting, and for reasons 
that I don't understand, when treating an array as an output range, rather 
than appending (like an output range normally would), the put function (which 
is how stuff gets written to an output range) overwrites what's in the array 
rather than appending to it. So, using an empty array with any function 
operating on output ranges isn't going to work. Maybe there's a good reason 
for arrays working that way when they're treated as output ranges, but for me, 
it's a good reason to not use arrays when you need an output range.

In either case, I'd suggest reading this if you want to know more about 
ranges:

http://ddili.org/ders/d.en/ranges.html

And since D's standard library ranges quite heavily, you're going to need at 
least a basic understanding of them if you want to use much of it. We really 
need a good article on ranges on dlang.org, but until we do, that link is 
probably your best resource for learning about ranges.

- Jonathan M Davis


More information about the Digitalmars-d mailing list