是否有比较 Scala 和 JavaFX Script 的代码示例?
我正在研究 JavaFX Script 并尝试将其与 Scala 进行比较,Scala 是 Java 平台的另一种非常有趣的新语言。
在Scala官方网站上我找到了这个例子,这是一个快速排序的实现。 然后,我编写了以下等效的 JavaFX Script 程序(使用 NetBeans IDE 6.7.1):
package examples;
function sort(a: Integer[]): Integer[] {
if (sizeof a < 2)
a
else {
def pivot = a[sizeof a / 2];
[sort(a[n | n < pivot]), a[n | n == pivot], sort(a[n | n > pivot])];
}
}
function run(args: String[]) {
def xs = [6, 2, 8, 5, 1];
println(xs);
println(sort(xs));
}
两个功能程序非常相似,但我更喜欢 JavaFX 版本。 Scala 版本中的那些“_”和“:::”部分对我来说看起来不太有吸引力……
当然,两种语言还有更多内容,所以我正在寻找更多示例。 有人知道我在哪里可以找到一些吗?或者更好的是,在这里发布其他示例?
I am studying JavaFX Script and trying to compare it to Scala, which is another very interesting new language for the Java platform.
In the official Scala site I found this example, which is a Quick Sort implementation.
I then wrote the following equivalent JavaFX Script program (using NetBeans IDE 6.7.1):
package examples;
function sort(a: Integer[]): Integer[] {
if (sizeof a < 2)
a
else {
def pivot = a[sizeof a / 2];
[sort(a[n | n < pivot]), a[n | n == pivot], sort(a[n | n > pivot])];
}
}
function run(args: String[]) {
def xs = [6, 2, 8, 5, 1];
println(xs);
println(sort(xs));
}
Both functional programs are very similar, but I like the JavaFX version better. Those "_" and ":::" parts in the Scala version don't look very appealing to me...
Of course, there is a lot more to both languages, so I am looking for more examples.
Does anybody know where I can find some? Or even better, post other examples here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请记住,Scala 语法非常灵活。您可以这样轻松地编写没有“:::”和“_”的代码:
对于代码比较,我通常查看 http ://rosettacode.org/
它有几个 Scala 示例,但没有 JavaFX 示例。如果您在该项目中取得了进展,请花时间向该站点添加一些 JavaFX。 :-)
Keep in mind that the Scala syntax is flexible. You could have easily written it without the ":::" and "_" this way:
For code comparisons, I usually look at http://rosettacode.org/
It has several Scala examples, but no JavaFX ones. If you get far in this project, please take the time to add some JavaFX to that site. :-)