aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/tools/tutorial.nom63
1 files changed, 30 insertions, 33 deletions
diff --git a/lib/tools/tutorial.nom b/lib/tools/tutorial.nom
index 8c104c5..e8295c2 100644
--- a/lib/tools/tutorial.nom
+++ b/lib/tools/tutorial.nom
@@ -13,8 +13,11 @@ use "shell"
)}
")
-[<your code here>, ???] all compile to:
- at (this tree) fail "Incomplete code: This needs to be filled in."
+[<your code here>, ???] all compile to
+ \(
+ at ("Text" tree with "\((this tree).source)") fail
+ \("Incomplete code: This needs to be filled in.")
+ ) as lua
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -37,7 +40,7 @@ $lessons = [
# Figure out what value $my_var should have:
$my_var = 100
$my_var = ($my_var + $x + $(my favorite number))
- assume $my_var == (???)
+ assume (???) == $my_var
lesson "Actions":
# Fix this action so the tests pass, then save and quit.
@@ -96,12 +99,9 @@ $lessons = [
$total = 0
for $i in 1 to 3:
$total = ($total + $i)
- assume $total == (???)
+ assume (???) == $total
lesson "Variable Scopes":
- # A nomsu variable that has not yet been assigned to is (nil)
- assume $never_assigned == (nil)
-
# Nomsu's variables are local by default, and actions have their own scopes:
$x = 1
$y = 2
@@ -110,17 +110,17 @@ $lessons = [
(do something) means:
# The variable $y is never set in this action, so it has the same value
it has outside this action.
- assume $y == (???)
+ assume (???) == $y
# $x is set inside this action, and actions have their own scopes.
$x = $y
# What number should $x be here?
- assume $x == (???)
+ assume (???) == $x
# After running the action, what value should $x have?
do something
- assume $x == (???)
+ assume (???) == $x
lesson "More Variable Scopes":
# Loops and conditionals do *not* have their own scopes:
@@ -130,13 +130,13 @@ $lessons = [
$z = 2
# After assigning in a conditional, what should $z be?
- assume $z == (???)
+ assume (???) == $z
for $ in 1 to 1:
# Set $z inside a loop:
$z = 3
# After assigning in a loop, what should $z be?
- assume $z == (???)
+ assume (???) == $z
lesson "Externals":
# The 'external' block lets you modify variables outside an action:
@@ -146,7 +146,7 @@ $lessons = [
do something
# After running the action that sets $x in an 'external' block, what should $x be?
- assume $x == (???)
+ assume (???) == $x
lesson "Locals":
# The 'with' block lets you create a local scope for the variables you list:
@@ -157,8 +157,8 @@ $lessons = [
$z = 2
# After setting $y and $z in the 'with [$y]' block, what should $y and $z be?
- assume $y == (???)
- assume $z == (???)
+ assume (???) == $y
+ assume (???) == $z
lesson "Failure and Recovery":
$what_happened = "nothing"
@@ -172,7 +172,7 @@ $lessons = [
$what_happened = "success"
# What do you think happened?
- assume $what_happened == (???)
+ assume (???) == $what_happened
# Note: a 'try' block will silence failures, so this has no effect:
try: fail
@@ -181,10 +181,10 @@ $lessons = [
# Nomsu uses the "." operator to access things inside an object:
$dictionary = {.dog = "A lovable doofus", .cat = "An internet superstar"}
assume $dictionary.dog == "A lovable doofus"
- assume $dictionary.cat == (???)
+ assume (???) == $dictionary.cat
# If you try to access a key that's not in an object, the result is (nil):
- assume $dictionary.mimsy == (???)
+ assume (???) == $dictionary.mimsy
# $dictionary.dog is just a shorthand for $dictionary."dog".
You may need to use the longer form for strings with spaces:
@@ -195,22 +195,22 @@ $lessons = [
$dictionary.5 = "The number five"
$dictionary.five = 5
$dictionary.myself = $dictionary
- assume $dictionary.myself == (???)
+ assume (???) == $dictionary.myself
# Lists are similar, but use square brackets ([])
and can only have numbers as keys, starting at 1:
$list = ["first", "second", 999]
assume $list.1 == "first"
- assume $list.2 == (???)
- assume $list.3 == (???)
+ assume (???) == $list.2
+ assume (???) == $list.3
# Hint: 4 should be a missing key
- assume $list.4 == (???)
- assume $list.foobar == (???)
+ assume (???) == $list.4
+ assume (???) == $list.foobar
# The "#" action gets the number of items inside something:
- assume (#$list) == (???)
- assume (#{.x = 10, .y = 20}) == (???)
+ assume (???) == (#$list)
+ assume (???) == (#{.x = 10, .y = 20})
lesson "Methods":
# The "," is used for method calls, which means calling an action
@@ -225,10 +225,10 @@ $lessons = [
# Text also has some methods like:
$name = "Harry Tuttle"
assume ($name, character 7) == "T"
- assume ($name, with "Tuttle" -> "Buttle") == (???)
+ assume (???) == ($name, with "Tuttle" -> "Buttle")
# Methods can be chained too:
- assume ($name, with "Tuttle" -> "Buttle", character 7) == (???)
+ assume (???) == ($name, with "Tuttle" -> "Buttle", character 7)
lesson "Object Oriented Programming":
# Object Oriented Programming deals with things that have
@@ -364,12 +364,8 @@ command line program with $args:
"y" "Y" "yes" "":
$f = (read file $filename)
- $cursor_positions = []
- $cursor_positions, add ($f, position of "<your code here>" 1 (yes))
- $cursor_positions, add ($f, position of "???" 1 (yes))
- unless ($cursor_positions is empty):
- $pos = (min of $cursor_positions)
- [$line, $col] = [($f, line number at $pos), ($f, line position at $pos)]
+ [$line, $col] = ($failures.1.failure, match ":(%d+),(%d+)")
+ if ($line and $col):
when:
($EDITOR, matches "vim$"):
sh> "\$EDITOR \$filename '+call cursor(\$line,\$col)'"
@@ -393,6 +389,7 @@ command line program with $args:
try:
run $file
..if it fails with $msg:
+ $failures.1.failure = $msg
say (bold (red "\n There's a bit more to fix:"))
$msg = ($msg, with "\n *stack traceback:.*" -> "")
say ($msg, indented)