On Sat, 2011-03-12 at 02:15 -0800, Ali Çehreli wrote: [ . . . ] > void main() > { > long[] data = [ 0, 1, 1, 2, 3, 5, 8 ]; > > foreach (n; 0 .. data.length) { > assert(equal(declarative(n), data[0..n])); > } > }
In fact the driver is: unittest { immutable data = [ [ 0 , 0 ] , [ 1 , 1 ] , [ 2 , 1 ] , [ 3 , 2 ] , [ 4 , 3 ] , [ 5 , 5 ] , [ 6 , 8 ] , [ 7 , 13 ] , [ 8 , 21 ] , [ 9 , 34 ] , [ 10 , 55 ] , [ 11 , 89 ] , [ 12 , 144 ] , [ 13 , 233 ] , ] ; foreach ( item ; data ) { assert ( iterative ( item[0] ) == item[1] ) ; } foreach ( item ; data ) { assert ( declarative ( item[0] ) == item[1] ) ; } } so I need to index the take-n list to return the last value. This of course brings up the question of the signature of any factorial function. Without a real use case it is a rhetorical question. What is nice though is that there could be a neat way of generating a memoized, i.e. cached, lazy list. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: rus...@russel.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
signature.asc
Description: This is a digitally signed message part