changeset 366:810b6115c1d4

Add a pop method to array
author Michael Pavone <pavone@retrodev.com>
date Sat, 08 Aug 2015 21:13:26 -0700
parents 3d36d69aab7f
children e2c1309ab750
files modules/array.tp samples/testarray.tp
diffstat 2 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/modules/array.tp	Fri Aug 07 21:40:08 2015 -0700
+++ b/modules/array.tp	Sat Aug 08 21:13:26 2015 -0700
@@ -54,6 +54,16 @@
 		size <- size + 1
 		self
 	}
+	
+	llMessage: pop withVars: {
+	} andCode: {
+		if: size > 0 {
+			size <- size - 1
+			data get: size
+		} else: {
+			false
+		}
+	}
 
 	llMessage: resize withVars: {
 		newsize <- obj_uint32 ptr
--- a/samples/testarray.tp	Fri Aug 07 21:40:08 2015 -0700
+++ b/samples/testarray.tp	Sat Aug 08 21:13:26 2015 -0700
@@ -13,6 +13,8 @@
 		bar append: 28
 		bar append: 42
 		print: "" . ((sum: foo) + (sum: bar)) . "\n"
+		val <- bar pop
+		print: "popped off: " . val . ", new length: " . (bar length) . "\n"
 	}
 }