[pure-lang-svn] SF.net SVN: pure-lang:[809] pure/trunk/examples
Status: Beta
Brought to you by:
agraef
|
From: <ag...@us...> - 2008-09-20 16:46:36
|
Revision: 809
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=809&view=rev
Author: agraef
Date: 2008-09-20 16:46:14 +0000 (Sat, 20 Sep 2008)
Log Message:
-----------
Fix deprecated list comprehension syntax.
Modified Paths:
--------------
pure/trunk/examples/hello.pure
pure/trunk/examples/libor/myutils.pure
pure/trunk/examples/libor/queens.pure
Modified: pure/trunk/examples/hello.pure
===================================================================
--- pure/trunk/examples/hello.pure 2008-09-20 16:39:35 UTC (rev 808)
+++ pure/trunk/examples/hello.pure 2008-09-20 16:46:14 UTC (rev 809)
@@ -141,7 +141,7 @@
the same little 2.5-liner. ;-) */
qsort p [] = [];
-qsort p (x:xs) = qsort p [l; l = xs; l<x] + (x : qsort p [r; r = xs; r>=x])
+qsort p (x:xs) = qsort p [l | l = xs; l<x] + (x : qsort p [r | r = xs; r>=x])
with x<y = p x y; x>=y = not p x y end;
qsort (<) (1..20); // ascending sort, no-op in this case
@@ -153,15 +153,15 @@
extern int rand();
-qsort (<) [rand; i = 1..20]; // sort 20 random numbers in ascending order
-qsort (>) [rand; i = 1..20]; // sort 20 random numbers in descending order
+qsort (<) [rand|i = 1..20]; // sort 20 random numbers in ascending order
+qsort (>) [rand|i = 1..20]; // sort 20 random numbers in descending order
/* Erathosthenes' classical prime sieve. Another example showing the beauty
and usefulness of list comprehensions. */
primes n = sieve (2..n) with
sieve [] = [];
- sieve (p:qs) = p : sieve [q; q = qs; q mod p];
+ sieve (p:qs) = p : sieve [q | q = qs; q mod p];
end;
primes 100;
@@ -170,7 +170,7 @@
prime numbers. */
all_primes = sieve (2..inf) with
- sieve (p:qs) = p : sieve [q; q = qs; q mod p] &;
+ sieve (p:qs) = p : sieve [q | q = qs; q mod p] &;
end;
// Assign this to a variable, so we can take advantage of memoization.
@@ -193,7 +193,7 @@
queens n = search n 1 []
with
search n i p = [reverse p] if i>n;
- = cat [search n (i+1) ((i,j):p); j = 1..n; safe (i,j) p];
+ = cat [search n (i+1) ((i,j):p) | j = 1..n; safe (i,j) p];
safe (i,j) p = not any (check (i,j)) p;
check (i1,j1) (i2,j2)
= i1==i2 || j1==j2 || i1+j1==i2+j2 || i1-j1==i2-j2;
@@ -206,7 +206,7 @@
queens1 n = catch reverse (search n 1 [])
with
search n i p = throw p if i>n;
- = void [search n (i+1) ((i,j):p); j = 1..n; safe (i,j) p];
+ = void [search n (i+1) ((i,j):p) | j = 1..n; safe (i,j) p];
safe (i,j) p = not any (check (i,j)) p;
check (i1,j1) (i2,j2)
= i1==i2 || j1==j2 || i1+j1==i2+j2 || i1-j1==i2-j2;
@@ -286,4 +286,4 @@
// A random example:
-let xs = [rand; i = 1..20]; let T = bintree xs; xs; T; members T;
+let xs = [rand|i = 1..20]; let T = bintree xs; xs; T; members T;
Modified: pure/trunk/examples/libor/myutils.pure
===================================================================
--- pure/trunk/examples/libor/myutils.pure 2008-09-20 16:39:35 UTC (rev 808)
+++ pure/trunk/examples/libor/myutils.pure 2008-09-20 16:46:14 UTC (rev 809)
@@ -4,7 +4,7 @@
MathIter1 op i1 i2 f = foldl1 op (map f (i1..i2));
MathIter2 op i1 i2 j1 j2 f =
- foldl1 op (map (uncurry f) [x,y; x = i1..i2; y = j1..j2]);
+ foldl1 op (map (uncurry f) [x,y | x = i1..i2; y = j1..j2]);
//Examples on how to use the mathematical iterators
Sigma i1 i2 f = MathIter1 (+) i1 i2 f;
Modified: pure/trunk/examples/libor/queens.pure
===================================================================
--- pure/trunk/examples/libor/queens.pure 2008-09-20 16:39:35 UTC (rev 808)
+++ pure/trunk/examples/libor/queens.pure 2008-09-20 16:46:14 UTC (rev 809)
@@ -20,7 +20,7 @@
with
searchall n::int 0 p = p;
searchall n::int i::int p =
- tuple [searchall n (i-1) (j:p); j = 1..n; safe 1 j p]
+ tuple [searchall n (i-1) (j:p) | j = 1..n; safe 1 j p]
end;
// the solution is only the rows permutation, without the ordered columns (1..n)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|