[pure-lang-svn] SF.net SVN: pure-lang: [408] pure/trunk/examples/libor
Status: Beta
Brought to you by:
agraef
From: <ye...@us...> - 2008-07-07 00:32:34
|
Revision: 408 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=408&view=rev Author: yes Date: 2008-07-06 17:32:43 -0700 (Sun, 06 Jul 2008) Log Message: ----------- use init in date.pure, improve some indentation in myutils.pure Modified Paths: -------------- pure/trunk/examples/libor/date.pure pure/trunk/examples/libor/myutils.pure Modified: pure/trunk/examples/libor/date.pure =================================================================== --- pure/trunk/examples/libor/date.pure 2008-07-07 00:14:35 UTC (rev 407) +++ pure/trunk/examples/libor/date.pure 2008-07-07 00:32:43 UTC (rev 408) @@ -35,7 +35,7 @@ secsnow = time mod secsinday; // int seconds since midnight // strip the inconvenient \n off strings given by ctime, gmtime -stripnl s::string = reverse (tail (reverse s)); +stripnl s::string = init s; // either mayan or julian posix epoch (and posix time) as a mjday number mjday epoch::int secs::int |mjday epoch::int secs::bigint= epoch+secs/secsinday; Modified: pure/trunk/examples/libor/myutils.pure =================================================================== --- pure/trunk/examples/libor/myutils.pure 2008-07-07 00:14:35 UTC (rev 407) +++ pure/trunk/examples/libor/myutils.pure 2008-07-07 00:32:43 UTC (rev 408) @@ -1,7 +1,5 @@ -/* General Utilities - Copyright (c) 2008 by Libor Spacek */ +/* General Utilities Copyright (c) 2008 by Libor Spacek */ -//(1) Mathematics //General mathematical iterators over one and two indices MathIter1 op i1 i2 f = foldl1 op (map f (i1..i2)); @@ -10,14 +8,12 @@ //Examples on how to use the mathematical iterators Sigma i1 i2 f = MathIter1 (+) i1 i2 f; - Pi i1 i2 f = MathIter1 (*) i1 i2 f; - Factorial n = Pi 1L n id; //Binomial using (k, n-k) symmetry and bignum division Binomial n k = (Pi (k+1L) n id) div (Pi 2L (n-k) id) if n-k < k; - = (Pi (n-k+1L) n id) div (Pi 2L k id); + = (Pi (n-k+1L) n id) div (Pi 2L k id); // Euclid's recursive greatest common factor algorithm for ints and bignums Gcf x 0 | Gcf x 0L = x; @@ -34,5 +30,7 @@ // rotate n items, cf. "rotate n bits instruction" (n can now also be negative) // example applied to clocks: >head (nrotate (-33) (0..23)); // what time is 33 hrs before midnight? Answer: 15 hrs. -nrotate n::int l = protate nm l when ll = #l; nm = ll + (n mod ll) end if n<0; - = protate nm l when nm = n mod #l end; +nrotate n::int l + = protate nm l when ll = #l; nm = ll + (n mod ll) end if n<0; + = protate nm l when nm = n mod #l end; + \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |