免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 5212 | 回复: 17
打印 上一主题 下一主题

看了一眼using perl6 draft,高手指点惊喜在哪里 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-07-30 15:56 |只看该作者 |倒序浏览
mutis是函数重载?
role是动态库?
perl6的最大的特点应该不是这些东西吧

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
2 [报告]
发表于 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

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
3 [报告]
发表于 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)。

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
4 [报告]
发表于 2010-08-01 13:02 |只看该作者
比如以前 foreach 遍历数组的时候,一次只能取一个元素出来,
所以如果恰巧需求是一次需要取两个出来的话,就比较费劲了。
现在的 for 语句就很方便。

for @array -> $a, $b { .......... }

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
5 [报告]
发表于 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

几十种……

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
6 [报告]
发表于 2010-08-01 13:11 |只看该作者
其中“元操作符”我认为是 Perl6 最大的亮点之一(grammar/regexe,和 role/class 算另外两个吧)。
这个特性几乎是其它语言所没有的。用来进行列表之间的运算实在是太方便了。

至于 grammar 和正则表达式则把 Perl 在正则表达式领域的领先程度又推到了一个新的、极高的高度。
恐怕在十年之内不会再有语言能够超逾 Perl6 了。(之前一直是 Perl5 在这个领域保持领先地位)

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
7 [报告]
发表于 2010-08-01 13:19 |只看该作者
哦,Perl6 的变量名中允许出现连字符(减号),这一点我非常喜欢,如果设计之初能够支持问号和感叹号就更好了。可惜现在加起来似乎有些困难。

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
8 [报告]
发表于 2010-08-01 13:42 |只看该作者
而且 multis(多重分配) 也不仅仅是一般语言比如 C++ 中的函数/方法重载,
事实 multis 是一组多重分配有关特性的集合:
1, overloading
2, constraints(guard)
3, narrowness
4, parameter pattern
5, 参数绑定检查(is rw)

Perl6 提供特性,向来都是一堆一堆的。十年的功夫不是白费的。
为什么花了十年时间?除了人手问题之外,
就是因为需要设计一个能够优美地包含全部这些语法特性的语言,
并且考虑如何实现它。

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
9 [报告]
发表于 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";
}

论坛徽章:
0
10 [报告]
发表于 2010-08-01 17:10 |只看该作者
听起来··很激动人心·
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP