Chinaunix

标题: 看了一眼using perl6 draft,高手指点惊喜在哪里 [打印本页]

作者: liht1981    时间: 2010-07-30 15:56
标题: 看了一眼using perl6 draft,高手指点惊喜在哪里
mutis是函数重载?
role是动态库?
perl6的最大的特点应该不是这些东西吧
作者: flw    时间: 2010-08-01 12:30
Perl6 语法中令人惊叹的特性有很多,
我不愿意说出来,是因为我觉得我的了解还不全面,
仅仅说出一部分怕给别人造成误解而已。

可以摘录一段儿 rakudo star release note 里的内容来回答这个问题:

Some of the many cool Perl 6 features that are available in this release of Rakudo Star:

    * Perl 6 grammars and regexes
    * formal parameter lists and signatures
    * metaoperators
    * gradual typing
    * a powerful object model, including roles and classes
    * lazy list evaluation
    * multiple dispatch
    * smart matching
    * junctions and autothreading
    * operator overloading (limited forms for now)
    * introspection
    * currying
    * a rich library of builtin operators, functions, and types
    * an interactive read-evaluation-print loop
    * Unicode at the codepoint level
    * resumable exceptions

There are some key features of Perl 6 that Rakudo Star does not yet handle appropriately, although they will appear in upcoming releases. Thus, we do not consider Rakudo Star to be a "Perl 6.0.0" or "1.0" release. Some of the not-quite-there features include:

    * nested package definitions
    * binary objects, native types, pack and unpack
    * typed arrays
    * macros
    * state variables
    * threads and concurrency
    * Unicode strings at levels other than codepoints
    * pre and post constraints, and some other phasers
    * interactive readline that understands Unicode
    * backslash escapes in regex <[...]> character classes
    * non-blocking I/O
    * most of Synopsis 9
    * perl6doc or pod manipulation tools
作者: flw    时间: 2010-08-01 13:00
Rakudo star 已经实现的特性里面,
就我了解的来说,

    * Perl 6 grammars and regexes
    * formal parameter lists and signatures
    * metaoperators
    * a powerful object model, including roles and classes
    * lazy list evaluation
    * smart matching
    * junctions and autothreading
    * currying

这些都与很不错的。
其实就算是撇开这些亮点的之外,
就基本的语法结构来说,也大有可圈可点之处,
比如 -> 和 =>,以及和 Perl5 不同的 $@% 的用法规则(在 Perl5 中搞不清楚这些的人可能更加喜欢 Perl6)。
作者: flw    时间: 2010-08-01 13:02
比如以前 foreach 遍历数组的时候,一次只能取一个元素出来,
所以如果恰巧需求是一次需要取两个出来的话,就比较费劲了。
现在的 for 语句就很方便。

for @array -> $a, $b { .......... }
作者: flw    时间: 2010-08-01 13:05
内置数据类型也很丰富,计有:

Bool Bit Int Rat FatRat UInt Num Complex int32 complex64 etc.
Str Cat Blob Char Byte Codepoint Grapheme Buf buf8 buf32 utf8
IO Mu Any Cool Junction Whatever Match
Parcel Capture Signature
Pair Range Set Bag
KeyHash KeySet KeyBag
Scalar Array Hash Code
Enum Order TrigBase
Block Routine Sub
Method Regex
Failure Exception
Instant Duration
Date DateTime

几十种……
作者: flw    时间: 2010-08-01 13:11
其中“元操作符”我认为是 Perl6 最大的亮点之一(grammar/regexe,和 role/class 算另外两个吧)。
这个特性几乎是其它语言所没有的。用来进行列表之间的运算实在是太方便了。

至于 grammar 和正则表达式则把 Perl 在正则表达式领域的领先程度又推到了一个新的、极高的高度。
恐怕在十年之内不会再有语言能够超逾 Perl6 了。(之前一直是 Perl5 在这个领域保持领先地位)
作者: flw    时间: 2010-08-01 13:19
哦,Perl6 的变量名中允许出现连字符(减号),这一点我非常喜欢,如果设计之初能够支持问号和感叹号就更好了。可惜现在加起来似乎有些困难。
作者: flw    时间: 2010-08-01 13:42
而且 multis(多重分配) 也不仅仅是一般语言比如 C++ 中的函数/方法重载,
事实 multis 是一组多重分配有关特性的集合:
1, overloading
2, constraints(guard)
3, narrowness
4, parameter pattern
5, 参数绑定检查(is rw)

Perl6 提供特性,向来都是一堆一堆的。十年的功夫不是白费的。
为什么花了十年时间?除了人手问题之外,
就是因为需要设计一个能够优美地包含全部这些语法特性的语言,
并且考虑如何实现它。
作者: flw    时间: 2010-08-01 13:49
本帖最后由 flw 于 2010-08-01 21:20 编辑

至于 role,我想灵感一定是来自于 Haskell 的 type class 系统。
role 相当于 Haskell 的 type class,但这和大多数人认识的 C++/Java 的 class 有所不同,大大的不同。

就 Perl6 目前的设计,简单地来说,你可以把 role 当成是 C++ 的类型系统中的“纯虚类”,
它的作用就是用来约束子类。但是在 Perl6/Haskell 中不这么理解。

顺便说一句,Perl6 的 role 不仅仅可以是编译时的,还可以是运行时的,举个例子:

if %pluggables($0) -> $plug-in {
    $self does $plug-in;
    return "Loaded $0";
}
作者: wfnh    时间: 2010-08-01 17:10
听起来··很激动人心·
作者: Wayne_sama    时间: 2010-08-02 10:42
鸡冻啊,赶紧学习,希望能在起跑的时候就领先一点
作者: zhuomingliang    时间: 2010-08-02 11:31
哦,Perl6 的变量名中允许出现连字符(减号),这一点我非常喜欢,如果设计之初能够支持问号和感叹号就更好 ...
flw 发表于 2010-08-01 13:19



    没事,perl6 支持动态扩展自己的语法,你忘记了?
作者: zhuomingliang    时间: 2010-08-02 11:32
看的出来,flw 对于perl6 的功能,非常的喜欢和鸡冻/动
作者: flw    时间: 2010-08-02 11:49
没事,perl6 支持动态扩展自己的语法,你忘记了?
zhuomingliang 发表于 2010-08-02 11:31

你个土人。你根本不明白我在说什么。
可以加,但如何加?

这是一个设计问题,难点在于设计。
作者: zhuomingliang    时间: 2010-08-02 12:11
你个土人。你根本不明白我在说什么。
可以加,但如何加?

这是一个设计问题,难点在于设计。
flw 发表于 2010-08-02 11:49



    如果你觉得你不满意现有的语法,你可以继承原有 的语法,并使用你自己的语法的,你忘记我和你讲过这个了? http://www.perlgeek.de/blog-en/ 有这个例子的。
作者: cinanine    时间: 2011-04-04 11:22
很激动
作者: kingwmj    时间: 2011-04-04 19:12
我也很期等,前几天试用了一下。 只试用了“hello world”。还很慢。前面讲的语法,我都没有试成功。
作者: d4rkl0rd    时间: 2011-04-04 19:30
如果把性能搞上去就爽了...




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2