[pure-lang-svn] SF.net SVN: pure-lang: [325] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-06-27 22:53:42
|
Revision: 325 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=325&view=rev Author: agraef Date: 2008-06-27 15:53:51 -0700 (Fri, 27 Jun 2008) Log Message: ----------- Restrict definition of the slicing operation to lists and tuples, and simplify it by using a list comprehension. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/lib/prelude.pure pure/trunk/test/prelude.log Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-06-27 20:05:31 UTC (rev 324) +++ pure/trunk/ChangeLog 2008-06-27 22:53:51 UTC (rev 325) @@ -1,11 +1,13 @@ -2008-06-27 Albert Graef <Dr....@t-...> +2008-06-28 Albert Graef <Dr....@t-...> * lib/prelude.pure: Using xs!ns for slicing conflicts with more general indexing of containers with arbitrary keys. Use !! for - slicing instead, as suggested by Jiri Spitz. Also make slicing - fail if indices aren't machine ints, and throw a bad_list_value - exception if computing the size of the container fails. + slicing instead. Restrict the definition to lists and tuples, and + simplify it by using a list comprehension. Suggested by Jiri + Spitz. +2008-06-27 Albert Graef <Dr....@t-...> + * runtime.cc/h: Added pure_current_interp(), variable and constant definitions, management of temporary definition levels. Modified: pure/trunk/lib/prelude.pure =================================================================== --- pure/trunk/lib/prelude.pure 2008-06-27 20:05:31 UTC (rev 324) +++ pure/trunk/lib/prelude.pure 2008-06-27 22:53:51 UTC (rev 325) @@ -186,23 +186,11 @@ end; /* Slicing. xs!!ns returns the list of xs!n for all members n of the index - list ns which are in the range 0..#xs-1. This works on any data structure - with zero-based indices and a contiguous index range. This includes, in - particular, the list and tuple structures defined above. Note that this - definition requires that the indices be machine ints, otherwise the - operation will fail. Also, you'll get a 'bad_list_value' exception if we - can't determine the size of xs using the # operator. */ + list ns which are in the range 0..#xs-1. xs must be a (proper) list or + tuple, and the indices must be machine ints. */ -xs!![] = []; -xs!!(n::int:ns) = accum [] (n:ns) with - accum ys [] = reverse ys; - accum ys (n::int:ns) = accum (xs!n:ys) ns if n>=0 && n<m; - = accum ys ns otherwise; - accum ys (n:ns) = reverse ys+xs!!(n:ns); - accum ys ns = reverse ys+xs!!ns; -end when - m::int = case #xs of m::int = m; _ = throw (bad_list_value xs) end; -end; +xs!!ns = [xs!n; n=ns; n>=0 && n<m] when m::int = #xs end + if listp xs || tuplep xs; /* Arithmetic sequences. */ Modified: pure/trunk/test/prelude.log =================================================================== --- pure/trunk/test/prelude.log 2008-06-27 20:05:31 UTC (rev 324) +++ pure/trunk/test/prelude.log 2008-06-27 22:53:51 UTC (rev 325) @@ -591,58 +591,17 @@ state 12: #0 #2 state 13: #1 #2 } end; -xs/*0:01*/!![] = []; -xs/*0:01*/!!(n/*0:101*/::int:ns/*0:11*/) = accum/*0*/ [] (n/*1:101*/:ns/*1:11*/) with accum ys/*0:01*/ [] = reverse ys/*0:01*/; accum ys/*0:01*/ (n/*0:101*/::int:ns/*0:11*/) = accum/*1*/ (xs/*2:01*/!n/*0:101*/:ys/*0:01*/) ns/*0:11*/ if n/*0:101*/>=0&&n/*0:101*/<m/*1:*/; accum ys/*0:01*/ (n/*0:101*/::int:ns/*0:11*/) = accum/*1*/ ys/*0:01*/ ns/*0:11*/; accum ys/*0:01*/ (n/*0:101*/:ns/*0:11*/) = reverse ys/*0:01*/+xs/*2:01*/!!(n/*0:101*/:ns/*0:11*/); accum ys/*0:01*/ ns/*0:1*/ = reverse ys/*0:01*/+xs/*2:01*/!!ns/*0:1*/ { - rule #0: accum ys [] = reverse ys - rule #1: accum ys (n::int:ns) = accum (xs!n:ys) ns if n>=0&&n<m - rule #2: accum ys (n::int:ns) = accum ys ns - rule #3: accum ys (n:ns) = reverse ys+xs!!(n:ns) - rule #4: accum ys ns = reverse ys+xs!!ns - state 0: #0 #1 #2 #3 #4 +xs/*0:01*/!!ns/*0:1*/ = catmap (\n/*0:*/ -> if n/*0:*/>=0&&n/*0:*/<m/*1:*/ then [xs/*2:01*/!n/*0:*/] else [] { + rule #0: n = if n>=0&&n<m then [xs!n] else [] + state 0: #0 <var> state 1 - state 1: #0 #1 #2 #3 #4 - <var> state 2 - [] state 3 - <app> state 4 - state 2: #4 - state 3: #0 #4 - state 4: #1 #2 #3 #4 - <var> state 5 - <app> state 7 - state 5: #4 - <var> state 6 - state 6: #4 - state 7: #1 #2 #3 #4 - <var> state 8 - : state 11 - state 8: #4 - <var> state 9 - state 9: #4 - <var> state 10 - state 10: #4 - state 11: #1 #2 #3 #4 - <var> state 12 - <var>::int state 14 - state 12: #3 #4 - <var> state 13 - state 13: #3 #4 - state 14: #1 #2 #3 #4 - <var> state 15 - state 15: #1 #2 #3 #4 -} end when m/*0:*/::int = case #xs/*0:01*/ of m/*0:*/::int = m/*0:*/; _/*0:*/ = throw (bad_list_value xs/*1:01*/) { - rule #0: m::int = m - rule #1: _ = throw (bad_list_value xs) - state 0: #0 #1 - <var> state 1 - <var>::int state 2 - state 1: #1 - state 2: #0 #1 -} end { - rule #0: m::int = case #xs of m::int = m; _ = throw (bad_list_value xs) end + state 1: #0 +}) ns/*1:1*/ when m/*0:*/::int = #xs/*0:01*/ { + rule #0: m::int = #xs state 0: #0 <var>::int state 1 state 1: #0 -} end; +} end if listp xs/*0:01*/||tuplep xs/*0:01*/; n1/*0:0101*/,n2/*0:011*/..m/*0:1*/ = while (\i/*0:*/ -> s/*1:*/*i/*0:*/<=s/*1:*/*m/*3:1*/ { rule #0: i = s*i<=s*m state 0: #0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |