File tree Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -1232,8 +1232,8 @@ X<|Virtual Machine>
1232
1232
1233
1233
A virtual machine is the Perl compiler entity that executes the
1234
1234
L < bytecode|#bytecode > . It can optimize the bytecode or generate machine code
1235
- Just in Time. Examples are L < #MoarVM > , L < #Parrot > (who are intended to run Perl
1236
- 6) and more generic virtual machines such as JVM and Javascript.
1235
+ Just in Time. Examples are L < #MoarVM > , L < #Parrot > (who are intended to run
1236
+ Perl 6) and more generic virtual machines such as JVM and Javascript.
1237
1237
1238
1238
= head1 whitespace
1239
1239
X < |whitespace >
Original file line number Diff line number Diff line change @@ -334,7 +334,7 @@ of all values of a C<Hash>.
334
334
335
335
my Int %h;
336
336
put %h<Goku> = 900;
337
-
337
+
338
338
try {
339
339
%h<Vegeta> = "string";
340
340
CATCH { when X::TypeCheck::Binding { .message.put } }
@@ -343,36 +343,36 @@ of all values of a C<Hash>.
343
343
# OUTPUT:
344
344
# 9001
345
345
# Type check failed in assignment to %h; expected Int but got Str ("string")
346
-
346
+
347
347
You can do the same by a more readable syntax.
348
348
349
349
my %h of Int; # the same as my Int %h
350
-
350
+
351
351
If you want to constraint the type of all keys of a C < Hash > , add C < {Type} > following
352
352
the name of variable.
353
353
354
354
my %h{Int};
355
-
355
+
356
356
Even put these two constriant together.
357
357
358
358
my %h{Int} of Int;
359
359
put %h{21} = 42;
360
-
360
+
361
361
try {
362
362
%h{0} = "String";
363
363
CATCH { when X::TypeCheck::Binding { .message.put } }
364
364
}
365
-
365
+
366
366
try {
367
367
%h<string> = 42;
368
368
CATCH { when X::TypeCheck::Binding { .message.put } }
369
369
}
370
-
370
+
371
371
try {
372
372
%h<string> = "String";
373
373
CATCH { when X::TypeCheck::Binding { .message.put } }
374
374
}
375
-
375
+
376
376
# OUTPUT:
377
377
# 42
378
378
# Type check failed in binding to parameter 'assignval'; expected Int but got Str ("String")
You can’t perform that action at this time.
0 commit comments