More lessons

This commit is contained in:
Bruce Hill 2025-03-24 18:06:22 -04:00
parent 00a0ebec58
commit 6efbc4b120
5 changed files with 83 additions and 24 deletions

View File

@ -13,7 +13,7 @@ enum TestResult(Success(output:Text), Error(err:Text), WrongOutput(actual:Text,
when result is Success(s):
$Colorful"
@(b,u:Program Output:)
$s
@(green:$s)
":print()
is Error(e):
$Colorful"
@ -48,7 +48,9 @@ struct Lesson(file:Path, description:Text, expected_output=none:Text):
LESSONS := [
Lesson((./lessons/lesson-01-hello-world.tm), "Hello World", "Hello world$\n"),
Lesson((./lessons/lesson-02.tm), "Working with Text"),
Lesson((./lessons/lesson-02-tests.tm), "Testing Code"),
Lesson((./lessons/lesson-03-variables.tm), "Variables"),
Lesson((./lessons/lesson-04-functions.tm), "Functions"),
]
func ask_continue():

View File

@ -0,0 +1,26 @@
# Docstring Tests
func main():
# Docstring tests begin with `>>` and can
# be used to check that a value is what you
# expected it to be:
>> 1 + 1
= 2
# If you don't provide an expected value,
# the expression will just be printed out
# and not checked:
>> 2 + 3
# If a docstring test's output is different
# from what was expected, it will print an
# error message and halt the program.
# Edit this test so it passes:
>> 2 + 2
= 9999
# For the rest of this tutorial, you won't
# be editing any of the tests, you'll be
# fixing code so it passes the tests.

View File

@ -1,22 +0,0 @@
func main():
say("
Let's learn about text concatenation!
It uses the `++` operator:
")
greeting := "Hello "
##############################################################
###################### EDIT BELOW HERE #######################
##############################################################
your_text := greeting ++ "space"
##############################################################
################## DO NOT EDIT AFTER HERE ####################
##############################################################
say(your_text)
>> your_text
= "Hello world"

View File

@ -0,0 +1,27 @@
# Variables
func main():
# Variable declarations use `:=` and do not
# require you to specify a type explicitly:
x := 123
# To assign a new value, use `=`
x = 999
# You can also use update assignments like `+=`
x += 1
>> x
= 1000
# Variables are strongly typed, so you can't
# assign different types to the same variable:
x = "hello"
# Declare a variable called `y` and give it the
# value "okay"
>> y
= "okay"

View File

@ -0,0 +1,26 @@
# Functions
func main():
# Functions can be declared in any order.
# The main() function is the first function to run,
# but it can call any other functions defined in
# the same file.
# Here, we're calling a function defined below.
# Fix up the function so it passes thes tests:
>> add(5, 10)
= 15
>> add(2, 4)
= 6
# Functions can also be called with keyword arguments:
>> add(x=4, y=12)
= 16
# Functions are defined using `func` and must specify
# the types of their arguments and return values like this:
func add(x:Int, y:Int -> Int):
# Fix this so it returns a sensible result:
return 0