-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeOG.klar
More file actions
66 lines (56 loc) · 1.65 KB
/
Copy paththeOG.klar
File metadata and controls
66 lines (56 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
The original Klar example, but reflecting modern changes
to the design of the language.
The changes are:
1. The language is called Klar instead of Pura. Standard library imports
are in lowercase. The import has been updated to `klar.cli` from `Pura.CLI`.
The reference to `CLI.args` has been updated to `cli.args`.
2. `while i, arg : args` has been changed to `for i, arg in args`.
3. The map syntax where `data` is being assigned has been changed to add `#`
before the curly braces.
4. In the `User.logIn` method, the return type has been updated to use `Nothing`
instead of `Void`.
5. Inheritance for the `Player` struct uses `: User` rather than `(User)`.
6. Interface `type Reader = {...}` has been changed to `type #Reader {...}`.
7. `_ :=` was added before the pipe expression at the bottom, all surrounded
by a function call.
8. `args: Any` was renamed to `args2: Any?`.
9. Type `Data` was defined.
10. Function `main` was called.
Everything else was unchanged! The original was written around April/May
(most likely May) 2025.
**/
import klar.cli
main()
func main() {
args := cli.args
for i, arg in args {
print("Argument {i + 1}: {arg}")
}
args2: Any? := nil
isEnabled: Bool := true
data: Data? := #{
value: "John"
}
type Data = #{String: String}
}
type User {
name: String
age: Int
password: String
}
func User.logIn(pwd: String) -> Result<Nothing> {
when pwd {
self.password -> return
_ -> return Error("Incorrect")
}
}
// Inheritance
type Player: User {
game: String
}
// Interface
type #Reader {
Read() -> String
}
func _() { _ := fn1(p) |> doThis |> .name } // Pipe