-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
350 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
|
||
mod D:\code\rs\key-lang\samples\testmod.ks> mym | ||
let s = mym-:MyStruct::new(); | ||
class A { | ||
a b | ||
new():A{ | ||
a:A{b:9} | ||
}, | ||
.f() { | ||
self.a = 99; | ||
:self | ||
} | ||
.g() { | ||
log(self.a) | ||
} | ||
} | ||
|
||
class A = mym-:MyStruct | ||
log(A::new().b) | ||
let a = A::new(); | ||
{ | ||
let f() log("ok") | ||
a.a.b = f | ||
} | ||
a.a.b() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,7 @@ | |
a,>b | ||
>.d(){log("ok");:8} | ||
>new():MyStruct { | ||
a:99 | ||
b:22 | ||
b:MyStruct {b:20} | ||
} | ||
} | ||
let s = MyStruct::new() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# self | ||
|
||
self是一个关键词,在方法外代表顶级作用域的一个变量,不会被let self覆盖;在方法内代表方法操作的目标。 | ||
|
||
你也可以使用bind方法使一个函数的self目标改变,但由于bind行为本身会传参引起复制,使用bind(变量名)时并不会引起变量本身改变。 | ||
|
||
在方法内外都可使用self = xx语法。但在方法内使用时有可能会直接导致原变量类型改变,所以请不要把self当普通变量使用,减少预料之外的事情发生。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.