Fibonacci with ranges
Russel Winder
russel at russel.org.uk
Sat Mar 12 01:33:34 PST 2011
On Fri, 2011-03-11 at 18:46 -0500, Jesse Phillips wrote:
> Without testing: foreach (f; take(recurrence!("a[n-1] + a[n-2]")(0UL, 1UL), 50))
>
> teo Wrote:
>
> > Just curious: How can I get ulong here?
> >
> > foreach (f; take(recurrence!("a[n-1] + a[n-2]")(0, 1), 50))
> > {
> > writeln(f);
> > }
>
Interestingly, or not, the code:
long declarative ( immutable long n ) {
return take ( recurrence ! ( "a[n-1] + a[n-2]" ) ( 0L , 1L ) , n ) ;
}
results in the return statement delivering:
rdmd --main -unittest fibonacci_d2.d
fibonacci_d2.d(15): Error: template std.range.take(R) if (isInputRange!(Unqual!(R)) && !isSafelySlicable!(Unqual!(R)) && !is(Unqual!(R) T == Take!(T))) does not match any function template declaration
fibonacci_d2.d(15): Error: template std.range.take(R) if (isInputRange!(Unqual!(R)) && !isSafelySlicable!(Unqual!(R)) && !is(Unqual!(R) T == Take!(T))) cannot deduce template function from argument types !()(Recurrence!(fun,long,2u),immutable(long))
which seems deeply impenetrable for mere mortals.
--
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/24f93f97/attachment.pgp>
More information about the Digitalmars-d-learn
mailing list