More lessons
This commit is contained in:
parent
00a0ebec58
commit
6efbc4b120
6
koans.tm
6
koans.tm
@ -13,7 +13,7 @@ enum TestResult(Success(output:Text), Error(err:Text), WrongOutput(actual:Text,
|
|||||||
when result is Success(s):
|
when result is Success(s):
|
||||||
$Colorful"
|
$Colorful"
|
||||||
@(b,u:Program Output:)
|
@(b,u:Program Output:)
|
||||||
$s
|
@(green:$s)
|
||||||
":print()
|
":print()
|
||||||
is Error(e):
|
is Error(e):
|
||||||
$Colorful"
|
$Colorful"
|
||||||
@ -48,7 +48,9 @@ struct Lesson(file:Path, description:Text, expected_output=none:Text):
|
|||||||
|
|
||||||
LESSONS := [
|
LESSONS := [
|
||||||
Lesson((./lessons/lesson-01-hello-world.tm), "Hello World", "Hello world$\n"),
|
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():
|
func ask_continue():
|
||||||
|
26
lesson-templates/lesson-02-tests.tm
Normal file
26
lesson-templates/lesson-02-tests.tm
Normal 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.
|
@ -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"
|
|
27
lesson-templates/lesson-03-variables.tm
Normal file
27
lesson-templates/lesson-03-variables.tm
Normal 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"
|
26
lesson-templates/lesson-04-functions.tm
Normal file
26
lesson-templates/lesson-04-functions.tm
Normal 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
|
Loading…
Reference in New Issue
Block a user