Skip to content

Commit 6484796

Browse files
committed
老文章的fn改成func
1 parent 139bf26 commit 6484796

File tree

10 files changed

+50
-50
lines changed

10 files changed

+50
-50
lines changed

docs/guide/design-wz.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ func Point.Length() => int {
545545
return math.sqrt(this.x*this.x + this.y*this.y)
546546
}
547547
548-
fn main {
548+
func main {
549549
p := Point{x:1, y:2}
550550
println(p.Length())
551551
}

docs/reference/design-wz.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ func Point.Length() => int {
545545
return math.sqrt(this.x*this.x + this.y*this.y)
546546
}
547547
548-
fn main {
548+
func main {
549549
p := Point{x:1, y:2}
550550
println(p.Length())
551551
}

docs/smalltalk/en/st0013.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ Where mem represents the virtual machine's 30,000 bytes of memory, then code rep
5858
Then wrap the corresponding constructor and Run method:
5959

6060
```wa
61-
fn NewBrainFuck(code: string) => *BrainFuck {
61+
func NewBrainFuck(code: string) => *BrainFuck {
6262
return &BrainFuck{code: code}
6363
}
6464
65-
fn BrainFuck.Run() {
65+
func BrainFuck.Run() {
6666
# ...
6767
}
6868
```
6969

7070
Here's how the main function constructs the BrainFuck VM and executes it:
7171

7272
```wa
73-
fn main {
73+
func main {
7474
# print hi
7575
const code = "++++++++++[>++++++++++<-]>++++.+."
7676
vm := NewBrainFuck(code)
@@ -81,7 +81,7 @@ fn main {
8181
Let's look at the implementation of the `BrainFuck.Run` function:
8282

8383
```wa
84-
fn BrainFuck.Run() {
84+
func BrainFuck.Run() {
8585
for ; this.pc != len(this.code); this.pc++ {
8686
switch x := this.code[this.pc]; x {
8787
case '>':
@@ -115,7 +115,7 @@ Basically, the instructions in BF language are interpreted one by one. Where the
115115
In addition, the `BrainFuck.loop` private method is used to handle nested instructions:
116116

117117
```wa
118-
fn BrainFuck.loop(inc: int) {
118+
func BrainFuck.loop(inc: int) {
119119
for i := inc; i != 0; this.pc += inc {
120120
switch this.code[this.pc+inc] {
121121
case '[':

docs/smalltalk/st0003.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ $ cat <<EOF >hello.wa
5151
> #!/Users/wa-user/go/bin/wa
5252
> # 版权 @2019 凹语言 作者。保留所有权利。
5353
>
54-
> fn main() {
54+
> func main() {
5555
> println("老凹,吃了吗")
5656
> }
5757
> EOF

docs/smalltalk/st0004.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@
6969
| 切换语句 switch-case | `swc` \| `找辙有辙` \| `zhaozheyouzhe`\| `zzyz` | switch expr { case cond: }<br />找辙 expr { 有辙 cond: } |
7070
| 切换语句 switch-default | `swd` \| `找辙没辙` \| `zhaozhemeizhe`\|`zzmz` | switch expr { default: }<br />找辙 expr { 没辙: } |
7171
| 切换语句 switch-case-default | `swcd` \| `找辙没辙` \| `zhaozheyouzhemeizhe`\|`zzyzmz` | switch expr { case cond1: default cond2:}<br />找辙 expr { 有辙 cond1: 没辙 cond2:} |
72-
| defer 语句 | `df` \| `善后` \|`shanhou`\| `sh` | defer fn()<br />善后 fn() |
72+
| defer 语句 | `df` \| `善后` \|`shanhou`\| `sh` | defer func()<br />善后 func() |
7373
| return 语句 | `rt` \| `返回` \|`fanhui`\| `fh` | return value<br />返回 value |
7474
| break 语句 | `br` \| `跳出` \|`tiaochu`\| `tc` | break<br />跳出 |
7575
| continue 语句 | `cn` \| `继续` \|`jixu`\| `jx` | continue<br />继续 |
76-
| 函数 | `f` \| `函数` \| `hanshu`\| `hs` | fn name() {}<br />函数 name() {} |
76+
| 函数 | `f` \| `函数` \| `hanshu`\| `hs` | func name() {}<br />函数 name() {} |
7777
| ... | ... | ... |
7878
:::
7979

docs/smalltalk/st0006.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import (
5252
)
5353

5454
func main() {
55-
output, err := api.RunCode("hello.wa", "fn main() { println(40+2) }")
55+
output, err := api.RunCode("hello.wa", "func main() { println(40+2) }")
5656
fmt.Print(string(output), err)
5757
}
5858
```
@@ -63,11 +63,11 @@ func main() {
6363
$ cat hello.wa
6464
# 版权 @2019 凹语言 作者。保留所有权利。
6565
66-
fn main() {
66+
func main() {
6767
println( add(40 , 2) )
6868
}
6969
70-
fn add(a:i32,b:i32)=> i32 {
70+
func add(a:i32,b:i32)=> i32 {
7171
return a+b
7272
}
7373
```
@@ -78,11 +78,11 @@ return a+b
7878
$ cat hello.wa
7979
# 版权 @2019 凹语言 作者。保留所有权利。
8080
81-
fn main() {
81+
func main() {
8282
println(add(40, 2))
8383
}
8484
85-
fn add(a: i32, b: i32) => i32 {
85+
func add(a: i32, b: i32) => i32 {
8686
return a + b
8787
}
8888
```

docs/smalltalk/st0011.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ WASM 后端原型如期发布,已支持数值/字符串基本类型、结构
9292
或者创建以 `hello.wa` 文件,包含下代码
9393

9494
```wa
95-
fn main {
95+
func main {
9696
println("你好,凹语言!")
9797
println(add(40, 2))
9898
}
9999
100-
fn add(a: i32, b: i32) => i32 {
100+
func add(a: i32, b: i32) => i32 {
101101
return a+b
102102
}
103103
```
@@ -125,7 +125,7 @@ import (
125125
)
126126

127127
func main() {
128-
output, err := api.RunCode("hello.wa", "fn main() { println(40+2) }")
128+
output, err := api.RunCode("hello.wa", "func main() { println(40+2) }")
129129
fmt.Print(string(output), err)
130130
}
131131
```

docs/smalltalk/st0013.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ type BrainFuck struct {
6161
然后封装对应的构造函数和 Run 方法:
6262

6363
```wa
64-
fn NewBrainFuck(code: string) => *BrainFuck {
64+
func NewBrainFuck(code: string) => *BrainFuck {
6565
return &BrainFuck{code: code}
6666
}
6767
68-
fn BrainFuck.Run() {
68+
func BrainFuck.Run() {
6969
# ...
7070
}
7171
```
7272

7373
下面是 main 函数构造 BF 虚拟机并执行的方式:
7474

7575
```wa
76-
fn main {
76+
func main {
7777
# print hi
7878
const code = "++++++++++[>++++++++++<-]>++++.+."
7979
vm := NewBrainFuck(code)
@@ -84,7 +84,7 @@ fn main {
8484
下面让我们来看看 `BrainFuck.Run` 函数的实现:
8585

8686
```wa
87-
fn BrainFuck.Run() {
87+
func BrainFuck.Run() {
8888
for ; this.pc != len(this.code); this.pc++ {
8989
switch x := this.code[this.pc]; x {
9090
case '>':
@@ -118,7 +118,7 @@ fn BrainFuck.Run() {
118118
另外 `BrainFuck.loop` 私有方法则用于处理嵌套指令:
119119

120120
```wa
121-
fn BrainFuck.loop(inc: int) {
121+
func BrainFuck.loop(inc: int) {
122122
for i := inc; i != 0; this.pc += inc {
123123
switch this.code[this.pc+inc] {
124124
case '[':

docs/smalltalk/st0015.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ import "syscall/arduino"
4141
4242
var LED = arduino.GetPinLED()
4343
44-
fn init() {
44+
func init() {
4545
arduino.PinMode(LED, 1)
4646
arduino.Print("凹语言(Wa)/Arduino is running ...\n")
4747
}
4848
49-
fn main() {
49+
func main() {
5050
for {
5151
arduino.DigitalWrite(LED, arduino.HIGH)
5252
arduino.Delay(100)
@@ -75,28 +75,28 @@ var (
7575
)
7676
7777
#wa:import arduino millis
78-
fn Millis() => i32
78+
func Millis() => i32
7979
8080
#wa:import arduino delay
81-
fn Delay(ms: i32)
81+
func Delay(ms: i32)
8282
8383
#wa:import arduino pinMode
84-
fn PinMode(pin, mode: i32)
84+
func PinMode(pin, mode: i32)
8585
8686
#wa:import arduino digitalWrite
87-
fn DigitalWrite(pin, value: i32)
87+
func DigitalWrite(pin, value: i32)
8888
8989
#wa:import arduino getPinLED
90-
fn GetPinLED() => i32
90+
func GetPinLED() => i32
9191
9292
#wa:import arduino print
93-
fn PrintRawString(ptr: i32, len: i32)
93+
func PrintRawString(ptr: i32, len: i32)
9494
95-
fn Print(s: string) {
95+
func Print(s: string) {
9696
print(s)
9797
}
9898
99-
fn Println(s: string) {
99+
func Println(s: string) {
100100
println(s)
101101
}
102102
```

docs/smalltalk/st0018.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ type Canvas struct {
4040
`NewCanvas`函数用于创建并初始化一个`Canvas`对象:
4141
```wa
4242
#wa:import wa_js_env newCanvas
43-
fn newCanvas_JS(w, h: u32) => u32
43+
func newCanvas_JS(w, h: u32) => u32
4444
4545
#创建一个宽度为w像素、高度为h像素的画布对象
46-
fn NewCanvas(w, h: u32) => *Canvas {
46+
func NewCanvas(w, h: u32) => *Canvas {
4747
var canvas Canvas
4848
canvas.device_id = newCanvas_JS(w, h)
4949
canvas.width = w
@@ -61,22 +61,22 @@ fn NewCanvas(w, h: u32) => *Canvas {
6161

6262
```wa
6363
#获取画布对象坐标为(x, y)处的像素颜色值
64-
fn Canvas.GetPixel(x, y: u32) => u32 {
64+
func Canvas.GetPixel(x, y: u32) => u32 {
6565
return this.frame_buf[y * this.width + x]
6666
}
6767
6868
#设置画布对象坐标(x, y)处的颜色值为color
69-
fn Canvas.SetPixel(x, y, color: u32) {
69+
func Canvas.SetPixel(x, y, color: u32) {
7070
this.frame_buf[y * this.width + x] = color
7171
}
7272
```
7373

7474
当整个帧缓存填充完毕后,通过`Canvas.Flush`方法将帧缓存数据更新至页面中的画布对象;与创建画布DOM对象类似,该操作也需要通过JS环境导入的函数完成:
7575
```wa
7676
#wa:import wa_js_env updateCanvas
77-
fn updateCanvas_JS(id: u32, buf: *u32)
77+
func updateCanvas_JS(id: u32, buf: *u32)
7878
79-
fn Canvas.Flush() {
79+
func Canvas.Flush() {
8080
updateCanvas_JS(this.device_id, &this.frame_buf[0])
8181
}
8282
```
@@ -85,8 +85,8 @@ fn Canvas.Flush() {
8585

8686
```wa
8787
#画布事件回调函数原型
88-
type OnTouch fn (x, y: u32)
89-
type OnKey fn(key: u32)
88+
type OnTouch func (x, y: u32)
89+
type OnKey func(key: u32)
9090
9191
#画布事件
9292
type CanvasEvents struct {
@@ -103,7 +103,7 @@ var canvas_events: []CanvasEvents
103103
一个`CanvasEvents`对应某个`Canvas`的一组交互事件回调函数,其对应关系由`CanvasEvents.Device_id``Canvas.device_id`确定。canvas包的包级变量`canvas_events`是一个动态数组,凹语言侧代码可以通过`AttachCanvasEvents`函数将一个事件对象附加到事件对象数组中:
104104

105105
```wa
106-
fn AttachCanvasEvents(e: CanvasEvents) {
106+
func AttachCanvasEvents(e: CanvasEvents) {
107107
for i := range canvas_events {
108108
if canvas_events[i].Device_id == e.Device_id {
109109
canvas_events[i] = e
@@ -123,7 +123,7 @@ fn AttachCanvasEvents(e: CanvasEvents) {
123123
id为画布DOM对象对应的Canvas对象id
124124
(x, y)为画布像素坐标系坐标
125125
*/
126-
fn OnMouseDown(id: u32, x, y:u32) {
126+
func OnMouseDown(id: u32, x, y:u32) {
127127
for _, i := range canvas_events {
128128
if i.Device_id == id {
129129
i.OnMouseDown(x, y)
@@ -150,7 +150,7 @@ type GameState struct {
150150
151151
var gameState: GameState
152152
153-
fn GameState.Init(w, h: i32, scale: i32) {
153+
func GameState.Init(w, h: i32, scale: i32) {
154154
this.w = w
155155
this.h = h
156156
this.scale = scale
@@ -159,9 +159,9 @@ fn GameState.Init(w, h: i32, scale: i32) {
159159
160160
var caev: canvas.CanvasEvents
161161
caev.Device_id = this.ca.GetDeviceID()
162-
caev.OnMouseDown = fn(x, y: u32) {}
163-
caev.OnMouseUp = fn(x, y: u32) {}
164-
caev.OnKeyUp = fn(key: u32) {}
162+
caev.OnMouseDown = func(x, y: u32) {}
163+
caev.OnMouseUp = func(x, y: u32) {}
164+
caev.OnKeyUp = func(key: u32) {}
165165
caev.OnKeyDown = this.OnKeyDown
166166
167167
Dirs[DirNull] = Position{x: 0, y: 0}
@@ -179,7 +179,7 @@ fn GameState.Init(w, h: i32, scale: i32) {
179179
游戏的处理流程很简单:
180180

181181
```wa
182-
fn GameState.Step() {
182+
func GameState.Step() {
183183
if this.dir == DirNull {
184184
return
185185
}
@@ -219,11 +219,11 @@ fn GameState.Step() {
219219
this.ca.Flush()
220220
}
221221
222-
fn Step() {
222+
func Step() {
223223
gameState.Step()
224224
}
225225
226-
fn main() {
226+
func main() {
227227
gameState.Init(32, 32, 10)
228228
gameState.Start()
229229
}

0 commit comments

Comments
 (0)