changeset 150:50c97b448f44

Add Previous method to List
author Mike Pavone <pavone@retrodev.com>
date Wed, 24 Nov 2010 02:28:01 +0000
parents 804e48af1027
children b75ec364cecc
files list.rhope
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/list.rhope	Mon Nov 22 20:38:03 2010 +0000
+++ b/list.rhope	Wed Nov 24 02:28:01 2010 +0000
@@ -100,6 +100,12 @@
 	}
 }
 
+Previous@List Leaf[list,index:prev,none]
+{
+	,none <- If[[index]>[0]]
+	{ prev <- [index]-[1] }
+}
+
 Blueprint List
 {
 	Buffer
@@ -278,6 +284,26 @@
 	}
 }
 
+Previous@List[list,index:prev,none]
+{
+	If[[index] <= [[list]Offset >>]]
+	{
+		prev,none <- [[list]Left >>]Previous[index]
+	}{
+		If[[index] <= [[list]Right Offset >>]]
+		{
+			pos prev <- [index]-[1]
+			If[[pos prev] < [[[[list]Buffer >>]Length]+[[list]Offset >>]]]
+			{ prev <- Val[pos prev] }
+			{ prev <- [[[[list]Buffer >>]Length]+[[list]Offset >>]]-[1] }
+		}{
+			[[list]Right >>]Previous[[index]-[[list]Right Offset >>]]
+			{ prev <- [~]+[[list]Right Offset >>] }
+			{ prev <- [[[[list]Buffer >>]Length]+[[list]Offset >>]]-[1] }
+		}
+	}
+}
+
 New Like@List[in:out]
 {
 	out <- List[]