May 11, 2008
Edward Diener wrote:
> Janice Caron wrote:
>>> Furthermore in D 1.0 a char[], a dynamic array of characters, is the
>>> equivalent of the C++ std::string. In the C++ std::string class there is a
>>> rich set of functionality for manipulating the char elements in the string,
>>> for finding particular elements in the string, and for comparing the
>>> character elements in strings with other strings, but I see little of this
>>> in dynamic array functionality. What am I missing ?
>>
>> std.string
>> std.algorithm
> 
> I do not see a std.algorithm in the D 1.0 Phobos docuemntation.

That's because D1 doesn't have it. Janice tends to be a bit more D2-oriented...

There's a port of D2 std.algorithm (and other D2 Phobos modules) available from <http://www.dsource.org/projects/std2>, but it's based on an older version (2.008) of Phobos. I have no idea if this is substantially different from the current D2 Phobos.
It might be worth checking out if you need the stuff it contains.
May 11, 2008
On 11/05/2008, Bill Baxter <dnewsgroup@billbaxter.com> wrote:
> std.algorithm's copy(), in its current form, will be less efficient because it copies elements one-at-a-time in a loop.

That may be what the source code does, but it's the compiler's job to optimize. If it doesn't, I blame the compiler :-)

Also, memmove can't be used in CTFE.


> Anyway, the existence of such subtleties is why things like erase should just be in the darn standard library so the problem only has to be solved once.

I agree.

Although, that said, I don't think anyone's really considered it a "problem" before now.
May 11, 2008
Janice Caron wrote:
> On 11/05/2008, Bill Baxter <dnewsgroup@billbaxter.com> wrote:
>> std.algorithm's copy(), in its current form, will be less efficient because
>> it copies elements one-at-a-time in a loop.
> 
> That may be what the source code does, but it's the compiler's job to
> optimize. If it doesn't, I blame the compiler :-)
> 
> Also, memmove can't be used in CTFE.

Does std.algorithm.copy work in CTFE?

>> Anyway, the existence of such subtleties is why things like erase
>> should just be in the darn standard library so the problem only has
>> to be solved once.
> 
> I agree.
> 
> Although, that said, I don't think anyone's really considered it a
> "problem" before now.

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

--bb
May 11, 2008
On 11/05/2008, Bill Baxter <dnewsgroup@billbaxter.com> wrote:
>  Does std.algorithm.copy work in CTFE?

I just tried it, and the answer's no. That seriously surprises me.

Apparently, it can't evaluate begin(target) at compile time.

OK - I withdraw that objection. (Although, of course, memmove will /never/ be CTFE compatible, whereas copy might be in the future).
May 11, 2008
Edward Diener wrote:
> In D 1.0 dynamic arrays are the equivalent of C++'s std::vector<T>, with slicing replacing iterators in order to access some subrange of the sequence. In C++ there is functionality in std::vector::erase for erasing elements from the vector and std::vector::insert for inserting new elements into the vector. Where is that functionality in D's dynamic arrays ?

The D string library is oriented more towards COW (copy-on-write) operations rather than in-place modification. Hence, things are biased towards slicing and concatenating strings.

> Furthermore in D 1.0 a char[], a dynamic array of characters, is the equivalent of the C++ std::string. In the C++ std::string class there is a rich set of functionality for manipulating the char elements in the string, for finding particular elements in the string,

std.string.find() for basic searches, std.regexp for more advanced ones.

> and for comparing the character elements in strings with other strings,

== works for array contents, too

> but I see little of this in dynamic array functionality. What am I missing ?

Can you be a bit more specific about what operation(s) you want to do?

> I am guessing this must be provided in D libraries of functions ( Phobos ? Tango ? ) templated on the dynamic array type. But, if so, this seems a poor way of providing dynamic array functionality as compared to built-in dynamic array functionality in order to provide the sort of functionality mentioned above, especially as D's dynamic arrays are part of the D language as opposed to a separate library like C++'s std::vector<T> and std::string.

I don't really understand your point. It sounds like you're suggesting that, by analogy, all floating point operations should be core language operations since floating point arithmetic is.
May 11, 2008
Janice Caron wrote:
> On 11/05/2008, Bill Baxter <dnewsgroup@billbaxter.com> wrote:
>>  Does std.algorithm.copy work in CTFE?
> 
> I just tried it, and the answer's no. That seriously surprises me.
> 
> Apparently, it can't evaluate begin(target) at compile time.
> 
> OK - I withdraw that objection. (Although, of course, memmove will
> /never/ be CTFE compatible, whereas copy might be in the future).

Eventually I think we'll need a "static if(is(CTFE))" or equivalent.
In that case functions like copy() could use a simpler fallback implementation in the "is(CTFE)" block, and use the fastest possible solution (e.g. memmove) in the non-CTFE case.

--bb
May 11, 2008
Walter Bright wrote:
> Edward Diener wrote:
>> In D 1.0 dynamic arrays are the equivalent of C++'s std::vector<T>, with slicing replacing iterators in order to access some subrange of the sequence. In C++ there is functionality in std::vector::erase for erasing elements from the vector and std::vector::insert for inserting new elements into the vector. Where is that functionality in D's dynamic arrays ?
> 
> The D string library is oriented more towards COW (copy-on-write) operations rather than in-place modification. Hence, things are biased towards slicing and concatenating strings.
> 
>> Furthermore in D 1.0 a char[], a dynamic array of characters, is the equivalent of the C++ std::string. In the C++ std::string class there is a rich set of functionality for manipulating the char elements in the string, for finding particular elements in the string,
> 
> std.string.find() for basic searches, std.regexp for more advanced ones.

OK, slicing gives much functionality for grabbing substrings and I appreciate the syntax ( I have programmed in Python ).

> 
>> and for comparing the character elements in strings with other strings,
> 
> == works for array contents, too

OK, good.

> 
>> but I see little of this in dynamic array functionality. What am I missing ?
> 
> Can you be a bit more specific about what operation(s) you want to do?

In the dynamic array world I would have expected functionlaity for erasing part of the array, inserting a new array at some point in the array, and for replacing any part of the array with another array of any 
 length. The replace is merely an erase + insert under the covers. Of course I am also talking about arrays of the same type.

> 
>> I am guessing this must be provided in D libraries of functions ( Phobos ? Tango ? ) templated on the dynamic array type. But, if so, this seems a poor way of providing dynamic array functionality as compared to built-in dynamic array functionality in order to provide the sort of functionality mentioned above, especially as D's dynamic arrays are part of the D language as opposed to a separate library like C++'s std::vector<T> and std::string.

Since dynamic arrays are part of the language and not a separate library I would have expected built-in functionality to manipulate them easily. Of course it can be in a library, but it seems even a general purpose dynamic array library does not exist for D 1.0, so that seems odd to me.
May 12, 2008
Edward Diener wrote:
> In the dynamic array world I would have expected functionlaity for erasing part of the array, inserting a new array at some point in the array, and for replacing any part of the array with another array of any 
>  length. The replace is merely an erase + insert under the covers. Of course I am also talking about arrays of the same type.

I agree.

> Since dynamic arrays are part of the language and not a separate library I would have expected built-in functionality to manipulate them easily. Of course it can be in a library, but it seems even a general purpose dynamic array library does not exist for D 1.0, so that seems odd to me.

It's demand driven <g>. Some of the functions in std.string may seem odd for someone coming from the C++ world, but they are functionally equivalent to Python's and Ruby's string functions.
May 12, 2008
Edward Diener wrote:

> but it seems even a general purpose dynamic array library does not exist for D 1.0, so that seems odd to me.

Yep. Me too.

Coming back to D was a real shock.

Kinda returning to the Ferrari factory after a similar period, having previously seen the prototype F450,When you left, it had clean lines, parred down framework and a great engine.

When you return you discover it's been fitted a hybrid drive train, a 1/4 tonne of batteries and the slick, 7-speed floor-shift has been swapped out for a 3-speed auto box.

The last thing I ever thought I would see, was D become "buzz-word complient". It's such a shame to see such a promising beginning get sidetracked off into a world of academic theory and computer science correctness. The promise was that because one guy with a pragmatic vision and the skills to make them so, held the ropes and was steering the thing, that D wouldn't be subject to the pull & push of academic group think nor the quagmire of design by committee.

b.
-- 

May 12, 2008
Edward Diener wrote:
> 
> Since dynamic arrays are part of the language and not a separate library I would have expected built-in functionality to manipulate them easily. Of course it can be in a library, but it seems even a general purpose dynamic array library does not exist for D 1.0, so that seems odd to me.

What would you suggest adding to tango.core.Array?  I assume insert and remove at some position... perhaps others as well?


Sean
1 2 3 4
Top | Discussion index | About this forum | D home