changeset 173:158444b77c09

Added foreach, string and print to list objects
author Mike Pavone <pavone@retrodev.com>
date Wed, 21 Aug 2013 08:00:09 -0700
parents 8d466c5a7dff
children 8b5829372ad1
files modules/list.tp
diffstat 1 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/modules/list.tp	Wed Aug 21 07:59:34 2013 -0700
+++ b/modules/list.tp	Wed Aug 21 08:00:09 2013 -0700
@@ -9,6 +9,8 @@
 			list node: val withTail: self
 		}
 		. <- :right { right }
+		string <- { "[]" }
+		print <- { print: string }
 	}
 	#{
 		empty <- { _empty }
@@ -34,6 +36,13 @@
 				map <- :fun {
 					node: (fun: _val) withTail: (_tail map: fun)
 				}
+				foreach <- :self fun {
+					fold: 0 with: :idx el{
+						fun: idx el
+						idx + 1
+					}
+					self
+				}
 				| <- :val {
 					node: val withTail: self
 				}
@@ -42,6 +51,18 @@
 						node: val withTail: tail
 					}
 				}
+				string <- {
+					(fold: "[\n" with: :acc el {
+						acc . "	" . (string: el) . "\n"
+					}) . "]"
+				}
+				print <- {
+					print: "[\n"
+					foreach: :_ el {
+						print: "	" . (string: el) . "\n"
+					}
+					print: "]"
+				}
 			}
 		}
 	}