Fibonacci with ranges

Russel Winder russel at russel.org.uk
Sat Mar 12 02:31:20 PST 2011


Jonathan,

Thanks for the info, very helpful.  One point though:

On Sat, 2011-03-12 at 01:56 -0800, Jonathan M Davis wrote:
[ . . . ]
> What's happening is that the parameter that you're passing n to for recurrence 
> is size_t. And on 32-bit systems, size_t is uint, so passing n - which is long - 
> to recurrence would be a narrowing conversion, which requires a cast. The 
> correct thing to do would be make n a size_t. The other thing that you'd need to 
> do is change declarative to return auto, since take returns a range, _not_ a 
> long.

It seems that D is falling into the same bear trap as C++ (and C?)
descended into long ago.  When a programmer want an int or a long, they
actually have to decide whether they need a size_t.  To be honest this
is a simple WTF!!!

Go really has this right.  int  does not exist, neither does long.
int32, int64 -- no ambiguity.  Why C++ and D have to continue with the
pretence of platform independent types when they are far from platform
independent seems counter-productive.

<post-facto-rant-warning/>

Thanks for the pointer about the take, I need to select just the last
entry in the range and return that.

> In any case, it _would_ be nice if the compiler gave a more informative message 
> about _why_ the template failed to instantiate - especially since it's _not_ the 
> template constraint which is the problem - but unfortunately, the compiler just 
> isn't that smart about template instantiation errors.

C++ is bad enough, if D cannot improve on it . . .   :-((

-- 
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 russel.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: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20110312/1d42bcf1/attachment.pgp>


More information about the Digitalmars-d-learn mailing list