[pure-lang-svn] SF.net SVN: pure-lang:[703] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-09-04 16:14:15
|
Revision: 703 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=703&view=rev Author: agraef Date: 2008-09-04 16:14:26 +0000 (Thu, 04 Sep 2008) Log Message: ----------- Prelude changes. Modified Paths: -------------- pure/trunk/lib/prelude.pure pure/trunk/test/prelude.log Modified: pure/trunk/lib/prelude.pure =================================================================== --- pure/trunk/lib/prelude.pure 2008-09-04 16:13:51 UTC (rev 702) +++ pure/trunk/lib/prelude.pure 2008-09-04 16:14:26 UTC (rev 703) @@ -89,6 +89,10 @@ uncurry3 f (x,y,z) = f x y z; +/* The (normal order) fixed point combinator. */ + +fix f = y y when y = \x -> f (x x&) end; + /* Some convenient optimization rules which eliminate saturated calls of the function composition combinators. */ @@ -211,7 +215,7 @@ accum ys xs = throw (bad_list_value xs); end; -/* Convert between lists and tuples. */ +/* Conversions between lists, tuples and streams. */ list () = []; list (x,xs) = accum [x] xs with @@ -226,8 +230,6 @@ accum ys xs = ys,xs; end; -/* Convert between lists and streams. */ - list [] = []; list (x:xs) = x:list xs; @@ -235,6 +237,9 @@ stream (x:xs) = x:xs if thunkp xs; = x:stream xs& otherwise; +stream () = []; +stream xs@(_,_) = stream (list xs); + /* Slicing. xs!!ns returns the list of xs!n for all members n of the index list ns which are in the valid index range. This is a generic definition which will work with any kind of container data structure which defines (!) Modified: pure/trunk/test/prelude.log =================================================================== --- pure/trunk/test/prelude.log 2008-09-04 16:13:51 UTC (rev 702) +++ pure/trunk/test/prelude.log 2008-09-04 16:14:26 UTC (rev 703) @@ -9,6 +9,17 @@ curry3 f/*0:0001*/ x/*0:001*/ y/*0:01*/ z/*0:1*/ = f/*0:0001*/ (x/*0:001*/,y/*0:01*/,z/*0:1*/); uncurry f/*0:01*/ (x/*0:101*/,y/*0:11*/) = f/*0:01*/ x/*0:101*/ y/*0:11*/; uncurry3 f/*0:01*/ (x/*0:101*/,y/*0:1101*/,z/*0:111*/) = f/*0:01*/ x/*0:101*/ y/*0:1101*/ z/*0:111*/; +fix f/*0:1*/ = y/*0:*/ y/*0:*/ when y/*0:*/ = \x/*0:*/ -> f/*1:1*/ (x/*1:*/ x/*1:*/&) { + rule #0: x = f (x x&) + state 0: #0 + <var> state 1 + state 1: #0 +} { + rule #0: y = \x -> f (x x&) + state 0: #0 + <var> state 1 + state 1: #0 +} end; def f/*0:01*/$x/*0:1*/ = f/*0:01*/ x/*0:1*/; def (f/*0:001*/.g/*0:01*/) x/*0:1*/ = f/*0:001*/ (g/*0:01*/ x/*0:1*/); def void (catmap f/*0:101*/ x/*0:11*/) = do f/*0:101*/ x/*0:11*/; @@ -303,6 +314,8 @@ stream [] = []; stream (x/*0:101*/:xs/*0:11*/) = x/*0:101*/:xs/*0:11*/ if thunkp xs/*0:11*/; stream (x/*0:101*/:xs/*0:11*/) = x/*0:101*/:stream xs/*1:11*/&; +stream () = []; +stream xs@(_/*0:101*/,_/*0:11*/) = stream (list xs/*0:1*/); xs/*0:01*/!!ns/*0:1*/ = catmap (nth/*0*/ xs/*0:01*/) ns/*0:1*/ with nth xs/*0:01*/ n/*0:1*/ = catch (cst []) [xs/*1:01*/!n/*1:1*/] { rule #0: nth xs n = catch (cst []) [xs!n] state 0: #0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |