Thread: [pure-lang-svn] SF.net SVN: pure-lang: [46] pure/trunk/examples/hello.pure
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-05-04 08:55:46
|
Revision: 46 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=46&view=rev Author: agraef Date: 2008-05-04 01:55:48 -0700 (Sun, 04 May 2008) Log Message: ----------- Make use of new bigint notation. Modified Paths: -------------- pure/trunk/examples/hello.pure Modified: pure/trunk/examples/hello.pure =================================================================== --- pure/trunk/examples/hello.pure 2008-05-04 07:10:41 UTC (rev 45) +++ pure/trunk/examples/hello.pure 2008-05-04 08:55:48 UTC (rev 46) @@ -117,9 +117,9 @@ // constant stack space. It also uses bigints so that the arithmetically // correct values are computed for large n. -fib3 n = a when a, b = fibs (0, 1) n end +fib3 n = a when a, b = fibs (0G, 1G) n end with fibs (a, b) n = a, b if n<=0; - = fibs (b, bigint a+b) (n-1) otherwise; + = fibs (b, a+b) (n-1) otherwise; end; map fib1 (1..10); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-05-04 10:44:54
|
Revision: 51 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=51&view=rev Author: agraef Date: 2008-05-04 03:44:58 -0700 (Sun, 04 May 2008) Log Message: ----------- Cosmetic change. Modified Paths: -------------- pure/trunk/examples/hello.pure Modified: pure/trunk/examples/hello.pure =================================================================== --- pure/trunk/examples/hello.pure 2008-05-04 10:10:37 UTC (rev 50) +++ pure/trunk/examples/hello.pure 2008-05-04 10:44:58 UTC (rev 51) @@ -55,8 +55,6 @@ fact1 n = n*fact1 (n-1) if n>0; = 1 otherwise; -let x = fact1 10; - // This is essentially the same, but uses a 'case' expression. fact2 n = case n of This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-05-10 18:25:38
|
Revision: 69 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=69&view=rev Author: agraef Date: 2008-05-10 11:25:45 -0700 (Sat, 10 May 2008) Log Message: ----------- Cosmetic changes. Modified Paths: -------------- pure/trunk/examples/hello.pure Modified: pure/trunk/examples/hello.pure =================================================================== --- pure/trunk/examples/hello.pure 2008-05-08 22:20:08 UTC (rev 68) +++ pure/trunk/examples/hello.pure 2008-05-10 18:25:45 UTC (rev 69) @@ -55,18 +55,18 @@ fact1 n = n*fact1 (n-1) if n>0; = 1 otherwise; +// Using pattern matching (note the constant pattern on the lhs of eqn. #1). + +fact2 0 = 1; +fact2 n = n*fact2 (n-1) if n>0; + // This is essentially the same, but uses a 'case' expression. -fact2 n = case n of - n = n*fact2 (n-1) if n>0; - = 1 otherwise; +fact3 n = case n of + 0 = 1; + n = n*fact3 (n-1) if n>0; end; -// Using pattern matching (note the constant pattern on the lhs of eqn. #1). - -fact3 0 = 1; -fact3 n = n*fact3 (n-1) if n>0; - // Using 'if-then-else'. fact4 n = if n>0 then n*fact4 (n-1) else 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-07-08 10:53:03
|
Revision: 421 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=421&view=rev Author: agraef Date: 2008-07-08 03:53:09 -0700 (Tue, 08 Jul 2008) Log Message: ----------- Comment change. Modified Paths: -------------- pure/trunk/examples/hello.pure Modified: pure/trunk/examples/hello.pure =================================================================== --- pure/trunk/examples/hello.pure 2008-07-08 10:51:02 UTC (rev 420) +++ pure/trunk/examples/hello.pure 2008-07-08 10:53:09 UTC (rev 421) @@ -232,9 +232,9 @@ /* Lists are all good and fine, but what about other, more complicated kinds of data? Luckily, as a term rewriting language Pure is well-suited to process any kind of tree-structured data. We only discuss a simple example - here, but using similar, more elaborate techniques like AVL trees, it is - possible to implement almost any kind of container data structure in an - efficient way. + here, but using similar, more elaborate techniques like AVL trees (see + avltree.pure for an example), it is possible to implement almost any kind + of container data structure in an efficient way. So let's see how we can implement simple binary search trees in Pure. These are represented using the constant symbol 'nil' (which denotes the empty This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-06-27 00:24:33
|
Revision: 318 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=318&view=rev Author: agraef Date: 2008-06-26 17:24:41 -0700 (Thu, 26 Jun 2008) Log Message: ----------- Add 'def' example. Modified Paths: -------------- pure/trunk/examples/hello.pure Modified: pure/trunk/examples/hello.pure =================================================================== --- pure/trunk/examples/hello.pure 2008-06-27 00:11:58 UTC (rev 317) +++ pure/trunk/examples/hello.pure 2008-06-27 00:24:41 UTC (rev 318) @@ -47,6 +47,12 @@ // Pattern matching definition with 'let'. let x, y = square x, square (x+2); x; y; +// We also have constant definitions using 'def' in lieu of 'let'. These +// cannot be redefined and are substituted directly into other definitions. +// Try something like 'foo x = pi*x;' and then 'list foo' to see the +// difference. +def pi = 3.14159265358979; + /* Variations on a theme: The factorial. This illustrates various different ways to define a simple recursive function. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |