Skip to Content
Raku学习手册
book

Raku学习手册

by brian d foy
October 2020
Beginner to intermediate
499 pages
9h 13m
Chinese
China Electric Power Press Ltd.
Content preview from Raku学习手册
数字
61
就像之前处理
if
一样,可以使用同样的方法用
do
使这个代码更简短。最后计算的
表达式将作为整个
given
结构的值:
put 'Saw ', do given $some-number {
when Int { 'an integer' }
when Complex { 'a complex number' }
when Rat { 'a rat! Eek!' }
default { 'something' }
}
练习
3.3
使用
given
创建一个程序,报告你在命令行指定的数字的类型。
17
17.0
17i
Hamadryas
等参数尝试运行这个程序。
还可以用
$_
做一件有意思的事情。如果有一种方法调用点号,但是左边没有对象,
就会使用
$_
为对象:
$_.put;
.put;
put $_.roots unless $_.is-prime;
put .roots unless .is-prime;
可以使用一个后缀
given
为一个语句设置
$_
从而避免多次键入变量。在这本书中,
你还会经常看到这个隐式主题
$_
my $some-number = 19;
put .^name, ' ', .is-prime given $some-number;
3.3
有理数
Perl 6
使用整数将非整数表示为分数(
fractions
)。你可能想当然地把它表示为一个
有小数点的数(有时称为浮点数),但是编译器会把它转换为一个分数。你能看到
这个简分数的分子和分母:
% perl6 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

可编程网络自动化

可编程网络自动化

Jason Edelman, Scott S. Lowe, Matt Oswalt
程序员学数据结构

程序员学数据结构

Posts & Telecom Press, William Smith
R深度学习权威指南

R深度学习权威指南

Posts & Telecom Press, Joshua F. Wiley
AI工程

AI工程

Chip Huyen

Publisher Resources

ISBN: 9787519848002