May 12, 2008
I haven't said any of the sort.

--------
On Mon, 12 May 2008 20:40:42 +0200, Me Here <p9e883002@sneakemail.com> wrote:

> boyd wrote:
>
>> I'm not saying either way is more efficient. I'm saying that slicing and
>> concatenation are lower level functionality than insert and delete. So  most
>> optimizations when using slicing and concatenation will be done by  the
>> programmer, rather than the compiler or library.
>
> You don't think that this is stuff that should be got right once and then just
> reused?
> You're not a /real D programmer/ unless reimplement these well-documented
> algorithms yourself?
>
> b.
May 12, 2008
"Bill Baxter" <dnewsgroup@billbaxter.com> wrote in message news:g0a82f$52q$1@digitalmars.com...
> Christopher Wright wrote:
>> If by 'scattered all over the place' you mean 'most everything suitable for all array types is in tango.core.Array and everything else is in tango.text.*', yes.
>
> I mean the * part of tango.text.*, which consitutes about 30 different files.  Not saying it's a bad design, but it does make it a little harder for me to find things.
>

Don't know if you mean "find things" in the documentation, but if you mean importing, there's this:

import tango.group.text;

http://www.dsource.org/projects/tango/docs/current/tango.group.text.html


May 13, 2008
boyd wrote:
> I think it's because erase and insert are really just the inverse of slicing and concatenation.
> 
> int[] a, c;
> 
> // insert
> c = a.insert(b, 10);
> c = a[0..10] ~ b ~ a[10..$];
> 
> // delete
> c = a.delete(&a[10..20]);
> c = a[0..10] ~ a[20..$];
> 
> I essence delete and insert are just another way of expressing slices and concatenations. Personally I prefer slicing and concatting stuff, because it expresses better what's actually happening.
> 
> Delete and Insert on the other hand are higher level and generally more intuitive. They leave optimization to the compiler/library. And I think most D-users like more control of optimizations than users of more high level languages.

You make a good point that things like delete, insert, and replace can be done with slicing and concatentaion. Thanks for bringing up these solutions. Having used Python extensively, where slicing is also a big part of lists, I should have realized that such operations are largely subsumed by slicing and concatenation in D. I have to take my C++ hat off and put my Python hat one when dealing with dynamic arrays in D.
May 13, 2008
Sean Kelly wrote:
> 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?

Actually once I realized that slicing and concatenation can do what is necessary to emulate 'remove', 'insert', and 'replace' fairly easily I understood that D covers array manipulation based on indices pretty well. Your tango.core.array emulates C++ algorithms on containers pretty nicely so I have nothing particular to suggest there since I have not tried it out enough. You just might want to take a look at the C++ container algorithms, if you have not already done so, to see if there is anything there you may have left out which you feel might be worthwhile doing in tango.core.Array. But I have no real criticism or suggestion for your module.

The only real problem with the slicing/concatenation model may be optimization. That may be a reason to still pursue the C++ model of dynamic array, aka std::vector, manipulations in Tango.core.array. But I have little objection if the design is clear, even if the code is not highly optimized.
May 13, 2008
Edward Diener wrote:
> boyd wrote:
>> I think it's because erase and insert are really just the inverse of slicing and concatenation.
>>
>> int[] a, c;
>>
>> // insert
>> c = a.insert(b, 10);
>> c = a[0..10] ~ b ~ a[10..$];
>>
>> // delete
>> c = a.delete(&a[10..20]);
>> c = a[0..10] ~ a[20..$];
>>
>> I essence delete and insert are just another way of expressing slices and concatenations. Personally I prefer slicing and concatting stuff, because it expresses better what's actually happening.
>>
>> Delete and Insert on the other hand are higher level and generally more intuitive. They leave optimization to the compiler/library. And I think most D-users like more control of optimizations than users of more high level languages.
> 
> You make a good point that things like delete, insert, and replace can be done with slicing and concatentaion. Thanks for bringing up these solutions. 

Part of the comment, though, was that delete/insert are "higher-level and generally more intuitive".  With that I agree.

> Having used Python extensively, where slicing is also a big
> part of lists, I should have realized that such operations are largely subsumed by slicing and concatenation in D. I have to take my C++ hat off and put my Python hat one when dealing with dynamic arrays in D.

Fine point, except Python lists also have append, extend, index, insert, pop, and remove methods which you can use when they express your intent better than fidgety slicing expressions.

--bb
May 13, 2008
> Fine point, except Python lists also have append, extend, index, insert, pop, and remove methods which you can use when they express your intent better than fidgety slicing expressions.
> 
> --bb

It's all a matter of taste. Making those functions is trivial in D; most are one-liners.
May 13, 2008
Robert Fraser wrote:
>> Fine point, except Python lists also have append, extend, index, insert, pop, and remove methods which you can use when they express your intent better than fidgety slicing expressions.
>>
>> --bb
> 
> It's all a matter of taste. Making those functions is trivial in D; most are one-liners.

And so we come around full circle.  We've been doing a lot of that on the newsgroup recently.

They are relatively trivial, but there are still some gotchas in making them safe and maximally efficient (e.g. using memmove for better performance, etc).

--bb
May 13, 2008
Bill Baxter wrote:
> Edward Diener wrote:
>> boyd wrote:
>>> I think it's because erase and insert are really just the inverse of slicing and concatenation.
>>>
>>> int[] a, c;
>>>
>>> // insert
>>> c = a.insert(b, 10);
>>> c = a[0..10] ~ b ~ a[10..$];
>>>
>>> // delete
>>> c = a.delete(&a[10..20]);
>>> c = a[0..10] ~ a[20..$];
>>>
>>> I essence delete and insert are just another way of expressing slices and concatenations. Personally I prefer slicing and concatting stuff, because it expresses better what's actually happening.
>>>
>>> Delete and Insert on the other hand are higher level and generally more intuitive. They leave optimization to the compiler/library. And I think most D-users like more control of optimizations than users of more high level languages.
>>
>> You make a good point that things like delete, insert, and replace can be done with slicing and concatentaion. Thanks for bringing up these solutions. 
> 
> Part of the comment, though, was that delete/insert are "higher-level and generally more intuitive".  With that I agree.
> 
>  > Having used Python extensively, where slicing is also a big
>> part of lists, I should have realized that such operations are largely subsumed by slicing and concatenation in D. I have to take my C++ hat off and put my Python hat one when dealing with dynamic arrays in D.
> 
> Fine point, except Python lists also have append, extend, index, insert, pop, and remove methods which you can use when they express your intent better than fidgety slicing expressions.

I don't know if slicing expressions are really "fidgety" but Python has more flexiblity in its mutable sequence functionality than D, even using slicing syntax.

It hijacks its own 'del' keyword to express 'remove' of some inner sequence using possible slicing notation, so maybe D can hijack 'delete' for a similar purpose with its dynamic array. It does have both a more flexible 'replace' than D, where the number of elements in the replacement does not have to equal the number of elements being replaced, as it has to in D. Finally it has a neat 'insert' which lets you insert another sequence, possibly using slicing, at any index.

Obviously D, or Python itself, can do these things purely through slicing-concatenation-reassignment but I agree the "higher level" equivalent syntax in Python is easier to understand, as well as possibly being bettered optimized.
Next ›   Last »
1 2 3 4
Top | Discussion index | About this forum | D home