@ -> ^, functional example
This commit is contained in:
@@ -4,7 +4,7 @@ func main[] : i64
|
||||
io.println("FizzBuzz")
|
||||
else if i % 5 == 0
|
||||
io.println("Buzz")
|
||||
else if i %3 == 0
|
||||
else if i % 3 == 0
|
||||
io.println("Fizz")
|
||||
else
|
||||
io.println_i64(i)
|
||||
11
examples/functional.zr
Normal file
11
examples/functional.zr
Normal file
@@ -0,0 +1,11 @@
|
||||
func square[x: i64] : i64
|
||||
return x * x
|
||||
|
||||
func sum[a: i64, b: i64] : i64
|
||||
return a + b
|
||||
|
||||
func main[] : i64
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
|
||||
|> alg.map(^square)
|
||||
|> alg.reduce(^sum, 0)
|
||||
|> io.println_i64()
|
||||
@@ -15,7 +15,7 @@ func main[] : i64
|
||||
let db = 0
|
||||
let stmt = 0
|
||||
|
||||
rc = sqlite3_open("todo.db", @db)
|
||||
rc = sqlite3_open("todo.db", ^db)
|
||||
if rc
|
||||
dbg.panic("failed to open db")
|
||||
|
||||
@@ -36,7 +36,7 @@ func main[] : i64
|
||||
break
|
||||
else if choice == 1
|
||||
io.println("============")
|
||||
sqlite3_prepare_v2(db, "SELECT * FROM todo", -1, @stmt, 0)
|
||||
sqlite3_prepare_v2(db, "SELECT * FROM todo", -1, ^stmt, 0)
|
||||
|
||||
while sqlite3_step(stmt) == 100
|
||||
let id: i64 = sqlite3_column_int(stmt, 0)
|
||||
@@ -51,7 +51,7 @@ func main[] : i64
|
||||
io.print("\nEnter new task: ")
|
||||
let task: str = io.read_line() |> str.trim()
|
||||
|
||||
sqlite3_prepare_v2(db, "INSERT INTO todo(task) VALUES (?);", -1, @stmt, 0)
|
||||
sqlite3_prepare_v2(db, "INSERT INTO todo(task) VALUES (?);", -1, ^stmt, 0)
|
||||
sqlite3_bind_text(stmt, 1, task, -1, 0)
|
||||
if sqlite3_step(stmt) != 101
|
||||
dbg.panic(sqlite3_errmsg(db))
|
||||
@@ -61,7 +61,7 @@ func main[] : i64
|
||||
io.print("\nEnter task id: ")
|
||||
let id: i64 = io.read_line() |> str.parse_i64()
|
||||
|
||||
sqlite3_prepare_v2(db, "DELETE FROM todo WHERE id = ?;", -1, @stmt, 0)
|
||||
sqlite3_prepare_v2(db, "DELETE FROM todo WHERE id = ?;", -1, ^stmt, 0)
|
||||
sqlite3_bind_int(stmt, 1, id, -1, 0)
|
||||
if sqlite3_step(stmt) != 101
|
||||
dbg.panic(sqlite3_errmsg(db))
|
||||
|
||||
@@ -151,8 +151,6 @@ func scan_token[tokens: array, current: ptr, line: ptr, column: ptr, source: str
|
||||
add_token("Xor", tokens, source, start, mem.read64(current), mem.read64(line), mem.read64(column))
|
||||
else if c == ':'
|
||||
add_token("Colon", tokens, source, start, mem.read64(current), mem.read64(line), mem.read64(column))
|
||||
else if c == '@'
|
||||
add_token("At", tokens, source, start, mem.read64(current), mem.read64(line), mem.read64(column))
|
||||
else if c == '.'
|
||||
if match_char('.', current, column, source, source_len)
|
||||
add_token("DoubleDot", tokens, source, start, mem.read64(current), mem.read64(line), mem.read64(column))
|
||||
@@ -241,7 +239,7 @@ func tokenize[source: str, filename: str] : array
|
||||
let tokens: array = []
|
||||
|
||||
while !eof(current, source_len)
|
||||
scan_token(tokens, @current, @line, @column, source, source_len, filename, indent_stack, @current_indent)
|
||||
scan_token(tokens, ^current, ^line, ^column, source, source_len, filename, indent_stack, ^current_indent)
|
||||
|
||||
add_token_with_lexeme("Eof", tokens, "", line, column)
|
||||
return tokens
|
||||
|
||||
Reference in New Issue
Block a user