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学习手册
猜数
33
试图改变这个值时,就会得到一个错误:
Cannot assign to an immutable value
并不是绑定操作符使这个变量不可变。它只是让左边的内容与右边相同。在这里,
$sides-of-square
实际上是
4
,而不是一个恰好存
4
的变量。不能
4
值,所
以也不能对
$sides-of-a-square
赋值。
如果先为一个标量变量赋值,然后又绑定到那个变量,最后就会得到同一个变量的
两个名字:
my $number = 3;
my $sides := $number;
如果改变
$sides
$number
,“另一个”也会改变。不过,这里并没有“另一个”
要改变,因为它们都是同一个东西!可以把它们看作是别名,不过要稍稍复杂一些。
这里有一个重要的概念,需要早一点了解。用
=
完成的变量赋值会创建一个容器,
然后把一个值放在这个容器中。容器就是一个可以存储的盒子。可以增加、删除和
替换这个盒子里的值。这对你基本上是不可见的,因为
Perl 6
语言会为你完成这一切。
绑定操作符会跳过这种容器工作。它直接对右边的东西建立别名。如果这已经是一
个容器,那就绑定这个容器。可以把赋值动作分解为两步。第一步绑定到一个匿名
容器。这是可以的:一个容器即使没有名字也能存在。匿名容器就是
$ sigil:
my $number := $;
然后,使用
=
改变容器中的值:
$number = 3;
有时你需要知道一个东西是否是容器,还有一些情况下你可能想跳过容器部分。在
养成坏习惯之前,要尽早考虑这些问题,这会让你的编程生涯更容易一些。 ...
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