changeset 20:5a36fda13a47

Added fold:with function
author Michael Pavone <pavone@retrodev.com>
date Fri, 25 Jul 2014 22:13:17 -0700
parents 84f595cff062
children 5a27dd6f03cd
files code/mike00.lm
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/code/mike00.lm	Fri Jul 25 22:09:54 2014 -0700
+++ b/code/mike00.lm	Fri Jul 25 22:13:17 2014 -0700
@@ -37,6 +37,14 @@
 		reverse: new
 	}
 	
+	fold:with <- :lst acc :fun {
+		while: { not: (lst isInteger?) } do: {
+			acc <- fun: acc (lst value)
+			lst <- lst tail
+		}
+		acc
+	}
+	
 	makeTree:size <- :lst :size {
 		ret <- 0
 		sub <- 0
@@ -165,6 +173,7 @@
 		print: (tree: tree set: 0 to: 42)
 		print: (tree: tree set: 6 to: 42)
 		print: (tree: tree set: 8 to: 42)
+		print: (fold: lst 0 with: :acc el { acc + el })
 	}
 	
 }
\ No newline at end of file