Templates problem

Russel Winder via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Sep 7 04:37:44 PDT 2016


On Wed, 2016-09-07 at 09:04 +0000, Lodovico Giaretta via Digitalmars-d-
learn wrote:
> 
[…]
> You have your const fixed-length array. You slice it and you 
> obtain a const range to feed map. Now map will not return you an 
> array. Because most of the time you don't need it. It will return 
> you a range that lazily computes its elements on demand. No 
> memory allocation at all. You can do a foreach on that range. If 
> you need to access those elements more than once, instead of 
> recomputing each of them every time it is accessed, you can store 
> the results of the map. You simply have to use .array on the map 
> result. This will allocate memory and give you an array with your 
> results. Otherwise, no allocation at all. That result array can 
> be const, if you want. If you need to access your elements only 
> once, there's no need to have an array.

The problem for me had been that ranges are mutable or useless since
they are single use destructive things. So yes trying to add immutable
or const to it is breaking the range model.

The real problem though is the terrifying error message. I am having a
hard time finding a way of pitching them to Pythonistas.


> I really don't see what's not working in this.

Trying to get new D users from Python users is the main problem. 

> And by the way, there's no need to put const on everything. An 
> optimizing compiler is often able to infer things, especially for 
> stack allocated local variables.

I'd prefer immutable, but const sometimes has to do. The idea is to
find out how to enforce single assignment in D. 


-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20160907/e8d19477/attachment.sig>


More information about the Digitalmars-d-learn mailing list