[pure-lang-svn] SF.net SVN: pure-lang:[881] pure/trunk/pure.1.in
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-09-27 05:35:51
|
Revision: 881 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=881&view=rev Author: agraef Date: 2008-09-27 05:35:40 +0000 (Sat, 27 Sep 2008) Log Message: ----------- Fix some minor glitches in the documentation. Modified Paths: -------------- pure/trunk/pure.1.in Modified: pure/trunk/pure.1.in =================================================================== --- pure/trunk/pure.1.in 2008-09-27 04:57:33 UTC (rev 880) +++ pure/trunk/pure.1.in 2008-09-27 05:35:40 UTC (rev 881) @@ -416,7 +416,9 @@ ``conses'', and `,' produces ``pairs''. As indicated, Pure provides the usual syntactic sugar for list values in brackets, such as [x,y,z], which is exactly the same as x:y:z:[]. Moreover, the prelude also provides an infix `..' -operator to denote arithmetic sequences such as 1..10 or 1.0,1.2..3.0. +operator to denote arithmetic sequences such as 1..10. Sequences with +arbitrary stepsizes can be written by denoting the first two sequence +elements using the `:' operator, as in 1.0:1.2..3.0. .sp Pure's tuples are a bit unusual: They are constructed by just ``pairing'' things using the `,' operator, for which the empty tuple acts as a neutral @@ -914,7 +916,7 @@ .nf primes n = sieve (2..n) \fBwith\fP sieve [] = []; - sieve (p:qs) = p : sieve [q; q = qs; q mod p]; + sieve (p:qs) = p : sieve [q | q = qs; q mod p]; \fBend\fP; .fi .sp @@ -941,12 +943,12 @@ in check. .sp .nf -queens n = search n 1 [] \fBwith\fP - search n i p = [reverse p] \fBif\fP i>n; - = 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; +queens n = search n 1 [] \fBwith\fP + search n i p = [reverse p] \fBif\fP i>n; + = 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; + = i1==i2 || j1==j2 || i1+j1==i2+j2 || i1-j1==i2-j2; \fBend\fP; .fi .SS Lazy Evaluation and Streams @@ -1103,7 +1105,7 @@ to denote an upper (or lower) infinite bound for the sequence, e.g.: .sp .nf -> let u = 1..inf; let v = -1.0,-1.2..-inf; +> let u = 1..inf; let v = -1.0:-1.2..-inf; > takel 10 u; takel 10 v; [1,2,3,4,5,6,7,8,9,10] [-1.0,-1.2,-1.4,-1.6,-1.8,-2.0,-2.2,-2.4,-2.6,-2.8] @@ -1126,7 +1128,7 @@ appropriate stream result: .sp .nf -> \fBlet\fP rats = [m,n-m; n=2..inf; m=1..n-1; gcd m (n-m) == 1]; rats; +> \fBlet\fP rats = [m,n-m | n=2..inf; m=1..n-1; gcd m (n-m) == 1]; rats; (1,1):#<thunk 0xb5fd08b8> > takel 10 rats; [(1,1),(1,2),(2,1),(1,3),(3,1),(1,4),(2,3),(3,2),(4,1),(1,5)] @@ -1139,7 +1141,7 @@ .sp .nf all_primes = sieve (2..inf) \fBwith\fP - sieve (p:qs) = p : sieve [q; q = qs; q mod p] &; + sieve (p:qs) = p : sieve [q | q = qs; q mod p] &; \fBend\fP; .fi .sp @@ -1423,8 +1425,8 @@ .sp .nf > \fBusing\fP system; -> f = [printf "%g\en" (2^x+1); x=1..5; x mod 2]; -> g = void [printf "%g\en" (2^x+1); x=1..5; x mod 2]; +> f = [printf "%g\en" (2^x+1) | x=1..5; x mod 2]; +> g = void [printf "%g\en" (2^x+1) | x=1..5; x mod 2]; > \fBshow\fP f g f = catmap (\ex -> if x mod 2 then [printf "%g\n" (2^x+1)] else []) (1..5); g = do (\ex -> if x mod 2 then [printf "%g\n" (2^x+1)] else []) (1..5); @@ -1447,7 +1449,7 @@ the outermost `catmap' if the list comprehension binds multiple variables: .sp .nf -> u = void [puts $ str (x,y); x=1..2; y=1..3]; +> u = void [puts $ str (x,y) | x=1..2; y=1..3]; > \fBshow\fP u u = do (\ex -> catmap (\ey -> [puts (str (x,y))]) (1..3)) (1..2); .fi @@ -1456,7 +1458,7 @@ a nested list comprehension which expands to a nested `do': .sp .nf -> v = void [void [puts $ str (x,y); y=1..3]; x=1..2]; +> v = void [void [puts $ str (x,y) | y=1..3] | x=1..2]; > \fBshow\fP v v = do (\ex -> [do (\ey -> [puts (str (x,y))]) (1..3)]) (1..2); .fi @@ -1810,12 +1812,12 @@ regularly returns with () to indicate that there is no solution. .sp .nf -queens1 n = catch reverse (search n 1 []) \fBwith\fP - search n i p = throw p \fBif\fP i>n; - = 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; +queens1 n = catch reverse (search n 1 []) \fBwith\fP + search n i p = throw p \fBif\fP i>n; + = 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; + = i1==i2 || j1==j2 || i1+j1==i2+j2 || i1-j1==i2-j2; \fBend\fP; .fi .PP @@ -2449,9 +2451,11 @@ .sp .nf > \fBshow\fP -g foldl* +foldl f a x::matrix = foldl f a (list x); foldl f a s::string = foldl f a (chars s); foldl f a [] = a; foldl f a (x:xs) = foldl f (f a x) xs; +foldl1 f x::matrix = foldl1 f (list x); foldl1 f s::string = foldl1 f (chars s); foldl1 f (x:xs) = foldl f x xs; .fi This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |