aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2022-08-14 23:44:45 -0700
committerGravatar Tom Willemse2022-08-14 23:44:45 -0700
commit8450ae6db8d5e7b85295ae15c1032220aae86af1 (patch)
treeb49412c775096c03599443e43d860131282e8aaf
parent69a9a95483ca23ee1a42554a9675a30a9d94cc30 (diff)
downloadcrafting-interpreters-8450ae6db8d5e7b85295ae15c1032220aae86af1.tar.gz
crafting-interpreters-8450ae6db8d5e7b85295ae15c1032220aae86af1.zip
Add a couple of Lox samples
-rw-r--r--src/coffee.lox15
-rw-r--r--src/scone.lox8
2 files changed, 23 insertions, 0 deletions
diff --git a/src/coffee.lox b/src/coffee.lox
new file mode 100644
index 0000000..d83e528
--- /dev/null
+++ b/src/coffee.lox
@@ -0,0 +1,15 @@
+class CoffeeMaker {
+ init(coffee) {
+ this.coffee = coffee;
+ }
+
+ brew() {
+ print "Enjoy your cup of " + this.coffee;
+
+ // No reusing the grounds!
+ this.coffee = nil;
+ }
+}
+
+var maker = CoffeeMaker("coffee and chicory");
+maker.brew();
diff --git a/src/scone.lox b/src/scone.lox
new file mode 100644
index 0000000..1d52c64
--- /dev/null
+++ b/src/scone.lox
@@ -0,0 +1,8 @@
+class Scone {
+ topping(first, second) {
+ print "scone with " + first + " and " + second;
+ }
+}
+
+var scone = Scone();
+scone.topping("berries", "cream");