shithub: limbobyexample

Download patch

ref: 7635c9c15d25fce6b392f9899a68a36cdd7c06c4
parent: 412fcca30891a7ef374ef751cab950ef44df0d8a
author: henesy <henesy.dev@gmail.com>
date: Thu Feb 28 07:48:48 EST 2019

add note about pete vnc ;; source, but no explanation for switch

--- a/README.md
+++ b/README.md
@@ -8,6 +8,8 @@
 
 Examples are composed in acme(1) which allows you to right click these strings to jump to the relevant source lines. 
 
+If you'd like to try Inferno without installing, I recommend trying Pete's on-demand VNC: http://tryinferno.reverso.be/
+
 The `;` rune indicates a command to be run from the Inferno sh(1) shell. 
 
 ## Building
--- /dev/null
+++ b/Switch/README.md
@@ -1,0 +1,46 @@
+# Switch
+
+Limbo does not have a verbatim `switch` statement. Rather, it has a statement named `case` which is analogous, but not identical to C's switch-case construct. 
+
+Limbo case statements break by default and accept range matching operations involving the `or` and `to` keywords.
+
+Note: A break or continue followed by a label causes a break out of, or the next iteration of, the enclosing construct that is labeled with the same label. 
+
+## Source
+
+### switch.b:16,31
+
+
+
+### switch.b:33,42
+
+
+
+### switch.b:44,51
+
+
+
+### switch.b:53,60
+
+
+
+### switch.b:62,69
+
+
+
+## Demo
+
+	; limbo switch.b
+	; switch
+	Even
+	Odd
+	i's value: 9
+	Valid hex
+	Quack!
+	This is binary
+	Neither 4 nor 7
+	; 
+
+## Exercises
+
+- Try commenting out the `break` and/or `continue` keywords in the first switch, how does the behavior change?
--- /dev/null
+++ b/Switch/switch.b
@@ -1,0 +1,72 @@
+implement Switch;
+
+include "sys.m";
+include "draw.m";
+
+sys: Sys;
+print, FD: import sys;
+
+Switch: module {
+	init: fn(nil: ref Draw->Context, nil: list of string);
+};
+
+init(nil: ref Draw->Context, nil: list of string) {
+	sys = load Sys Sys->PATH;
+
+	i := 10;
+
+	# The label labelling the enclosing construct
+	loop:
+
+	for(; i >= 0; i--)
+		case i {
+		0 or 2 or 4 or 6 or 8 or 10 =>
+			print("Even\n");
+			continue loop;
+		* =>
+			print("Odd\n");
+			break loop;
+		}
+
+	print("i's value: %d\n", i);
+
+	c := 'c';
+
+	case c {
+	'a' to 'f' =>
+		print("Valid hex\n");
+	'C' =>
+		print("The letter 'C'\n");
+	* =>
+		print("The default\n");
+	}
+
+	str := "ducks";
+
+	case str {
+	"ducks" =>
+		print("Quack!\n");
+	"" =>
+		print("Nil string\n");
+	}
+
+	n := 1;
+
+	case n {
+	0 or 1 =>
+		print("This is binary\n");
+	* =>
+		print("This is non-binary\n");
+	}
+
+	f := big 6;
+
+	case f {
+	big 4 => print("The number 4\n");
+	big 5 => print("The number 7\n");
+	* =>
+		print("Neither 4 nor 7\n");
+	}
+
+	exit;
+}