Fibonacci with ranges
Russel Winder
russel at russel.org.uk
Sat Mar 12 01:38:22 PST 2011
On Sat, 2011-03-12 at 09:33 +0000, Russel Winder wrote:
[ . . . ]
> 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.
Sorry I needed to add the driver code:
foreach ( item ; data ) {
assert ( declarative ( item[0] ) == item[1] ) ;
}
within a unittest block.
--
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/40afcc79/attachment.pgp>
More information about the Digitalmars-d-learn
mailing list