shithub: limbobyexample

Download patch

ref: 88326ef46d597b689b83ec8a44bde60ee8622537
parent: 78873542e74f63d289a1a44ead0dd143a9b11fcf
author: seh <henesy.dev@gmail.com>
date: Sun Mar 3 20:44:03 EST 2019

add arrays example

--- a/Arrays/README.md
+++ b/Arrays/README.md
@@ -8,32 +8,42 @@
 
 ### arrays.b:20,30
 
+This shows the initialization of an array of integers using a variable, `width`, as the count of elements for the array. 
 
+Note that on `arrays.b:13,15` the array of integers, `nums`, and the integer, `width`, are declared. 
 
 ### arrays.b:32,44
 
+Limbo supports indexing strings. The length, as per `len`, of a string is equivalent to the number of utf-8 runes within a given string. All strings in Limbo are utf-8 strings. 
 
+This section demonstrates the copying of a string into an array of bytes. 
 
 ### arrays.b:46,57
 
+Since the size of arrays is dynamic, one can declare an array to the size of a dynamic value. The array of bytes, `dbl`, is initialized to double the size of the array `arr`. 
 
+Each index of `arr` is copied to two neighboring indices in `dbl`. 
 
 ### arrays.b:59,67
 
+Arrays can be initialized to a given set of values as well. In this case, the characters `[a-f]` are used as values to populate the array of strings, `chars`. The size of the array will be equal to the number of elements provided in the aforementioned set. 
 
-
 ### arrays.b:69,84
 
+Arrays can be declared to be arrays of other arrays. In this case, the array `nest` is an array of four arrays of strings of size `2 << i`. 
 
+### arrays.b:86,97
 
-### arrays.b:86,94
+Arrays can be conditionally initialized to values. The syntax is similar to the `case` statement syntax. In this case, the first three indices are initialized to the byte value of 4. Indices three and greater are initialized to the byte value of 0.
 
+Note: Multiple conditional sections are not necessary to initialize to a given value. 
 
+### arrays.b:99,123
 
-### arrays.b:96,122
+This shows the declaration of an array of size 4 containing lists of string pairs. The lists begin as empty lists, comparable to nil. 
 
+The lists at indices 0 and 2 are prepended with pairs of strings. The head of the respective lists are then printed by extracting the pairs of strings prepended previously. 
 
-
 ## Demo
 
 	; limbo arrays.b
@@ -56,7 +66,7 @@
 	Lens: [ 2 4 8 16]
 	
 	Len buf: 10
-	[ 3 3 3 3 3 3 3 3 3 3]
+	[ 4 4 4 3 3 3 3 3 3 3]
 	
 	Len two: 4
 	Lens: [ 1 0 1 0]
@@ -66,4 +76,5 @@
 ## Exercises
 
 - Play with the widths of different arrays, what happens?
-- What can you initialize with the `* =>` operator, what can't you?
+- What can you initialize to with the `* =>` operator, what can't you?
+- Remove a case section from the `* =>` operator section, are all indices set to that value?
--- a/Arrays/arrays.b
+++ b/Arrays/arrays.b
@@ -84,7 +84,10 @@
 	print("]\n\n");
 
 	# Buf
-	buf := array[10] of {* => byte 3};
+	buf := array[10] of {
+		0 to 2 => byte 4,
+		* => byte 3
+	};
 
 	print("Len buf: %d\n", len buf);
 
@@ -95,8 +98,6 @@
 
 	# Two
 	two := array[4] of list of (string, string);
-
-	#two = array[4] of list of (string, string);
 
 	two[0] = ("ducks", "quack") :: two[0];
 
--- a/README.md
+++ b/README.md
@@ -34,6 +34,7 @@
 - [Loops](./Loops)
 - [If Else](./If-Else)
 - [Switch Case](./Switch)
+- [Arrays](./Arrays)
 
 ## References