Skip to content

Commit afdc3e6

Browse files
committed
tutorial: update all examples
1 parent 567da3d commit afdc3e6

16 files changed

Lines changed: 0 additions & 32 deletions

File tree

tutorial/01-hello/main.kv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# 01-hello: your first kvlang program
22
# Run: kvlang tutorial/01-hello/main.kv
33

4-
"kvlangrun" -> ./term
5-
64
def main() -> () {
75
print("hello kvlang")
86
}

tutorial/02-vars/main.kv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# 02-vars: variables and paths
22
# Run: kvlang tutorial/02-vars/main.kv
33

4-
"kvlangrun" -> ./term
5-
64
def main() -> () {
75
42 -> ./x // write 42 to path ./x
86
print("x =", ./x) // read from path ./x

tutorial/03-arith/main.kv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# 03-arith: arithmetic operations
22
# Run: kvlang tutorial/03-arith/main.kv
33

4-
"kvlangrun" -> ./term
5-
64
def main() -> () {
75
print("add:", 10 + 3) // 13
86
print("sub:", 10 - 3) // 7

tutorial/04-func/main.kv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# 04-func: defining and calling functions
22
# Run: kvlang tutorial/04-func/main.kv
33

4-
"kvlangrun" -> ./term
5-
64
def add(A: int, B: int) -> (C: int) {
75
A + B -> ./C
86
}

tutorial/05-if/main.kv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# 05-if: conditional logic
22
# Run: kvlang tutorial/05-if/main.kv
33

4-
"kvlangrun" -> ./term
5-
64
def abs(x: int) -> (r: int) {
75
if (x < 0) {
86
-x -> ./r

tutorial/06-while/main.kv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# 06-while: while loops, break, and continue
22
# Run: kvlang tutorial/06-while/main.kv
33

4-
"kvlangrun" -> ./term
5-
64
# sum 1 + 2 + ... + n
75
def sum_to(n: int) -> (total: int) {
86
0 -> ./total

tutorial/07-recursion/main.kv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# 07-recursion: recursive functions with TCO
22
# Run: kvlang tutorial/07-recursion/main.kv
33

4-
"kvlangrun" -> ./term
5-
64
def fib(n: int) -> (a: int, b: int) {
75
if (n <= 1) {
86
0 -> ./a

tutorial/08-algo/classify.kv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
# 期望输出:
66
# grade = B
77

8-
"kvlangrun" -> ./term
9-
108
def classify(score:int) -> (grade:string) {
119
if (score >= 90) {
1210
"A" -> ./grade

tutorial/08-algo/collatz.kv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
# 期望输出:
66
# steps = 111
77

8-
"kvlangrun" -> ./term
9-
108
def collatz(n:int) -> (steps:int) {
119
0 -> ./steps
1210
while (n > 1) {

tutorial/08-algo/factorial.kv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
# 期望输出:
66
# fact = 3628800
77

8-
"kvlangrun" -> ./term
9-
108
def factorial(n:int) -> (result:int) {
119
1 -> ./result
1210
1 -> ./i

0 commit comments

Comments
 (0)