Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

改进复合语句的语义 #19

Closed
xushiwei opened this issue Apr 3, 2016 · 1 comment
Closed

改进复合语句的语义 #19

xushiwei opened this issue Apr 3, 2016 · 1 comment
Milestone

Comments

@xushiwei
Copy link
Member

xushiwei commented Apr 3, 2016

a = if x < y {
    x
} else {
    y
}

当前的结果为 nil。如果我们认为:复合语句 { s1; s2; ...; sN; } 的值为 sN,那么以上表达式就等价于:

a = min(x, y)

另外,函数的语义也可以调整:

foo = fn() { s1; s2; ...; sN; }

如果中间没有出现 return,那么 foo() 的结果为 nil。但是我们可以调整为值也是 sN。这样 qlang 的 fn 就有点类似函数式的味道了。示例:

min = fn(x, y) {
    if x < y { x } else { y }
}
@xushiwei xushiwei added this to the qlang.v3 milestone Apr 3, 2016
@xushiwei xushiwei modified the milestones: qlang.v2, qlang.v3 Apr 8, 2016
@xushiwei
Copy link
Member Author

xushiwei commented Apr 9, 2016

考虑到支持 if, switch 有值的成本比较高,并且和常规语言有较大差异,打算改变 statement 语义,不再是个值。这样 if, switch, for 语句也就没有值。

@xushiwei xushiwei closed this as completed Apr 9, 2016
xushiwei added a commit that referenced this issue Apr 10, 2016
* #21 thread-safe module init
* #19 redefine meanings of compound statements
* #26 #19 break/continue, statement without value
* dumpCode mode
xushiwei added a commit that referenced this issue May 21, 2016
* #21 thread-safe module init
* #19 redefine meanings of compound statements
* #26 #19 break/continue, statement without value
* dumpCode mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant