Skip to content
This repository has been archived by the owner on Dec 20, 2018. It is now read-only.

Commit

Permalink
Modify README
Browse files Browse the repository at this point in the history
  • Loading branch information
haifenghuang committed Dec 7, 2017
1 parent d9a21ac commit 7c081e4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ e = 5
= ""
```

Note however, if you do not use the keyword `let`, you could not do multiple variable assignments.
Below code is not correct:

```swift
//Error, multiple variable assignments must be use `let` keyword
a, b, c = 1, "hello world", [1,2,3]
```


### Reserved keywords

Keywords are predefined, reserved identifiers that have special meanings to the compiler. They cannot be used as identifiers. Below is a list of reserved keywords
Expand Down Expand Up @@ -782,6 +791,26 @@ fn sub(x,y=2) {
println(sub(10)) //output : 8
```
Monkey do not support multiple return values, But there are many ways to do it.
Below suggest a way of doing it:
```swift
fn div(x, y) {
if y == 0 {
return [nil, "y could not be zero"]
}
return [x/y, ""]
}
ret = div(10,5)
if ret[1] != "" {
println(ret[1])
} else {
println(ret[0])
}
```
## Pipe Operator
The pipe operator, inspired by [Elixir](https://elixir-lang.org/).
Expand Down
27 changes: 27 additions & 0 deletions README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ e = 5
=""
```

如果你不使用`let`来给变量赋值,那么你将不能使用多变量赋值。下面的语句是错误的:

```swift
//错误,多变量赋值必须使用let关键字
a, b, c = 1, "hello world", [1,2,3]
```

## 保留字

下面列出了monkey语言的保留字:
Expand Down Expand Up @@ -765,6 +772,26 @@ fn sub(x,y=2) {
println(sub(10)) //结果 : 8
```
Monkey不支持多个返回值, 但有很多方法可以达到目的.
下面是其中的一种实现方式:
```swift
fn div(x, y) {
if y == 0 {
return [nil, "y could not be zero"]
}
return [x/y, ""]
}
ret = div(10,5)
if ret[1] != "" {
println(ret[1])
} else {
println(ret[0])
}
```
## Pipe操作符
`pipe`操作符来自[Elixir](https://elixir-lang.org/).
Expand Down

0 comments on commit 7c081e4

Please sign in to comment.