-
-
Save coke/e9cc048b059a850a34f91314076b43ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1..3140 | |
# class Point { | |
# has Int $.x; | |
# has Int $.y; | |
# } | |
# class Rectangle { | |
# has Point $.lower; | |
# has Point $.upper; | |
# method area() returns Int { | |
# ($!upper.x - $!lower.x) * ( $!upper.y - $!lower.y); | |
# } | |
# } | |
# # Create a new Rectangle from two Points | |
# my $r = Rectangle.new(lower => Point.new(x => 0, y => 0), upper => Point.new(x => 10, y => 10)); | |
# say $r.area(); # OUTPUT: «100» | |
ok 1 - doc/Language/classtut.pod6 chunk 1 compiles | |
# class Task { | |
# has &!callback; | |
# has Task @!dependencies; | |
# has Bool $.done; | |
# # Normally doesn't need to be written | |
# # BUILD is the equivalent of a constructor in other languages | |
# method new(&callback, *@dependencies) { | |
# return self.bless(:&callback, :@dependencies); | |
# } | |
# submethod BUILD(:&!callback, :@!dependencies) { } | |
# method add-dependency(Task $dependency) { | |
# push @!dependencies, $dependency; | |
# } | |
# method perform() { | |
# unless $!done { | |
# .perform() for @!dependencies; | |
# &!callback(); | |
# $!done = True; | |
# } | |
# } | |
# } | |
# my $eat = | |
# Task.new({ say 'eating dinner. NOM!' }, | |
# Task.new({ say 'making dinner' }, | |
# Task.new({ say 'buying food' }, | |
# Task.new({ say 'making some money' }), | |
# Task.new({ say 'going to the store' }) | |
# ), | |
# Task.new({ say 'cleaning kitchen' }) | |
# ) | |
# ); | |
# $eat.perform(); | |
ok 2 - doc/Language/classtut.pod6 chunk 2 compiles | |
# say Int.DEFINITE; # OUTPUT: «False» (type object) | |
# say 426.DEFINITE; # OUTPUT: «True» (instance) | |
# class Foo {}; | |
# say Foo.DEFINITE; # OUTPUT: «False» (type object) | |
# say Foo.new.DEFINITE; # OUTPUT: «True» (instance) | |
ok 3 - doc/Language/classtut.pod6 chunk 3 compiles | |
# multi foo (Int:U) { "It's a type object!" } | |
# multi foo (Int:D) { "It's an instance!" } | |
# say foo Int; # OUTPUT: «It's a type object!» | |
# say foo 42; # OUTPUT: «It's an instance!» | |
ok 4 - doc/Language/classtut.pod6 chunk 4 compiles | |
# has Bool $!done; | |
# method done() { return $!done } | |
ok 5 - doc/Language/classtut.pod6 chunk 5 compiles | |
# has Bool $.done is rw; | |
ok 6 - doc/Language/classtut.pod6 chunk 6 compiles | |
# has Bool $.done = False; | |
ok 7 - doc/Language/classtut.pod6 chunk 7 compiles | |
# class Singleton { | |
# my Singleton $instance; | |
# method new {!!!} | |
# submethod instance { | |
# $instance = Singleton.bless unless $instance; | |
# $instance; | |
# } | |
# } | |
ok 8 - doc/Language/classtut.pod6 chunk 8 compiles | |
# class B {...} | |
# class C { | |
# trusts B; | |
# has $!hidden = 'invisible'; | |
# method !not-yours () { say 'hidden' } | |
# method yours-to-use () { | |
# say $!hidden; | |
# self!not-yours(); | |
# } | |
# } | |
# class B { | |
# method i-am-trusted () { | |
# my C $c.=new; | |
# $c!C::not-yours(); | |
# } | |
# } | |
# C.new.yours-to-use(); # the context of this call is GLOBAL, and not trusted by C | |
# B.new.i-am-trusted(); | |
ok 9 - doc/Language/classtut.pod6 chunk 9 compiles | |
# method new(&callback, *@dependencies) { | |
# return self.bless(:&callback, :@dependencies); | |
# } | |
ok 10 - doc/Language/classtut.pod6 chunk 10 compiles | |
# class Employee { | |
# has $.salary; | |
# method pay() { | |
# say "Here is \$$.salary"; | |
# } | |
# } | |
# class Programmer is Employee { | |
# has @.known_languages is rw; | |
# has $.favorite_editor; | |
# method code_to_solve( $problem ) { | |
# say "Solving $problem using $.favorite_editor in " | |
# ~ $.known_languages[0] ~ '.'; | |
# } | |
# } | |
ok 11 - doc/Language/classtut.pod6 chunk 11 compiles | |
# my $p1 = Promise.new; | |
# say $p1.status; # OUTPUT: «Planned» | |
# $p1.keep('result'); | |
# say $p1.status; # OUTPUT: «Kept» | |
# say $p1.result; # OUTPUT: «result» | |
# # (since it has been kept, a result is available!) | |
# my $p2 = Promise.new; | |
# $p2.break('oh no'); | |
# say $p2.status; # OUTPUT: «Broken» | |
# say $p2.result; # dies, because the promise has been broken | |
# CATCH { default { say .^name, ': ', .Str } }; | |
# # OUTPUT: «X::AdHoc+{X::Promise::Broken}: oh no» | |
ok 12 - doc/Language/concurrency.pod6 chunk 1 compiles | |
# my $promise1 = Promise.new(); | |
# my $promise2 = $promise1.then( | |
# -> $v { say $v.result; "Second Result" } | |
# ); | |
# $promise1.keep("First Result"); | |
# say $promise2.result; # OUTPUT: «First ResultSecond Result» | |
ok 13 - doc/Language/concurrency.pod6 chunk 2 compiles | |
# my $promise1 = Promise.new(); | |
# my $promise2 = $promise1.then(-> $v { say "Handled but : "; say $v.result}); | |
# $promise1.break("First Result"); | |
# try $promise2.result; | |
# say $promise2.cause; # OUTPUT: «Handled but : First Result» | |
ok 14 - doc/Language/concurrency.pod6 chunk 3 compiles | |
# my $promise1 = Promise.in(5); | |
# my $promise2 = $promise1.then(-> $v { say $v.status; 'Second Result' }); | |
# say $promise2.result; | |
ok 15 - doc/Language/concurrency.pod6 chunk 4 compiles | |
# my $promise = Promise.start( | |
# { my $i = 0; for 1 .. 10 { $i += $_ }; $i} | |
# ); | |
# say $promise.result; # OUTPUT: «55» | |
ok 16 - doc/Language/concurrency.pod6 chunk 5 compiles | |
# my $promise = Promise.start({ die "Broken Promise" }); | |
# try $promise.result; | |
# say $promise.cause; | |
ok 17 - doc/Language/concurrency.pod6 chunk 6 compiles | |
# my $promise = start { | |
# my $i = 0; | |
# for 1 .. 10 { | |
# $i += $_ | |
# } | |
# $i | |
# } | |
# my $result = await $promise; | |
# say $result; | |
ok 18 - doc/Language/concurrency.pod6 chunk 7 compiles | |
# my $p1 = start { | |
# my $i = 0; | |
# for 1 .. 10 { | |
# $i += $_ | |
# } | |
# $i | |
# }; | |
# my $p2 = start { | |
# my $i = 0; | |
# for 1 .. 10 { | |
# $i -= $_ | |
# } | |
# $i | |
# }; | |
# my @result = await $p1, $p2; | |
# say @result; # OUTPUT: «[55 -55]» | |
ok 19 - doc/Language/concurrency.pod6 chunk 8 compiles | |
# my $promise = Promise.allof( | |
# Promise.in(2), | |
# Promise.in(3) | |
# ); | |
# await $promise; | |
# say "All done"; # Should be not much more than three seconds later | |
ok 20 - doc/Language/concurrency.pod6 chunk 9 compiles | |
# my $promise = Promise.anyof( | |
# Promise.in(3), | |
# Promise.in(8600) | |
# ); | |
# await $promise; | |
# say "All done"; # Should be about 3 seconds later | |
ok 21 - doc/Language/concurrency.pod6 chunk 10 compiles | |
# my @promises; | |
# for 1..5 -> $t { | |
# push @promises, start { | |
# sleep $t; | |
# Bool.pick; | |
# }; | |
# } | |
# say await Promise.allof(@promises).then({ so all(@promises>>.result) }); | |
ok 22 - doc/Language/concurrency.pod6 chunk 11 compiles | |
# sub get_promise { | |
# my $promise = Promise.new; | |
# my $vow = $promise.vow; | |
# Promise.in(10).then({$vow.keep}); | |
# $promise; | |
# } | |
# my $promise = get_promise(); | |
# # Will throw an exception | |
# # "Access denied to keep/break this Promise; already vowed" | |
# $promise.keep; | |
# CATCH { default { say .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Promise::Vowed: Access denied to keep/break this Promise; already vowed» | |
ok 23 - doc/Language/concurrency.pod6 chunk 12 compiles | |
# my $supplier = Supplier.new; | |
# my $supply = $supplier.Supply; | |
# $supply.tap( -> $v { say $v }); | |
# for 1 .. 10 { | |
# $supplier.emit($_); | |
# } | |
ok 24 - doc/Language/concurrency.pod6 chunk 13 compiles | |
# my $supply = supply { | |
# for 1 .. 10 { | |
# emit($_); | |
# } | |
# } | |
# $supply.tap( -> $v { say $v }); | |
ok 25 - doc/Language/concurrency.pod6 chunk 14 compiles | |
# my $supply = supply { | |
# for 1 .. 10 { | |
# emit($_); | |
# } | |
# } | |
# $supply.tap( -> $v { say "First : $v" }); | |
# $supply.tap( -> $v { say "Second : $v" }); | |
ok 26 - doc/Language/concurrency.pod6 chunk 15 compiles | |
# my $supplier = Supplier.new; | |
# my $supply = $supplier.Supply; | |
# my $tap = $supply.tap( -> $v { say $v }); | |
# $supplier.emit("OK"); | |
# $tap.close; | |
# $supplier.emit("Won't trigger the tap"); | |
ok 27 - doc/Language/concurrency.pod6 chunk 16 compiles | |
# my $supply = Supply.interval(2); | |
# $supply.tap(-> $v { say $v }); | |
# sleep 10; | |
ok 28 - doc/Language/concurrency.pod6 chunk 17 compiles | |
# react { | |
# whenever Supply.interval(2) -> $v { | |
# say $v; | |
# done() if $v == 4; | |
# } | |
# } | |
ok 29 - doc/Language/concurrency.pod6 chunk 18 compiles | |
# my $supply = Supply.interval(2); | |
# $supply.tap(-> $v { say "First $v" }); | |
# sleep 6; | |
# $supply.tap(-> $v { say "Second $v"}); | |
# sleep 10; | |
ok 30 - doc/Language/concurrency.pod6 chunk 19 compiles | |
# react { | |
# whenever Supply.from-list(1..10) -> $v { | |
# say $v; | |
# } | |
# } | |
ok 31 - doc/Language/concurrency.pod6 chunk 20 compiles | |
# my $supplier = Supplier.new; | |
# my $supply = $supplier.Supply; | |
# $supply.tap(-> $v { say "Original : $v" }); | |
# my $odd_supply = $supply.grep({ $_ % 2 }); | |
# $odd_supply.tap(-> $v { say "Odd : $v" }); | |
# my $even_supply = $supply.grep({ not $_ % 2 }); | |
# $even_supply.tap(-> $v { say "Even : $v" }); | |
# for 0 .. 10 { | |
# $supplier.emit($_); | |
# } | |
ok 32 - doc/Language/concurrency.pod6 chunk 21 compiles | |
# my $supplier = Supplier.new; | |
# my $supply = $supplier.Supply; | |
# $supply.tap(-> $v { say "Original : $v" }); | |
# my $half_supply = $supply.map({ $_ / 2 }); | |
# $half_supply.tap(-> $v { say "Half : $v" }); | |
# for 0 .. 10 { | |
# $supplier.emit($_); | |
# } | |
ok 33 - doc/Language/concurrency.pod6 chunk 22 compiles | |
# my $channel = Channel.new; | |
# $channel.send('Channel One'); | |
# say $channel.receive; # OUTPUT: «Channel One» | |
ok 34 - doc/Language/concurrency.pod6 chunk 23 compiles | |
# my $channel = Channel.new; | |
# await (^10).map: -> $r { | |
# start { | |
# sleep $r; | |
# $channel.send($r); | |
# } | |
# } | |
# $channel.close; | |
# for $channel.list -> $r { | |
# say $r; | |
# } | |
ok 35 - doc/Language/concurrency.pod6 chunk 24 compiles | |
# my $c = Channel.new; | |
# # Start three Promises that sleep for 1..3 seconds, and then | |
# # send a value to our Channel | |
# ^3 .map: -> $v { | |
# start { | |
# sleep 3 - $v; | |
# $c.send: "$v from thread {$*THREAD.id}"; | |
# } | |
# } | |
# # Wait 3 seconds before closing the channel | |
# Promise.in(3).then: { $c.close } | |
# # Continuously loop and poll the channel, until it's closed | |
# my $is-closed = $c.closed; | |
# loop { | |
# if $c.poll -> $item { | |
# say "$item received after {now - INIT now} seconds"; | |
# } | |
# elsif $is-closed { | |
# last; | |
# } | |
# say 'Doing some unrelated things...'; | |
# sleep .6; | |
# } | |
# # Doing some unrelated things... | |
# # Doing some unrelated things... | |
# # 2 from thread 5 received after 1.2063182 seconds | |
# # Doing some unrelated things... | |
# # Doing some unrelated things... | |
# # 1 from thread 4 received after 2.41117376 seconds | |
# # Doing some unrelated things... | |
# # 0 from thread 3 received after 3.01364461 seconds | |
# # Doing some unrelated things... | |
ok 36 - doc/Language/concurrency.pod6 chunk 25 compiles | |
# my $supplier = Supplier.new; | |
# my $supply = $supplier.Supply; | |
# my $channel = $supply.Channel; | |
# my $p = start { | |
# react { | |
# whenever $channel -> $item { | |
# say "via Channel: $item"; | |
# } | |
# } | |
# } | |
# await (^10).map: -> $r { | |
# start { | |
# sleep $r; | |
# $supplier.emit($r); | |
# } | |
# } | |
# $supplier.done; | |
# await $p; | |
ok 37 - doc/Language/concurrency.pod6 chunk 26 compiles | |
# my $proc = Proc::Async.new('echo', 'foo', 'bar'); | |
# $proc.stdout.tap(-> $v { print "Output: $v" }); | |
# $proc.stderr.tap(-> $v { print "Error: $v" }); | |
# say "Starting..."; | |
# my $promise = $proc.start; | |
# await $promise; | |
# say "Done."; | |
# # Output: | |
# # Starting... | |
# # Output: foo bar | |
# # Done. | |
ok 38 - doc/Language/concurrency.pod6 chunk 27 compiles | |
# my $proc = Proc::Async.new(:w, 'grep', 'foo'); | |
# $proc.stdout.tap(-> $v { print "Output: $v" }); | |
# say "Starting..."; | |
# my $promise = $proc.start; | |
# $proc.say("this line has foo"); | |
# $proc.say("this one doesn't"); | |
# $proc.close-stdin; | |
# await $promise; | |
# say "Done."; | |
# # Output: | |
# # Starting... | |
# # Output: this line has foo | |
# # Done. | |
ok 39 - doc/Language/concurrency.pod6 chunk 28 compiles | |
# my $thread = Thread.new(code => { for 1 .. 10 -> $v { say $v }}); | |
# # ... | |
# $thread.run; | |
ok 40 - doc/Language/concurrency.pod6 chunk 29 compiles | |
# my $thread = Thread.start({ for 1 .. 10 -> $v { say $v }}); | |
ok 41 - doc/Language/concurrency.pod6 chunk 30 compiles | |
# method cue(:&code, Instant :$at, :$in, :$every, :$times = 1; :&catch) | |
ok 42 - doc/Language/concurrency.pod6 chunk 31 compiles | |
# my $i = 0; | |
# my $cancellation = $*SCHEDULER.cue({ say $i++}, every => 2 ); | |
# sleep 20; | |
ok 43 - doc/Language/concurrency.pod6 chunk 32 compiles | |
# my $i = 0; | |
# my $cancellation = $*SCHEDULER.cue({ say $i++}, every => 2 ); | |
# sleep 10; | |
# $cancellation.cancel; | |
# sleep 10; | |
ok 44 - doc/Language/concurrency.pod6 chunk 33 compiles | |
# my $lock = Lock.new; | |
# my $a = 0; | |
# await (^10).map: { | |
# start { | |
# $lock.protect({ | |
# my $r = rand; | |
# sleep $r; | |
# $a++; | |
# }); | |
# } | |
# } | |
# say $a; # OUTPUT: «10» | |
ok 45 - doc/Language/concurrency.pod6 chunk 34 compiles | |
# my @array; | |
# my $slot := @array[20]; | |
# $slot = 'foo'; | |
ok 46 - doc/Language/concurrency.pod6 chunk 35 compiles | |
# my $x = 42; | |
# say $x; | |
ok 47 - doc/Language/containers.pod6 chunk 1 compiles | |
# sub f($a is rw) { | |
# $a = 23; | |
# } | |
# my $x = 42; | |
# f($x); | |
# say $x; # OUTPUT: «23» | |
ok 48 - doc/Language/containers.pod6 chunk 2 compiles | |
# my $x = 23; | |
# sub f() is rw { $x }; | |
# f() = 42; | |
# say $x; # OUTPUT: «42» | |
ok 49 - doc/Language/containers.pod6 chunk 3 compiles | |
# class A { | |
# has $.attr is rw; | |
# } | |
ok 50 - doc/Language/containers.pod6 chunk 4 compiles | |
# class A { | |
# has $!attr; | |
# method attr() is rw { $!attr } | |
# } | |
ok 51 - doc/Language/containers.pod6 chunk 5 compiles | |
# my $x = 42; | |
# say $x.^name; # OUTPUT: «Int» | |
# say $x.VAR.^name; # OUTPUT: «Scalar» | |
ok 52 - doc/Language/containers.pod6 chunk 6 compiles | |
# sub f($x is rw) { say $x }; | |
# f 42; | |
# CATCH { default { say .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Parameter::RW: Parameter '$x' expected a writable container, but got Int value» | |
ok 53 - doc/Language/containers.pod6 chunk 7 compiles | |
# my $x := 42; | |
ok 54 - doc/Language/containers.pod6 chunk 8 compiles | |
# my $x := 42; | |
# $x = 23; | |
# CATCH { default { say .^name, ': ', .Str } }; | |
# # OUTPUT: «X::AdHoc: Cannot assign to an immutable value» | |
ok 55 - doc/Language/containers.pod6 chunk 9 compiles | |
# my $a = 0; | |
# my $b = 0; | |
# $a := $b; | |
# $b = 42; | |
# say $a; # OUTPUT: «42» | |
ok 56 - doc/Language/containers.pod6 chunk 10 compiles | |
# my $a = 42; | |
# my \b = $a; | |
# b++; | |
# say $a; # OUTPUT: «43» | |
# sub f($c is raw) { $c++ } | |
# f($a); | |
# say $a; # OUTPUT: «44» | |
ok 57 - doc/Language/containers.pod6 chunk 11 compiles | |
# say (1, 2, 3).^name; # OUTPUT: «List» | |
ok 58 - doc/Language/containers.pod6 chunk 12 compiles | |
# my $x = 42; | |
# ($x, 1, 2)[0] = 23; | |
# say $x; # OUTPUT: «23» | |
# ($x, 1, 2)[1] = 23; # Cannot modify an immutable value | |
# CATCH { default { say .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Assignment::RO: Cannot modify an immutable Int» | |
ok 59 - doc/Language/containers.pod6 chunk 13 compiles | |
# my @a = 1, 2, 3; | |
# @a[0] = 42; | |
# say @a; # OUTPUT: «[42 2 3]» | |
ok 60 - doc/Language/containers.pod6 chunk 14 compiles | |
# my $x = 42; say $x.^name; # OUTPUT: «Int» | |
# my @a = 42; say @a.^name; # OUTPUT: «Array» | |
ok 61 - doc/Language/containers.pod6 chunk 15 compiles | |
# my @a := (1, 2, 3); | |
# say @a.WHAT; # OUTPUT: «(List)» | |
ok 62 - doc/Language/containers.pod6 chunk 16 compiles | |
# my @a = (1, 2, 3); | |
# @a[0] := my $x; | |
# $x = 42; | |
# say @a; # OUTPUT: «[42 2 3]» | |
ok 63 - doc/Language/containers.pod6 chunk 17 compiles | |
# my @a = (1, 2, 3); | |
# @a[0] := 42; # This is not recommended, use assignment instead. | |
# my $b := 42; | |
# @a[1] := $b; # Nor is this. | |
# @a[2] = $b; # ...but this is fine. | |
# @a[1, 2] := 1, 2; # runtime error: X::Bind::Slice | |
# CATCH { default { say .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Bind::Slice: Cannot bind to Array slice» | |
ok 64 - doc/Language/containers.pod6 chunk 18 compiles | |
# my @a = 1, 2, 3; | |
# for @a { }; # 3 iterations | |
# my $a = (1, 2, 3); | |
# for $a { }; # 1 iteration | |
ok 65 - doc/Language/containers.pod6 chunk 19 compiles | |
# my @a = 1, 2, 3; | |
# my @b = @a, 4, 5; | |
# say @b.elems; # OUTPUT: «3» | |
ok 66 - doc/Language/containers.pod6 chunk 20 compiles | |
# my @a = 1, 2, 3; | |
# say (flat @a, 4, 5).elems; # OUTPUT: «5» | |
# sub f(*@x) { @x.elems }; | |
# say f @a, 4, 5; # OUTPUT: «5» | |
ok 67 - doc/Language/containers.pod6 chunk 21 compiles | |
# sub f(*@x) { @x.elems }; | |
# my @a = 1, 2, 3; | |
# say f $@a, 4, 5; # OUTPUT: «3» | |
ok 68 - doc/Language/containers.pod6 chunk 22 compiles | |
# my $x = (1, 2, 3); | |
# .say for @$x; # 3 iterations | |
ok 69 - doc/Language/containers.pod6 chunk 23 compiles | |
# my $x = (1, 2, 3); | |
# $x.map(*.say); # 3 iterations | |
ok 70 - doc/Language/containers.pod6 chunk 24 compiles | |
# my @a; | |
# @a[0] = @a; | |
# put @a.perl; | |
# # OUTPUT: «(my \Array_54878224 = [Array_54878224,])» | |
ok 71 - doc/Language/containers.pod6 chunk 25 compiles | |
# EVAL ‚my $i = 42; say $i.VAR.of; $i := "forty plus two"; say $i.VAR.of;‘; | |
# CATCH { default { say .^name, ' ', .Str } } | |
# # OUTPUT: «(Mu)X::Method::NotFound No such method 'of' for invocant of type 'Str'» | |
ok 72 - doc/Language/containers.pod6 chunk 26 compiles | |
# sub lucky(::T $type) { | |
# my T $c-value; # closure variable | |
# return Proxy.new( | |
# FETCH => method () { $c-value }, | |
# STORE => method (T $new-value) { | |
# X::OutOfRange.new(what => 'number', got => '13', range => '-Inf..12, 14..Inf').throw | |
# if $new-value == 13; | |
# $c-value = $new-value; | |
# } | |
# ); | |
# } | |
# my Int $a := lucky(Int); | |
# say $a = 12; # OUTPUT: «12» | |
# say $a = 'FOO'; # X::TypeCheck::Binding | |
# say $a = 13; # X::OutOfRange | |
# CATCH { default { say .^name, ': ', .Str } }; | |
ok 73 - doc/Language/containers.pod6 chunk 27 compiles | |
# say "Hello"; | |
# say "World"; | |
ok 74 - doc/Language/control.pod6 chunk 1 compiles | |
# say | |
# "Hello"; say "World"; | |
ok 75 - doc/Language/control.pod6 chunk 2 compiles | |
# { say "Hello"; say "World" } | |
ok 76 - doc/Language/control.pod6 chunk 3 compiles | |
# say 1; # OUTPUT: «1» | |
# { say 2; say 3 }; # OUTPUT: «23» | |
# say 4; # OUTPUT: «4» | |
ok 77 - doc/Language/control.pod6 chunk 4 compiles | |
# # All three of these lines can appear as a group, as is, in a program | |
# { 42.say } # OUTPUT: «42» | |
# { 43.say } # OUTPUT: «43» | |
# { 42.say }; { 43.say } # OUTPUT: «4243» | |
ok 78 - doc/Language/control.pod6 chunk 5 compiles | |
# False and do { 42.say }; | |
ok 79 - doc/Language/control.pod6 chunk 6 compiles | |
# # This says "(..1 ..2 ..3)" not "(..1 ...2 ....3)" | |
# my $f = "."; say do { $f ~= "." } X~ 1, 2, 3; | |
ok 80 - doc/Language/control.pod6 chunk 7 compiles | |
# 43.say if 42.say and 0; # says "42" but does not say "43" | |
# 43.say if 42.say and 1; # says "42" and then says "43" | |
# say "It is easier to read code when 'if's are kept on left of screen" | |
# if True; # says the above, because it is true | |
# { 43.say } if True; # says "43" as well | |
ok 81 - doc/Language/control.pod6 chunk 8 compiles | |
# my $d = 0; say (1, (if 0 { $d += 42; 2; }), 3, $d); # says "(1 3 0)" | |
# my $c = 0; say (1, (if 1 { $c += 42; 2; }), 3, $c); # says "(1 2 3 42)" | |
# say (1, (if 1 { 2, 2 }), 3); # does not slip, says "(1 (2 2) 3)" | |
ok 82 - doc/Language/control.pod6 chunk 9 compiles | |
# say (1, (42 if True) , 2); # says "(1 42 2)" | |
# say (1, (42 if False), 2); # says "(1 2)" | |
# say (1, 42 if False , 2); # says "(1 42)" because "if False, 2" is true | |
ok 83 - doc/Language/control.pod6 chunk 10 compiles | |
# $_ = 1; if 42 { $_.say } ; # says "1" | |
# $_ = 1; if 42 -> $_ { $_.say } ; # says "42" | |
# $_ = 1; if 42 -> $a { $_.say; $a.say } ; # says "1" then says "42" | |
# $_ = 1; if 42 { $_.say; $^a.say } ; # says "1" then says "42" | |
ok 84 - doc/Language/control.pod6 chunk 11 compiles | |
# if 0 { say "no" } elsif False { say "NO" } else { say "yes" } # says "yes" | |
# if 0 { say "no" } elsif True { say "YES" } else { say "yes" } # says "YES" | |
# if 0 { say "no" } elsif False { say "NO" } # does not say anything | |
# sub right { "Right!".say; True } | |
# sub wrong { "Wrong!".say; False } | |
# if wrong() { say "no" } elsif right() { say "yes" } else { say "maybe" } | |
# # The above says "Wrong!" then says "Right!" then says "yes" | |
ok 85 - doc/Language/control.pod6 chunk 12 compiles | |
# if 0 { say 0 } elsif 1 { say 1 } | |
# else { say "how?" } ; # says "1" | |
# if 0 { say 0 } | |
# elsif 1 { say 1 } else { say "how?" } ; # says "1" | |
# if 0 { say "no" } | |
# elsif False { say "NO" } | |
# else { say "yes" } ; # says "yes" | |
ok 86 - doc/Language/control.pod6 chunk 13 compiles | |
# my $d = 0; say (1, | |
# (if 0 { $d += 42; "two"; } elsif False { $d += 43; 2; }), | |
# 3, $d); # says "(1 3 0)" | |
# my $c = 0; say (1, | |
# (if 0 { $c += 42; "two"; } else { $c += 43; 2; }), | |
# 3, $c); # says "(1 2 3 43)" | |
ok 87 - doc/Language/control.pod6 chunk 14 compiles | |
# $_ = 1; if 0 { } else -> $a { "$_ $a".say } ; # says "1 0" | |
# $_ = 1; if False { } else -> $a { "$_ $a".say } ; # says "1 False" | |
# if False { } elsif 0 { } else -> $a { $a.say } ; # says "0" | |
ok 88 - doc/Language/control.pod6 chunk 15 compiles | |
# unless 42.say and 1 { 43.say } ; # says "42" but does not say "43" | |
# 43.say unless 42.say and 0; # says "42" and then says "43" | |
# 43.say unless 42.say and 1; # says "42" but does not say "43" | |
# $_ = 1; unless 0 { $_.say } ; # says "1" | |
# $_ = 1; unless 0 -> $_ { $_.say } ; # says "0" | |
# $_ = 1; unless False -> $a { $a.say } ; # says "False" | |
# my $c = 0; say (1, (unless 0 { $c += 42; 2; }), 3, $c); # says "(1 2 3 42)" | |
# my $d = 0; say (1, (unless 1 { $d += 42; 2; }), 3, $d); # says "(1 3 0)" | |
ok 89 - doc/Language/control.pod6 chunk 16 compiles | |
# with "abc".index("a") { .say } # prints 0 | |
ok 90 - doc/Language/control.pod6 chunk 17 compiles | |
# # The below code says "Found a at 0" | |
# my $s = "abc"; | |
# with $s.index("a") { say "Found a at $_" } | |
# orwith $s.index("b") { say "Found b at $_" } | |
# orwith $s.index("c") { say "Found c at $_" } | |
# else { say "Didn't find a, b or c" } | |
ok 91 - doc/Language/control.pod6 chunk 18 compiles | |
# # This says "Yes" | |
# if 0 { say "No" } orwith Nil { say "No" } orwith 0 { say "Yes" }; | |
ok 92 - doc/Language/control.pod6 chunk 19 compiles | |
# my $answer = Any; | |
# without $answer { warn "Got: $_" } | |
ok 93 - doc/Language/control.pod6 chunk 20 compiles | |
# my $answer = (Any, True).roll; | |
# say 42 with $answer; | |
# warn "undefined answer" without $answer; | |
ok 94 - doc/Language/control.pod6 chunk 21 compiles | |
# my @foo = 1..3; | |
# for @foo { $_.print } # prints each value contained in @foo | |
# for @foo { .print } # same thing, because .print implies a $_ argument | |
# for @foo { 42.print } # prints 42 as many times as @foo has elements | |
ok 95 - doc/Language/control.pod6 chunk 22 compiles | |
# my @foo = 1..3; | |
# for @foo -> $item { print $item } | |
# for @foo { print $^item } # same thing | |
ok 96 - doc/Language/control.pod6 chunk 23 compiles | |
# my @foo = 1..3; | |
# for @foo.kv -> $idx, $val { say "$idx: $val" } | |
# my %hash = <a b c> Z=> 1,2,3; | |
# for %hash.kv -> $key, $val { say "$key => $val" } | |
# for 1, 1.1, 2, 2.1 { say "$^x < $^y" } # says "1 < 1.1" then says "2 < 2.1" | |
ok 97 - doc/Language/control.pod6 chunk 24 compiles | |
# my @list = 1,2,3,4; | |
# for @list -> $a, $b = 'N/A', $c = 'N/A' { | |
# say "$a $b $c" | |
# } | |
# # OUTPUT: «1 2 34 N/A N/A» | |
ok 98 - doc/Language/control.pod6 chunk 25 compiles | |
# say „I $_ butterflies!“ for <♥ ♥ ♥>; | |
# # OUTPUT«I ♥ butterflies!I ♥ butterflies!I ♥ butterflies!» | |
ok 99 - doc/Language/control.pod6 chunk 26 compiles | |
# my @foo = 1..3; | |
# for @foo <-> $_ { $_++ } | |
ok 100 - doc/Language/control.pod6 chunk 27 compiles | |
# (for 1, 2, 3 { $_ * 2 }).say; # says "(2 4 6)" | |
# my @a = do for 1, 2, 3 { $_ * 2 }; @a.say; # says "[2 4 6]" | |
# my @b = (for 1, 2, 3 { $_ * 2 }); @a.say; # same thing | |
ok 101 - doc/Language/control.pod6 chunk 28 compiles | |
# my $a = gather { | |
# take 1; | |
# take 5; | |
# take 42; | |
# } | |
# say join ', ', $a; # OUTPUT: «1, 5, 42» | |
ok 102 - doc/Language/control.pod6 chunk 29 compiles | |
# my @vals = lazy gather { | |
# take 1; | |
# say "Produced a value"; | |
# take 2; | |
# } | |
# say @vals[0]; | |
# say 'between consumption of two values'; | |
# say @vals[1]; | |
# # OUTPUT: | |
# # 1 | |
# # between consumption of two values | |
# # Produced a value | |
# # 2 | |
ok 103 - doc/Language/control.pod6 chunk 30 compiles | |
# sub weird(@elems, :$direction = 'forward') { | |
# my %direction = ( | |
# forward => sub { take $_ for @elems }, | |
# backward => sub { take $_ for @elems.reverse }, | |
# random => sub { take $_ for @elems.pick(*) }, | |
# ); | |
# return gather %direction{$direction}(); | |
# } | |
# say weird(<a b c>, :direction<backward> ); # OUTPUT: «(c b a)» | |
ok 104 - doc/Language/control.pod6 chunk 31 compiles | |
# my $var = (Any, 21, any <answer lie>).pick; | |
# given $var { | |
# when 21 { say $_ * 2 } | |
# when 'lie' { .say } | |
# default { say 'default' } | |
# } | |
ok 105 - doc/Language/control.pod6 chunk 32 compiles | |
# given 42 { .say; .Numeric; } | |
ok 106 - doc/Language/control.pod6 chunk 33 compiles | |
# { .say; .Numeric; }(42) | |
ok 107 - doc/Language/control.pod6 chunk 34 compiles | |
# given 42 { | |
# "This says".say; | |
# $_ == 42 and ( default { "This says, too".say; 43; } ); | |
# "This never says".say; | |
# } | |
# # The above block evaluates to 43 | |
ok 108 - doc/Language/control.pod6 chunk 35 compiles | |
# for 42, 43, "foo", 44, "bar" { | |
# when Int { .say } | |
# when /:i ^Bar/ { .say } | |
# default { say "Not an Int or a Bar" } | |
# } | |
# # OUTPUT: «4243Not an Int or a Bar44Bar» | |
ok 109 - doc/Language/control.pod6 chunk 36 compiles | |
# given 42 { | |
# when Int { say "Int" } | |
# when 42 { say 42 } | |
# default { say "huh?" } | |
# } | |
# # OUTPUT: «Int» | |
ok 110 - doc/Language/control.pod6 chunk 37 compiles | |
# given 42 { | |
# when Int { | |
# when 42 { say 42 } | |
# say "Int" | |
# } | |
# default { say "huh?" } | |
# } | |
# # OUTPUT: «42» | |
ok 111 - doc/Language/control.pod6 chunk 38 compiles | |
# given 42 { | |
# when Int { say "Int"; proceed } | |
# when 42 { say 42 } | |
# when 40..* { say "greater than 40" } | |
# default { say "huh?" } | |
# } | |
# # OUTPUT: «Int» | |
# # OUTPUT: «42» | |
ok 112 - doc/Language/control.pod6 chunk 39 compiles | |
# given 42 { | |
# when Int { "Int".say; proceed } | |
# when 43 { 43.say } | |
# when 42 { 42.say } | |
# default { "got change for an existential answer?".say } | |
# } | |
# # OUTPUT: «Int» | |
# # OUTPUT: «42» | |
ok 113 - doc/Language/control.pod6 chunk 40 compiles | |
# given 42 { | |
# when Int { | |
# say "Int"; | |
# succeed "Found"; | |
# say "never this!"; | |
# } | |
# when 42 { say 42 } | |
# default { say "dunno?" } | |
# } | |
# # OUTPUT: «Int» | |
ok 114 - doc/Language/control.pod6 chunk 41 compiles | |
# given 42 { | |
# { say "This says" } when Int; | |
# "This says too".say; | |
# when * > 41 { | |
# { "And this says".say; proceed } when * > 41; | |
# "This never says".say; | |
# } | |
# "This also says".say; | |
# } | |
ok 115 - doc/Language/control.pod6 chunk 42 compiles | |
# .say given "foo"; | |
# # OUTPUT: «foo» | |
# printf "%s %02i.%02i.%i", | |
# <Mo Tu We Th Fr Sa Su>[.day-of-week - 1], | |
# .day, | |
# .month, | |
# .year | |
# given DateTime.now; | |
# # OUTPUT: «Sa 03.06.2016» | |
ok 116 - doc/Language/control.pod6 chunk 43 compiles | |
# loop (my $i = 0; $i < 10; $i++) { | |
# say $i; | |
# } | |
ok 117 - doc/Language/control.pod6 chunk 44 compiles | |
# (loop ( my $i = 0; $i++ < 3;) { $i * 2 }).say; # OUTPUT: «(2 4 6)» | |
# my @a = (loop ( my $j = 0; $j++ < 3;) { $j * 2 }); @a.say; # OUTPUT: «[2 4 6]» | |
# my @b = do loop ( my $k = 0; $k++ < 3;) { $k * 2 }; @b.say; # same thing | |
ok 118 - doc/Language/control.pod6 chunk 45 compiles | |
# sub heads-in-a-row { | |
# (eager loop (; 2.rand < 1;) { "heads".say }) | |
# } | |
ok 119 - doc/Language/control.pod6 chunk 46 compiles | |
# my $x = 1; | |
# while $x < 4 { | |
# print $x++; | |
# } | |
# print "\n"; | |
# # OUTPUT: «123» | |
ok 120 - doc/Language/control.pod6 chunk 47 compiles | |
# my $x = 1; | |
# until $x > 3 { | |
# print $x++; | |
# } | |
# print "\n"; | |
# # OUTPUT: «123» | |
ok 121 - doc/Language/control.pod6 chunk 48 compiles | |
# my $x = 42; | |
# $x-- while $x > 12 | |
ok 122 - doc/Language/control.pod6 chunk 49 compiles | |
# my $x = -42; | |
# repeat { | |
# $x++; | |
# } while $x < 5; | |
# $x.say; # OUTPUT: «5» | |
# repeat { | |
# $x++; | |
# } while $x < 5; | |
# $x.say; # OUTPUT: «6» | |
# repeat while $x < 10 { | |
# $x++; | |
# } | |
# $x.say; # OUTPUT: «10» | |
# repeat while $x < 10 { | |
# $x++; | |
# } | |
# $x.say; # OUTPUT: «11» | |
# repeat { | |
# $x++; | |
# } until $x >= 15; | |
# $x.say; # OUTPUT: «15» | |
# repeat { | |
# $x++; | |
# } until $x >= 15; | |
# $x.say; # OUTPUT: «16» | |
# repeat until $x >= 20 { | |
# $x++; | |
# } | |
# $x.say; # OUTPUT: «20» | |
# repeat until $x >= 20 { | |
# $x++; | |
# } | |
# $x.say; # OUTPUT: «21» | |
ok 123 - doc/Language/control.pod6 chunk 50 compiles | |
# sub s(){ my $a = 41; return $a }; | |
# say ++s(); | |
# CATCH { default { say .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Multi::NoMatch.new(dispatcher … | |
ok 124 - doc/Language/control.pod6 chunk 51 compiles | |
# sub s(){ my $a = 41; return-rw $a }; | |
# say ++s(); | |
# # OUTPUT: «42» | |
ok 125 - doc/Language/control.pod6 chunk 52 compiles | |
# sub f { fail "WELP!" }; | |
# say f; | |
# CATCH { default { say .^name, ': ', .Str } } | |
# # OUTPUT: «X::AdHoc: WELP!» | |
ok 126 - doc/Language/control.pod6 chunk 53 compiles | |
# my $guard = 3; | |
# loop { | |
# last if $guard-- <= 0; | |
# once { put 'once' }; | |
# print 'many' | |
# } # OUTPUT: «oncemanymanymany» | |
ok 127 - doc/Language/control.pod6 chunk 54 compiles | |
# ({ once 42.say } xx 3).map: {$_(), $_()}; # says 42 thrice | |
ok 128 - doc/Language/control.pod6 chunk 55 compiles | |
# quietly { warn 'kaput!' }; | |
# warn 'still kaput!'; | |
# # OUTPUT: «still kaput! [...]» | |
ok 129 - doc/Language/control.pod6 chunk 56 compiles | |
# OUTAHERE: while True { | |
# for 1,2,3 -> $n { | |
# last OUTAHERE if $n == 2; | |
# } | |
# } | |
ok 130 - doc/Language/control.pod6 chunk 57 compiles | |
# my @x = 1, 2, 3, 4, 5; | |
# for @x -> $x { | |
# next if $x == 3; | |
# print $x; | |
# } | |
ok 131 - doc/Language/control.pod6 chunk 58 compiles | |
# my @x = 1, 2, 3, 4, 5; | |
# for @x -> $x { | |
# last if $x == 3; | |
# print $x; | |
# } | |
ok 132 - doc/Language/control.pod6 chunk 59 compiles | |
# multi indent-say ( 'test' ) { | |
# samewith 'ABCD'; | |
# } | |
# multi indent-say ( Str $string ) { | |
# say "\t$string"; | |
# } | |
ok 133 - doc/Language/control.pod6 chunk 60 compiles | |
# die "oops, something went wrong"; | |
# # RESULT: «oops, something went wrong in block <unit> at my-script.p6:1» | |
ok 134 - doc/Language/exceptions.pod6 chunk 1 compiles | |
# die X::IO::DoesNotExist.new(:path("foo/bar"), :trying("zombie copy")) | |
# # RESULT: «Failed to find 'foo/bar' while trying to do '.zombie copy' | |
# # in block <unit> at my-script.p6:1» | |
ok 135 - doc/Language/exceptions.pod6 chunk 2 compiles | |
# die X::IO::DoesNotExist.new(:path("foo/bar"), :trying("zombie copy")); | |
# CATCH { | |
# when X::IO { say "some kind of IO exception was caught!" } | |
# } | |
# # RESULT: «some kind of IO exception was caught!» | |
ok 136 - doc/Language/exceptions.pod6 chunk 3 compiles | |
# CATCH { | |
# default { | |
# say .WHAT.perl, do given .backtrace[0] { .file, .line, .subname } | |
# } | |
# } | |
ok 137 - doc/Language/exceptions.pod6 chunk 4 compiles | |
# die "something went wrong ..."; | |
# CATCH { | |
# # will definitely catch all the exception | |
# default { .Str.say; } | |
# } | |
# say "This won't be said."; # but this line will be never reached since | |
# # the enclosing block will be exited immediately | |
# # OUTPUT: «something went wrong ...» | |
ok 138 - doc/Language/exceptions.pod6 chunk 5 compiles | |
# CATCH { | |
# CATCH { | |
# default { .Str.say; } | |
# } | |
# die "something went wrong ..."; | |
# } | |
# say "Hi! I am at the outer block!"; # OUTPUT: «Hi! I am at the outer block!» | |
ok 139 - doc/Language/exceptions.pod6 chunk 6 compiles | |
# class E is Exception { method message() { "Just stop already!" } } | |
# try { | |
# E.throw.new; # this will be local | |
# say "This won't be said."; | |
# } | |
# say "I'm alive!"; | |
# try { | |
# CATCH { | |
# when X::AdHoc { .Str.say; .resume } | |
# } | |
# die "No, I expect you to DIE Mr. Bond!"; | |
# say "I'm immortal."; | |
# E.new.throw; | |
# say "No, you don't!"; | |
# } | |
ok 140 - doc/Language/exceptions.pod6 chunk 7 compiles | |
# say try { +"99999" } // "oh no"; | |
# say try { +"hello" } // "oh no"; | |
# # OUTPUT: «99999oh no» | |
ok 141 - doc/Language/exceptions.pod6 chunk 8 compiles | |
# with try +"♥" { | |
# say "this is my number: $_" | |
# } else { | |
# say "not my number!" | |
# } | |
# # OUTPUT: «not my number!» | |
ok 142 - doc/Language/exceptions.pod6 chunk 9 compiles | |
# { | |
# X::AdHoc.new(:payload<foo>).throw; | |
# "OHAI".say; | |
# CATCH { | |
# when X::AdHoc { .resume } | |
# } | |
# } | |
# "OBAI".say; | |
# # OUTPUT: «OHAIOBAI» | |
ok 143 - doc/Language/exceptions.pod6 chunk 10 compiles | |
# { | |
# X::AdHoc.new(:payload<foo>).throw; | |
# "OHAI".say; | |
# CATCH { } | |
# } | |
# "OBAI".say; | |
# # RESULT: «foo | |
# # in block <unit> at my-script.p6:1» | |
ok 144 - doc/Language/exceptions.pod6 chunk 11 compiles | |
# { | |
# X::AdHoc.new(:payload<foo>).throw; | |
# "OHAI".say; | |
# CATCH { | |
# when X::AdHoc { } | |
# } | |
# } | |
# "OBAI".say; | |
# # OUTPUT: «OBAI» | |
ok 145 - doc/Language/exceptions.pod6 chunk 12 compiles | |
# CATCH { when X::AdHoc { .resume } } # this is step 2 | |
# die "We leave control after this."; # this is step 1 | |
# say "We have continued with control flow."; # this is step 3 | |
ok 146 - doc/Language/exceptions.pod6 chunk 13 compiles | |
# class X::WithoutLineNumber is X::AdHoc { | |
# multi method gist(X::WithoutLineNumber:D:) { | |
# $.payload | |
# } | |
# } | |
# die X::WithoutLineNumber.new(payload => "message") | |
# # prints "message\n" to $*ERR and exits, no backtrace | |
ok 147 - doc/Language/exceptions.pod6 chunk 14 compiles | |
# { return; CATCH { default { say .^name, ': ',.Str } } } | |
# # OUTPUT: «X::ControlFlow::Return: Attempt to return outside of any Routine» | |
# # was CX::Return | |
ok 148 - doc/Language/exceptions.pod6 chunk 15 compiles | |
# use experimental :macros; | |
ok 149 - doc/Language/experimental.pod6 chunk 1 compiles | |
# use experimental :collation; | |
ok 150 - doc/Language/experimental.pod6 chunk 2 compiles | |
# use experimental :collation; | |
# say 'a' unicmp 'Z'; # Less | |
# say 'a' cmp 'Z'; # More | |
ok 151 - doc/Language/experimental.pod6 chunk 3 compiles | |
# use experimental :collation; | |
# say ('a', 'Z').sort; # (Z a) | |
# say ('a', 'Z').collate; # (a Z) | |
# say <ä a o ö>.collate; # (a ä o ö) | |
# my %hash = 'aa' => 'value', 'Za' => 'second'; | |
# say %hash.collate; # (aa => value Za => second); | |
ok 152 - doc/Language/experimental.pod6 chunk 4 compiles | |
# use experimental :collation; | |
# $*COLLATION.set(:quaternary(False), :tertiary(False)); | |
# say 'a' coll 'A'; # Same | |
ok 153 - doc/Language/experimental.pod6 chunk 5 compiles | |
# my $foo="bar"; | |
# dd $foo; # OUTPUT: «Str $foo = "bar"» | |
# say :$foo.perl; # OUTPUT: «:foo("bar")» | |
# say :$foo.gist; # OUTPUT: «foo => bar» | |
ok 154 - doc/Language/faq.pod6 chunk 1 compiles | |
# my $foo; | |
# say $foo; # OUTPUT: «(Any)» - note the parentheses indicate type object | |
# say $foo.^name; # OUTPUT: «Any» | |
ok 155 - doc/Language/faq.pod6 chunk 2 compiles | |
# say 1.defined; # OUTPUT: «True» | |
# say (Any).defined; # OUTPUT: «False» | |
ok 156 - doc/Language/faq.pod6 chunk 3 compiles | |
# say so 1|2 == 2; # OUTPUT: «True» | |
ok 157 - doc/Language/faq.pod6 chunk 4 compiles | |
# my Int $x = 42; | |
ok 158 - doc/Language/faq.pod6 chunk 5 compiles | |
# sub discard-random-number( --> 42 ) { rand } | |
# say discard-random-number; | |
# # OUTPUT: «42» | |
ok 159 - doc/Language/faq.pod6 chunk 6 compiles | |
# sub eigenstates(Mu $j) { | |
# my @states; | |
# -> Any $s { @states.push: $s }.($j); | |
# @states; | |
# } | |
# say eigenstates(1|2|3).join(', '); | |
# # prints 1, 2, 3 or a permutation thereof | |
ok 160 - doc/Language/faq.pod6 chunk 7 compiles | |
# my @a = 1, 2, 3; | |
# say @a; # OUTPUT: «[1 2 3]» | |
# say @a.WHAT; # OUTPUT: «(Array)» | |
# my $scalar = @a; | |
# say $scalar; # OUTPUT: «[1 2 3]» | |
# say $scalar.WHAT; # OUTPUT: «(Array)» | |
ok 161 - doc/Language/faq.pod6 chunk 8 compiles | |
# my $foo = "abc"; | |
# say "{$foo}<html-tag>"; | |
ok 162 - doc/Language/faq.pod6 chunk 9 compiles | |
# class A { | |
# has $!x; | |
# method show-x { | |
# say $!x; | |
# } | |
# } | |
# A.new(x => 5).show-x; | |
ok 163 - doc/Language/faq.pod6 chunk 10 compiles | |
# class B { | |
# has $!x; | |
# submethod BUILD(:$!x) { } | |
# method show-x { | |
# say $!x; | |
# } | |
# } | |
# B.new(x => 5).show-x; | |
ok 164 - doc/Language/faq.pod6 chunk 11 compiles | |
# my Date $x; # $x now contains the Date type object | |
# print $x; # empty string plus warning | |
# say $x; # OUTPUT: «(Date)» | |
ok 165 - doc/Language/faq.pod6 chunk 12 compiles | |
# (not (not Nil)) | |
ok 166 - doc/Language/faq.pod6 chunk 13 compiles | |
# sub my-func { say "Look ma, no args!" } | |
# my-func; | |
ok 167 - doc/Language/functions.pod6 chunk 1 compiles | |
# sub exclaim ($phrase) { | |
# say $phrase ~ "!!!!" | |
# } | |
# exclaim "Howdy, World"; | |
ok 168 - doc/Language/functions.pod6 chunk 2 compiles | |
# sub escape($str) { | |
# # Puts a slash before non-alphanumeric characters | |
# S:g[<-alpha -digit>] = "\\$/" given $str | |
# } | |
# say escape 'foo#bar?'; # foo\#bar\? | |
# { | |
# sub escape($str) { | |
# # Writes each non-alphanumeric character in its hexadecimal escape | |
# S:g[<-alpha -digit>] = "\\x[{ $/.ord.base(16) }]" given $str | |
# } | |
# say escape 'foo#bar?' # foo\x[23]bar\x[3F] | |
# } | |
# # Back to original escape function | |
# say escape 'foo#bar?'; # foo\#bar\? | |
ok 169 - doc/Language/functions.pod6 chunk 3 compiles | |
# say sub ($a, $b) { $a ** 2 + $b ** 2 }(3, 4) # OUTPUT: «25» | |
ok 170 - doc/Language/functions.pod6 chunk 4 compiles | |
# for 1, 2, 3, 4 -> $a, $b { | |
# say $a ~ $b; | |
# } | |
# # OUTPUT: «1234» | |
ok 171 - doc/Language/functions.pod6 chunk 5 compiles | |
# say { $^a ** 2 + $^b ** 2}(3, 4) # OUTPUT: «25» | |
ok 172 - doc/Language/functions.pod6 chunk 6 compiles | |
# sub format(Str $s) { ... } | |
# -> $a, $b { ... } | |
ok 173 - doc/Language/functions.pod6 chunk 7 compiles | |
# sub s { dd @_, %_ }; | |
# dd &s.signature # OUTPUT: «:(*@_, *%_)» | |
ok 174 - doc/Language/functions.pod6 chunk 8 compiles | |
# sub f(&c){ c() * 2 }; # call the function reference c with empty parameter list | |
# sub g($p){ $p - 2 }; | |
# say(g(42), 45); # pass only 42 to g() | |
ok 175 - doc/Language/functions.pod6 chunk 9 compiles | |
# sub f(|c){}; | |
# f :named(35); # A named argument (in "adverb" form.) | |
# f named => 35; # Also a named argument. | |
# f :35named; # A named argument using abbreviated adverb form | |
# f 'named' => 35; # Not a named argument, a Pair in a positional argument | |
# my \c = <a b c>.Capture; | |
# f |c; # Merge the contents of Capture $c as if they were supplied | |
ok 176 - doc/Language/functions.pod6 chunk 10 compiles | |
# sub f(|c){}; | |
# f :dest</tmp/foo> :src</tmp/bar> :lines(512); | |
# f :32x :50y :110z; # This flavor of "adverb" works, too | |
# f :a:b:c; # The spaces are also optional. | |
ok 177 - doc/Language/functions.pod6 chunk 11 compiles | |
# sub a { 42 }; | |
# sub b { say a }; | |
# b; | |
# # OUTPUT: «42» | |
ok 178 - doc/Language/functions.pod6 chunk 12 compiles | |
# sub a { 42, 'answer' }; | |
# put a.perl; | |
# # OUTPUT: «(42, "answer")» | |
# my ($n, $s) = a; | |
# put [$s, $n]; | |
# # OUTPUT: «answer 42» | |
# sub b { <a b c>.Capture }; | |
# put b.perl; | |
# # OUTPUT: «\("a", "b", "c")» | |
ok 179 - doc/Language/functions.pod6 chunk 13 compiles | |
# sub foo() returns Int { "a"; }; foo; # Type check fails | |
ok 180 - doc/Language/functions.pod6 chunk 14 compiles | |
# sub foo() returns Int { fail }; foo; # Failure returned | |
# sub bar() returns Int { return }; bar; # Nil returned | |
ok 181 - doc/Language/functions.pod6 chunk 15 compiles | |
# multi congratulate($name) { | |
# say "Happy birthday, $name"; | |
# } | |
# multi congratulate($name, $age) { | |
# say "Happy {$age}th birthday, $name"; | |
# } | |
# congratulate 'Larry'; # OUTPUT: «Happy birthday, Larry» | |
# congratulate 'Bob', 45; # OUTPUT: «Happy 45th birthday, Bob» | |
ok 182 - doc/Language/functions.pod6 chunk 16 compiles | |
# multi as-json(Bool $d) { $d ?? 'true' !! 'false'; } | |
# multi as-json(Real $d) { ~$d } | |
# multi as-json(@d) { sprintf '[%s]', @d.map(&as-json).join(', ') } | |
# say as-json([True, 42]); # OUTPUT: «[true, 42]» | |
ok 183 - doc/Language/functions.pod6 chunk 17 compiles | |
# class Congrats { | |
# multi method congratulate($reason, $name) { | |
# say "Hooray for your $reason, $name"; | |
# } | |
# } | |
# role BirthdayCongrats { | |
# multi method congratulate('birthday', $name) { | |
# say "Happy birthday, $name"; | |
# } | |
# multi method congratulate('birthday', $name, $age) { | |
# say "Happy {$age}th birthday, $name"; | |
# } | |
# } | |
# my $congrats = Congrats.new does BirthdayCongrats; | |
# $congrats.congratulate('promotion','Cindy'); # OUTPUT: «Hooray for your promotion, Cindy» | |
# $congrats.congratulate('birthday','Bob'); # OUTPUT: «Happy birthday, Bob» | |
ok 184 - doc/Language/functions.pod6 chunk 18 compiles | |
# proto congratulate(Str $reason, Str $name, |) {*} | |
# multi congratulate($reason, $name) { | |
# say "Hooray for your $reason, $name"; | |
# } | |
# multi congratulate($reason, $name, Int $rank) { | |
# say "Hooray for your $reason, $name -- got rank $rank!"; | |
# } | |
ok 185 - doc/Language/functions.pod6 chunk 19 compiles | |
# # attempts to notify someone -- False if unsuccessful | |
# proto notify(Str $user,Str $msg) { | |
# my \hour = DateTime.now.hour; | |
# if hour > 8 or hour < 22 { | |
# return {*}; | |
# } else { | |
# # we can't notify someone when they might be sleeping | |
# return False; | |
# } | |
# } | |
ok 186 - doc/Language/functions.pod6 chunk 20 compiles | |
# sub grab(+@a) { "grab $_".say for @a } | |
ok 187 - doc/Language/functions.pod6 chunk 21 compiles | |
# multi sub grab(**@a) { "grab $_".say for @a } | |
# multi sub grab(\a) { | |
# a ~~ Iterable and a.VAR !~~ Scalar ?? nextwith(|a) !! nextwith(a,) | |
# } | |
ok 188 - doc/Language/functions.pod6 chunk 22 compiles | |
# my $square = sub (Numeric $x) { $x * $x } | |
# # and then use it: | |
# say $square(6); # OUTPUT: «36» | |
ok 189 - doc/Language/functions.pod6 chunk 23 compiles | |
# sub square($x) { $x * $x }; | |
# # get hold of a reference to the function: | |
# my $func = &square | |
ok 190 - doc/Language/functions.pod6 chunk 24 compiles | |
# sub square($x) { $x * $x }; | |
# my @squared = map &square, 1..5; | |
# say join ', ', @squared; # OUTPUT: «1, 4, 9, 16, 25» | |
ok 191 - doc/Language/functions.pod6 chunk 25 compiles | |
# sub plus { $^a + $^b }; | |
# say 21 [&plus] 21; | |
# # OUTPUT: «42» | |
ok 192 - doc/Language/functions.pod6 chunk 26 compiles | |
# sub generate-sub($x) { | |
# my $y = 2 * $x; | |
# return sub { say $y }; | |
# # ^^^^^^^^^^^^^^ inner sub, uses $y | |
# } | |
# my $generated = generate-sub(21); | |
# $generated(); # OUTPUT: «42» | |
ok 193 - doc/Language/functions.pod6 chunk 27 compiles | |
# my $multiply-by = 5; | |
# say join ', ', map { $_ * $multiply-by }, 1..5; # OUTPUT: «5, 10, 15, 20, 25» | |
ok 194 - doc/Language/functions.pod6 chunk 28 compiles | |
# my $keywords = set <if for unless while>; | |
# sub has-keyword(*@words) { | |
# for @words -> $word { | |
# return True if $word (elem) $keywords; | |
# } | |
# False; | |
# } | |
# say has-keyword 'not', 'one', 'here'; # OUTPUT: «False» | |
# say has-keyword 'but', 'here', 'for'; # OUTPUT: «True» | |
ok 195 - doc/Language/functions.pod6 chunk 29 compiles | |
# sub testee(Int $i, Str $s){ | |
# rand.Rat * $i ~ $s; | |
# } | |
# sub wrap-to-debug(&c){ | |
# say "wrapping {&c.name} with arguments {&c.signature.perl}"; | |
# &c.wrap: sub (|args){ | |
# note "calling {&c.name} with {args.gist}"; | |
# my \ret-val := callwith(|args); | |
# note "returned from {&c.name} with return value {ret-val.perl}"; | |
# ret-val | |
# } | |
# } | |
# my $testee-handler = wrap-to-debug(&testee); | |
# # OUTPUT: «wrapping testee with arguments :(Int $i, Str $s)» | |
# say testee(10, "ten"); | |
# # OUTPUT: «calling testee with \(10, "ten")returned from testee with return value "6.151190ten"6.151190ten» | |
# &testee.unwrap($testee-handler); | |
# say testee(10, "ten"); | |
# # OUTPUT: «6.151190ten» | |
ok 196 - doc/Language/functions.pod6 chunk 30 compiles | |
# # adding a multi candidate to an existing operator: | |
# multi infix:<+>(Int $x, "same") { 2 * $x }; | |
# say 21 + "same"; # OUTPUT: «42» | |
# # defining a new operator | |
# sub postfix:<!>(Int $x where { $x >= 0 }) { [*] 1..$x }; | |
# say 6!; # OUTPUT: «720» | |
ok 197 - doc/Language/functions.pod6 chunk 31 compiles | |
# sub postfix:<!>(Int $x where { $x >= 0 }) { | |
# $x == 0 ?? 1 !! $x * ($x - 1)! | |
# } | |
# say 6!; # OUTPUT: «720» | |
ok 198 - doc/Language/functions.pod6 chunk 32 compiles | |
# sub circumfix:<START END>(*@elems) { | |
# "start", @elems, "end" | |
# } | |
# say START 'a', 'b', 'c' END; # OUTPUT: «start a b c end» | |
ok 199 - doc/Language/functions.pod6 chunk 33 compiles | |
# sub postcircumfix:<!! !!>($left, $inside) { | |
# "$left -> ( $inside )" | |
# } | |
# say 42!! 1 !!; # OUTPUT: «42 -> ( 1 )» | |
ok 200 - doc/Language/functions.pod6 chunk 34 compiles | |
# my &infix:<ieq> = -> |l { [eq] l>>.fc }; | |
# say "abc" ieq "Abc"; | |
# # OUTPUT: «True» | |
ok 201 - doc/Language/functions.pod6 chunk 35 compiles | |
# sub infix:<!!>($a, $b) is tighter(&infix:<+>) { | |
# 2 * ($a + $b) | |
# } | |
# say 1 + 2 * 3 !! 4; # OUTPUT: «21» | |
ok 202 - doc/Language/functions.pod6 chunk 36 compiles | |
# sub infix:<!!>($a, $b) is looser(&infix:<*>) { ... } | |
ok 203 - doc/Language/functions.pod6 chunk 37 compiles | |
# 1 + 2 + 3 | |
ok 204 - doc/Language/functions.pod6 chunk 38 compiles | |
# (1 + 2) + 3 # left associative | |
ok 205 - doc/Language/functions.pod6 chunk 39 compiles | |
# 1 + (2 + 3) # right associative | |
ok 206 - doc/Language/functions.pod6 chunk 40 compiles | |
# say 2 ** (2 ** 3); # OUTPUT: «256» | |
# say (2 ** 2) ** 3; # OUTPUT: «64» | |
ok 207 - doc/Language/functions.pod6 chunk 41 compiles | |
# sub infix:<§>(*@a) is assoc<list> { | |
# '(' ~ @a.join('|') ~ ')'; | |
# } | |
# say 1 § 2 § 3; # OUTPUT: «(1|2|3)» | |
ok 208 - doc/Language/functions.pod6 chunk 42 compiles | |
# multi sub trait_mod:<is>(Routine $r, :$doubles!) { | |
# $r.wrap({ | |
# 2 * callsame; | |
# }); | |
# } | |
# sub square($x) is doubles { | |
# $x * $x; | |
# } | |
# say square 3; # OUTPUT: «18» | |
ok 209 - doc/Language/functions.pod6 chunk 43 compiles | |
# multi a(Any $x) { | |
# say "Any $x"; | |
# return 5; | |
# } | |
# multi a(Int $x) { | |
# say "Int $x"; | |
# my $res = callwith($x + 1); | |
# say "Back in Int with $res"; | |
# } | |
# a 1; # OUTPUT: «Int 1Any 2Back in Int with 5» | |
ok 210 - doc/Language/functions.pod6 chunk 44 compiles | |
# multi a(Any $x) { | |
# say "Any $x"; | |
# return 5; | |
# } | |
# multi a(Int $x) { | |
# say "Int $x"; | |
# my $res = callsame; | |
# say "Back in Int with $res"; | |
# } | |
# a 1; # OUTPUT: «Int 1Any 1Back in Int with 5» | |
ok 211 - doc/Language/functions.pod6 chunk 45 compiles | |
# multi a(Any $x) { | |
# say "Any $x"; | |
# return 5; | |
# } | |
# multi a(Int $x) { | |
# say "Int $x"; | |
# nextsame; | |
# say "back in a"; # never executed, because 'nextsame' doesn't return | |
# } | |
# a 1; # OUTPUT: «Int 1Any 1» | |
ok 212 - doc/Language/functions.pod6 chunk 46 compiles | |
# # enable wrapping: | |
# use soft; | |
# # function to be wrapped: | |
# sub square-root($x) { $x.sqrt } | |
# &square-root.wrap(sub ($num) { | |
# nextsame if $num >= 0; | |
# 1i * callwith(abs($num)); | |
# }); | |
# say square-root(4); # OUTPUT: «2» | |
# say square-root(-4); # OUTPUT: «0+2i» | |
ok 213 - doc/Language/functions.pod6 chunk 47 compiles | |
# class LoggedVersion is Version { | |
# method new(|c) { | |
# note "New version object created with arguments " ~ c.perl; | |
# nextsame; | |
# } | |
# } | |
# say LoggedVersion.new('1.0.2'); | |
ok 214 - doc/Language/functions.pod6 chunk 48 compiles | |
# sub power-it($x) { $x * $x } | |
# sub run-it-again-and-again($x) { | |
# my &again = nextcallee; | |
# again again $x; | |
# } | |
# &power-it.wrap(&run-it-again-and-again); | |
# say power-it(5); # OUTPUT: «625» | |
ok 215 - doc/Language/functions.pod6 chunk 49 compiles | |
# my \IOL = Lock.new; | |
# &say.wrap( -> |c { | |
# my &wrappee = nextcallee; | |
# IOL.protect: { &wrappee(|c) } | |
# }); | |
# for ^100 { say "oops" } | |
ok 216 - doc/Language/functions.pod6 chunk 50 compiles | |
# sub MAIN( Int :$length = 24, | |
# :file($data) where { .IO.f // die "file not found in $*CWD" } = 'file.dat', | |
# Bool :$verbose ) | |
# { | |
# say $length if $length.defined; | |
# say $data if $data.defined; | |
# say 'Verbosity ', ($verbose ?? 'on' !! 'off'); | |
# exit 1; | |
# } | |
ok 217 - doc/Language/functions.pod6 chunk 51 compiles | |
# sub MAIN(Int $i){ say $i == 42 ?? 'answer' !! 'dunno' } | |
# sub USAGE(){ | |
# print Q:c:to/EOH/; | |
# Usage: {$*PROGRAM-NAME} [number] | |
# Prints the answer or 'dunno'. | |
# EOH | |
# } | |
ok 218 - doc/Language/functions.pod6 chunk 52 compiles | |
# role Canine { | |
# method bark { ... } # the ... indicates a stub | |
# } | |
# class Dog does Canine { | |
# method bark { say "woof" } # *MUST* be implemented by class | |
# } | |
ok 219 - doc/Language/glossary.pod6 chunk 1 compiles | |
# q:w"foo bar"; # ":w" is a Quotelike form modifier adverb | |
# m:g/a|b|c/; # ":g" is also | |
ok 220 - doc/Language/glossary.pod6 chunk 2 compiles | |
# :a(4) # Same as "a" => 4 | |
ok 221 - doc/Language/glossary.pod6 chunk 3 compiles | |
# :20seconds # same as seconds => 20 | |
ok 222 - doc/Language/glossary.pod6 chunk 4 compiles | |
# say <42>.WHAT; # OUTPUT: «(IntStr)» | |
# say <42.1e0>.WHAT; # OUTPUT: «(NumStr)» | |
# say <42.1>.WHAT; # OUTPUT: «(RatStr)» | |
ok 223 - doc/Language/glossary.pod6 chunk 5 compiles | |
# say <42/1>.WHAT; # OUTPUT: «(Rat)» | |
# say <42+0i>.WHAT; # OUTPUT: «(Complex)» | |
# say < 42+0i >.WHAT;# OUTPUT: «(ComplexStr)» | |
# say < 42/1 >.WHAT; # OUTPUT: «(RatStr)» | |
ok 224 - doc/Language/glossary.pod6 chunk 6 compiles | |
# # named subroutine | |
# sub double($x) { 2 * $x }; | |
# # anonymous subroutine, stored in a named scalar | |
# my $double = sub ($x) { 2 * $x }; | |
ok 225 - doc/Language/glossary.pod6 chunk 7 compiles | |
# sub f($x) { 2 * $x }; | |
# say f(1|2|3) == 4; # OUTPUT: «any(False, True, False)» | |
ok 226 - doc/Language/glossary.pod6 chunk 8 compiles | |
# :a(4) # Same as "a" => 4, same as Pair.new("a", 4) | |
# :a<4> # Same as "a" => "4", same as Pair.new("a", "4") | |
ok 227 - doc/Language/glossary.pod6 chunk 9 compiles | |
# :a # Same as :a(True) | |
# :!a # Same as :a(False) | |
ok 228 - doc/Language/glossary.pod6 chunk 10 compiles | |
# :a(4):c:!d:c # Same as a => 4, c => True, d => False, c => True | |
ok 229 - doc/Language/glossary.pod6 chunk 11 compiles | |
# my Str $str = "hello"; ## this is with builtin types, e.g. Str | |
# if defined($str) { | |
# say "Oh, yeah. I'm defined."; | |
# } | |
# else { | |
# say "No. Something off? "; | |
# } | |
# ## if you wanted objects... | |
# class A { | |
# # nothing here for now. | |
# } | |
# my $an_instance = A.new; | |
# say $an_instance.defined.perl;# defined($an_instance) works too. | |
ok 230 - doc/Language/glossary.pod6 chunk 12 compiles | |
# my $x = 2; # the 2 is a literal | |
# say $x; # $x is not a literal, but a variable | |
# my $s = "Foo"; # the "Foo" is a literal, the $s is a variable | |
ok 231 - doc/Language/glossary.pod6 chunk 13 compiles | |
# use v6.c; # mainline | |
# sub f { | |
# # not in mainline, in sub f | |
# } | |
# f(); # in mainline again | |
ok 232 - doc/Language/glossary.pod6 chunk 14 compiles | |
# <O('%conditional, :reducecheck<ternary>, :pasttype<if>')> | |
ok 233 - doc/Language/glossary.pod6 chunk 15 compiles | |
# sub foo($bar) { say $bar } # $bar is a parameter | |
# foo(42); # 42 is an argument | |
ok 234 - doc/Language/glossary.pod6 chunk 16 compiles | |
# grammar My::Gram { | |
# token TOP { <thingy> .* } | |
# token thingy { 'clever_text_keyword' } | |
# } | |
ok 235 - doc/Language/grammar_tutorial.pod6 chunk 1 compiles | |
# grammar REST { | |
# token subject { \w+ } | |
# token command { \w+ } | |
# token data { .* } | |
# } | |
ok 236 - doc/Language/grammar_tutorial.pod6 chunk 2 compiles | |
# grammar REST { | |
# token TOP { '/' <subject> '/' <command> '/' <data> } | |
# token subject { \w+ } | |
# token command { \w+ } | |
# token data { .* } | |
# } | |
ok 237 - doc/Language/grammar_tutorial.pod6 chunk 3 compiles | |
# grammar REST { | |
# token TOP { '/' <subject> '/' <command> [ '/' <data> ]? } | |
# token subject { \w+ } | |
# token command { \w+ } | |
# token data { .* } | |
# } | |
# my $m = REST.parse('/product/create'); | |
# say $m<subject>, $m<command>; | |
# # OUTPUT: «「product」「create」» | |
ok 238 - doc/Language/grammar_tutorial.pod6 chunk 4 compiles | |
# grammar REST { | |
# token TOP { <slash><subject><slash><command>[<slash><data>]? } | |
# token subject { \w+ } | |
# token command { \w+ } | |
# token data { .* } | |
# token slash { \s* '/' \s* } | |
# } | |
# my $m = REST.parse('/ product / update /7 /notify'); | |
# say $m; | |
# # OUTPUT: «「/ product / update /7 /notify」 | |
# # slash => 「/ 」 | |
# # subject => 「product」 | |
# # slash => 「 / 」 | |
# # command => 「update」 | |
# # slash => 「 /」 | |
# # data => 「7 /notify」» | |
ok 239 - doc/Language/grammar_tutorial.pod6 chunk 5 compiles | |
# proto token command {*} | |
# token command:sym<create> { <sym> } | |
# token command:sym<retrieve> { <sym> } | |
# token command:sym<update> { <sym> } | |
# token command:sym<delete> { <sym> } | |
ok 240 - doc/Language/grammar_tutorial.pod6 chunk 6 compiles | |
# grammar REST | |
# { | |
# token TOP { <slash><subject><slash><command>[<slash><data>]? } | |
# proto token command {*} | |
# token command:sym<create> { <sym> } | |
# token command:sym<retrieve> { <sym> } | |
# token command:sym<update> { <sym> } | |
# token command:sym<delete> { <sym> } | |
# token subject { \w+ } | |
# token data { .* } | |
# token slash { \s* '/' \s* } | |
# } | |
ok 241 - doc/Language/grammar_tutorial.pod6 chunk 7 compiles | |
# grammar REST | |
# { | |
# token TOP { <slash><subject><slash><command>[<slash><data>]? } | |
# proto token command {*} | |
# token command:sym<create> { <sym> } | |
# token command:sym<retrieve> { <sym> } | |
# token command:sym<update> { <sym> } | |
# token command:sym<delete> { <sym> } | |
# token subject { \w+ } | |
# token data { .* } | |
# token slash { \s* '/' \s* } | |
# } | |
ok 242 - doc/Language/grammar_tutorial.pod6 chunk 8 compiles | |
# class REST-actions | |
# { | |
# method data($/) { $/.split('/') } | |
# } | |
ok 243 - doc/Language/grammar_tutorial.pod6 chunk 9 compiles | |
# class REST-actions | |
# { | |
# method data($/) { make $/.split('/') } | |
# } | |
ok 244 - doc/Language/grammar_tutorial.pod6 chunk 10 compiles | |
# class REST-actions | |
# { | |
# method TOP ($/) { | |
# make { subject => $<subject>.Str, | |
# command => $<command>.Str, | |
# data => $<data>.made } | |
# } | |
# method data($/) { make $/.split('/') } | |
# } | |
ok 245 - doc/Language/grammar_tutorial.pod6 chunk 11 compiles | |
# class REST-actions | |
# { | |
# method TOP ($/) { | |
# make { subject => $<subject>.Str, | |
# command => $<command>.Str, | |
# data => $<data>.made, | |
# subject-id => $<data>.made[0] } | |
# } | |
# method data($/) { make $/.split('/') } | |
# } | |
ok 246 - doc/Language/grammar_tutorial.pod6 chunk 12 compiles | |
# grammar REST | |
# { | |
# token TOP { <slash><subject><slash><command>[<slash><data>]? } | |
# proto token command {*} | |
# token command:sym<create> { <sym> } | |
# token command:sym<retrieve> { <sym> } | |
# token command:sym<update> { <sym> } | |
# token command:sym<delete> { <sym> } | |
# token subject { \w+ } | |
# token data { .* } | |
# token slash { \s* '/' \s* } | |
# } | |
# class REST-actions | |
# { | |
# method TOP ($/) { | |
# make { subject => $<subject>.Str, | |
# command => $<command>.Str, | |
# data => $<data>.made, | |
# subject-id => $<data>.made[0] } | |
# } | |
# method data($/) { make $/.split('/') } | |
# } | |
ok 247 - doc/Language/grammar_tutorial.pod6 chunk 13 compiles | |
# my regex number { \d+ [ \. \d+ ]? } | |
ok 248 - doc/Language/grammars.pod6 chunk 1 compiles | |
# my regex works-but-slow { .+ q } | |
# my token fails-but-fast { .+ q } | |
# my $s = 'Tokens won\'t backtrack, which makes them fail quicker!'; | |
# say so $s ~~ &works-but-slow; # OUTPUT: «True» | |
# say so $s ~~ &fails-but-fast; # OUTPUT: «False», the entire string get taken by the .+ | |
ok 249 - doc/Language/grammars.pod6 chunk 2 compiles | |
# my token non-space-y { 'once' 'upon' 'a' 'time' } | |
# my rule space-y { 'once' 'upon' 'a' 'time' } | |
# say so 'onceuponatime' ~~ &non-space-y; # OUTPUT: «True» | |
# say so 'once upon a time' ~~ &non-space-y; # OUTPUT: «False» | |
# say so 'onceuponatime' ~~ &space-y; # OUTPUT: «False» | |
# say so 'once upon a time' ~~ &space-y; # OUTPUT: «True» | |
ok 250 - doc/Language/grammars.pod6 chunk 3 compiles | |
# grammar Calculator { | |
# token TOP { [ <add> | <sub> ] } | |
# rule add { <num> '+' <num> } | |
# rule sub { <num> '-' <num> } | |
# token num { \d+ } | |
# } | |
# class Calculations { | |
# method TOP ($/) { make $<add> ?? $<add>.made !! $<sub>.made; } | |
# method add ($/) { make [+] $<num>; } | |
# method sub ($/) { make [-] $<num>; } | |
# } | |
# say Calculator.parse('2 + 3', actions => Calculations).made; | |
# # OUTPUT: «5» | |
ok 251 - doc/Language/grammars.pod6 chunk 4 compiles | |
# grammar Calculator { | |
# token TOP { <calc-op> } | |
# proto rule calc-op {*} | |
# rule calc-op:sym<add> { <num> '+' <num> } | |
# rule calc-op:sym<sub> { <num> '-' <num> } | |
# token num { \d+ } | |
# } | |
# class Calculations { | |
# method TOP ($/) { make $<calc-op>.made; } | |
# method calc-op:sym<add> ($/) { make [+] $<num>; } | |
# method calc-op:sym<sub> ($/) { make [-] $<num>; } | |
# } | |
# say Calculator.parse('2 + 3', actions => Calculations).made; | |
# # OUTPUT: «5» | |
ok 252 - doc/Language/grammars.pod6 chunk 5 compiles | |
# grammar Foo { | |
# token TOP { \d+ } | |
# } | |
ok 253 - doc/Language/grammars.pod6 chunk 6 compiles | |
# rule entry { <key> ’=’ <value> } | |
ok 254 - doc/Language/grammars.pod6 chunk 7 compiles | |
# token entry { <key> <.ws> ’=’ <.ws> <value> <.ws> } # . = non-capturing | |
ok 255 - doc/Language/grammars.pod6 chunk 8 compiles | |
# # First <.ws> matches word boundary at the start of the line | |
# # and second <.ws> matches the whitespace between 'b' and 'c' | |
# say 'ab c' ~~ /<.ws> ab <.ws> c /; # OUTPUT: «「ab c」» | |
# # Failed match: there is neither any whitespace nor a word | |
# # boundary between 'a' and 'b' | |
# say 'ab' ~~ /. <.ws> b/; # OUTPUT: «Nil» | |
# # Successful match: there is a word boundary between ')' and 'b' | |
# say ')b' ~~ /. <.ws> b/; # OUTPUT: «「)b」» | |
ok 256 - doc/Language/grammars.pod6 chunk 9 compiles | |
# grammar Foo { | |
# rule TOP { \d \d } | |
# }.parse: "4 \n\n 5"; # Succeeds | |
# grammar Bar { | |
# rule TOP { \d \d } | |
# token ws { \h* } | |
# }.parse: "4 \n\n 5"; # Fails | |
ok 257 - doc/Language/grammars.pod6 chunk 10 compiles | |
# grammar Digifier { | |
# rule TOP { | |
# [ <.succ> <digit>+ ]+ | |
# } | |
# token succ { <?> } | |
# token digit { <[0..9]> } | |
# } | |
# class Devanagari { | |
# has @!numbers; | |
# method digit ($/) { @!numbers[*-1] ~= $/.ord.&[+](2358).chr } | |
# method succ ($) { @!numbers.push: '' } | |
# method TOP ($/) { make @!numbers[^(*-1)] } | |
# } | |
# say Digifier.parse('255 435 777', actions => Devanagari.new).made; | |
# # OUTPUT: «(२५५ ४३५ ७७७)» | |
ok 258 - doc/Language/grammars.pod6 chunk 11 compiles | |
# grammar DigitMatcher { | |
# method TOP (:$full-unicode) { | |
# $full-unicode ?? self.num-full !! self.num-basic; | |
# } | |
# token num-full { \d+ } | |
# token num-basic { <[0..9]>+ } | |
# } | |
ok 259 - doc/Language/grammars.pod6 chunk 12 compiles | |
# use v6.c; | |
# grammar TestGrammar { | |
# token TOP { \d+ } | |
# } | |
# class TestActions { | |
# method TOP($/) { | |
# $/.make(2 + $/); | |
# } | |
# } | |
# my $actions = TestActions.new; | |
# my $match = TestGrammar.parse('40', :$actions); | |
# say $match; # OUTPUT: «「40」» | |
# say $match.made; # OUTPUT: «42» | |
ok 260 - doc/Language/grammars.pod6 chunk 13 compiles | |
# use v6.c; | |
# grammar KeyValuePairs { | |
# token TOP { | |
# [<pair> \n+]* | |
# } | |
# token ws { \h* } | |
# rule pair { | |
# <key=.identifier> '=' <value=.identifier> | |
# } | |
# token identifier { | |
# \w+ | |
# } | |
# } | |
# class KeyValuePairsActions { | |
# method identifier($/) { $/.make: ~$/ } | |
# method pair ($/) { $/.make: $<key>.made => $<value>.made } | |
# method TOP ($/) { $/.make: $<pair>».made } | |
# } | |
# my $res = KeyValuePairs.parse(q:to/EOI/, :actions(KeyValuePairsActions)).made; | |
# second=b | |
# hits=42 | |
# perl=6 | |
# EOI | |
# for @$res -> $p { | |
# say "Key: $p.key()\tValue: $p.value()"; | |
# } | |
ok 261 - doc/Language/grammars.pod6 chunk 14 compiles | |
# sub plus-two(Int $x --> Int) { $x + 2 } | |
# plus-two(2); # This is valid | |
# plus-two(Int); # This is valid | |
ok 262 - doc/Language/haskell-to-p6.pod6 chunk 1 compiles | |
# multi sub is-string(Str $ --> True) {} | |
# multi sub is-string(Any $ --> False) {} | |
# is-string('hello'); #True | |
# is-string(4); #False | |
ok 263 - doc/Language/haskell-to-p6.pod6 chunk 2 compiles | |
# sub parse-int(Str $s --> Int) { ... } | |
# my $string = {...}; | |
# given parse-int($string) { | |
# when Int:D { $_ } | |
# when Int:U { 0 } | |
# } | |
ok 264 - doc/Language/haskell-to-p6.pod6 chunk 3 compiles | |
WARNINGS for /Users/williamcoleda/sandbox/doc/EVAL_264: | |
Useless use of constant value Int:U in sink context (line 3) | |
Useless use of constant value Int:D in sink context (line 2) | |
# Int:D; # This is a defined Int. | |
# Int:U; # This is an undefined Int, AKA a type object | |
# Int:_; # This is either defined or undefined. | |
ok 265 - doc/Language/haskell-to-p6.pod6 chunk 4 compiles | |
# sub parse-int(Str $s --> Int:_) { ... } | |
# # One way to do it | |
# my $string = {...}; | |
# given parse-int($string) { | |
# when Int:D { $_ } | |
# when Int:U { 0 } | |
# } | |
# # Another way to do it | |
# my Int $number = parse-int($string); | |
# if $number.defined { $number } else { 0 } | |
# # A better way | |
# with parse-int($string) { $_ } else { 0 } | |
# # With the defined-or operator | |
# parse-int($string) // 0 | |
ok 266 - doc/Language/haskell-to-p6.pod6 chunk 5 compiles | |
WARNINGS for /Users/williamcoleda/sandbox/doc/EVAL_266: | |
Useless use of constant integer 0 in sink context (line 5) | |
# sub parse-int(Str $s --> Int:_) { ... } | |
# my $string = {...}; | |
# my $result = parse-int($string) orelse 0; | |
# sub hello() { say 'hi' } | |
# hello() andthen say 'bye'; | |
ok 267 - doc/Language/haskell-to-p6.pod6 chunk 6 compiles | |
# class Point { has $.x; has $.y; } | |
# sub move-up(Point $p --> Point) { | |
# Point.new(x => $p.x, y => $p.y + 1) | |
# } | |
ok 268 - doc/Language/haskell-to-p6.pod6 chunk 7 compiles | |
# enum Animal < Dog Cat Bird Horse >; | |
# proto sub test-animal( Animal ) {*} | |
# multi sub test-animal( Dog ) { 'Woof' } | |
# multi sub test-animal( Animal::Horse ) { 'Neigh' } # more explicit | |
# say test-animal Animal::Dog; # more explicit | |
# say test-animal Horse; | |
ok 269 - doc/Language/haskell-to-p6.pod6 chunk 8 compiles | |
# my constant Name = Str; | |
# sub full-name ( Name \first, Name \last --> Name ) { first ~ last } | |
ok 270 - doc/Language/haskell-to-p6.pod6 chunk 9 compiles | |
# proto greeting ( Str --> Str ) {*} | |
# multi greeting ( "" --> "Hello, World!" ) {} | |
# multi greeting ( "bub" --> "Hey bub." ) {} | |
# multi greeting ( \name ) { "Hello, " ~ name ~ "!" } | |
ok 271 - doc/Language/haskell-to-p6.pod6 chunk 10 compiles | |
# proto greeting ( Str \name --> Str ) {*} | |
# say &greeting.signature; # (Str \name --> Str) | |
ok 272 - doc/Language/haskell-to-p6.pod6 chunk 11 compiles | |
# multi greeting ( "" --> "Hello, World!" ) {} | |
# multi greeting ( "bub" --> "Hey bub." ) {} | |
# # The above is the same as the below | |
# multi greeting(Str \name where '' ) {'Hello, World!'} | |
# multi greeting(Str \name where 'bub' ) {'Hey bub.'} | |
# # The above is the same as the below, again. | |
# multi greeting(Str \name where $_ ~~ '' ) {'Hello, World!'} | |
# multi greeting(Str \name where $_ ~~ 'bub') {'Hey bub.'} | |
ok 273 - doc/Language/haskell-to-p6.pod6 chunk 12 compiles | |
# multi greeting ( Str \name where '' --> 'Hello, World!' ){} | |
# multi greeting ( Str \name where { Bool.pick } --> 'True' ){} | |
# multi greeting ( Str \name where 'bub' --> 'Hey, bub.' ){} | |
# say greeting '' ; # will never say True | |
# say greeting 'bub'; # about 50% of the time it will say True | |
ok 274 - doc/Language/haskell-to-p6.pod6 chunk 13 compiles | |
# my $number = {...}; | |
# given $number { | |
# when 2 { "two" } | |
# when 4 { "four" } | |
# when 8 { "eight" } | |
# default { "don't care" } | |
# } | |
ok 275 - doc/Language/haskell-to-p6.pod6 chunk 14 compiles | |
# my @evens = ($_ if $_ %% 2 for ^100); | |
ok 276 - doc/Language/haskell-to-p6.pod6 chunk 15 compiles | |
# my @tuples = (1,2) X 1..4; | |
# # [(1 1) (1 2) (1 3) (1 4) (2 1) (2 2) (2 3) (2 4)] | |
ok 277 - doc/Language/haskell-to-p6.pod6 chunk 16 compiles | |
# my @numbers = {...}; | |
# reduce { $^a + $^b }, 0, |@numbers; | |
# @numbers.reduce({$^a + $^b}, with => 0) | |
ok 278 - doc/Language/haskell-to-p6.pod6 chunk 17 compiles | |
# my @numbers = {...}; | |
# [+] @numbers # This is the same | |
# [+] 0, @numbers # as this | |
ok 279 - doc/Language/haskell-to-p6.pod6 chunk 18 compiles | |
# sub two-elem-list ( \a, \b ) { ( a, b ) } | |
# # you can use a subroutine as an infix operator | |
# say 'a' [&two-elem-list] 'b'; # (a b) | |
# # as the reduction prefix meta operator takes an infix operator, it will work there too; | |
# [[&two-elem-list]] 1..5; # ((((1 2) 3) 4) 5) | |
# say (1..5).reduce: &two-elem-list; # ((((1 2) 3) 4) 5) | |
# # right associative | |
# sub right-two-elem-list( \a, \b ) is assoc<right> { ( a, b ) } | |
# say (1..5).reduce: &right-two-elem-list; # (1 (2 (3 (4 5)))) | |
# # XXX there is possibly a bug here as this currently doesn't look at | |
# # XXX the associativity of &right-two-elem-list and just always does left assoc | |
# say [[&right-two-elem-list]] 1..5; | |
# # chaining | |
# say [<] 1..5; # True | |
# say (1..5).reduce: &[<]; # True | |
ok 280 - doc/Language/haskell-to-p6.pod6 chunk 19 compiles | |
# my $range1 = 10..100; | |
# my $range2 = 1..*; # Infinite | |
# my $range3 = 'a'..'h'; # Letters work too | |
ok 281 - doc/Language/haskell-to-p6.pod6 chunk 20 compiles | |
# (1 .. 100).is-lazy; # False | |
# (1 .. Inf).is-lazy; # True | |
ok 282 - doc/Language/haskell-to-p6.pod6 chunk 21 compiles | |
# (1 .. 100).lazy.is-lazy; # True | |
# (1 .. 100).lazy.eager.is-lazy; # False | |
ok 283 - doc/Language/haskell-to-p6.pod6 chunk 22 compiles | |
# spurt "testfile", "more data\n", :append; | |
ok 284 - doc/Language/io.pod6 chunk 1 compiles | |
# my $file = "path/to/file"; | |
# if $file.IO ~~ :e { | |
# say 'file exists'; | |
# } | |
ok 285 - doc/Language/io.pod6 chunk 2 compiles | |
# say dir; # OUTPUT: «"/path/to/testfile".IO "/path/to/lib".IO» | |
ok 286 - doc/Language/io.pod6 chunk 3 compiles | |
# say dir "/etc/"; # OUTPUT: «"/etc/ld.so.conf".IO "/etc/shadow".IO ....» | |
ok 287 - doc/Language/io.pod6 chunk 4 compiles | |
# run 'git', 'status'; | |
ok 288 - doc/Language/ipc.pod6 chunk 1 compiles | |
# shell 'ls -lR | gzip -9 > ls-lR.gz'; | |
ok 289 - doc/Language/ipc.pod6 chunk 2 compiles | |
# my $git = run 'git', 'log', '--oneline', :out; | |
# for $git.out.lines -> $line { | |
# my ($sha, $subject) = $line.split: ' ', 2; | |
# say "$subject [$sha]"; | |
# } | |
# $git.out.close(); | |
ok 290 - doc/Language/ipc.pod6 chunk 3 compiles | |
# my $echo = run 'echo', 'Hello, world', :out; | |
# my $cat = run 'cat', '-n', :in($echo.out), :out; | |
# say $cat.out.get; | |
# $cat.out.close(); | |
ok 291 - doc/Language/ipc.pod6 chunk 4 compiles | |
# my $crontab = run 'crontab', '-l'; | |
# if $crontab.exitcode == 0 { | |
# say 'crontab -l ran ok'; | |
# } | |
# else { | |
# say 'something went wrong'; | |
# } | |
ok 292 - doc/Language/ipc.pod6 chunk 5 compiles | |
WARNINGS for /Users/williamcoleda/sandbox/doc/EVAL_292: | |
Useless use of constant integer 1 in sink context (line 5) | |
# 1, 2; # This is two-element list | |
# (1, 2); # This is also a List, in parentheses | |
# (1; 2); # same List | |
# (1); # This is not a List, just a 1 in parentheses | |
# (1,); # This is a one-element List | |
ok 293 - doc/Language/list.pod6 chunk 1 compiles | |
# (1, 2), (1, 2) # This is a list of two lists. | |
ok 294 - doc/Language/list.pod6 chunk 2 compiles | |
# say so (1,2; 3,4) eqv ((1,2), (3,4)); | |
# # OUTPUT: «True» | |
# say('foo';); # a list with one element and the empty list | |
# # OUTPUT: «(foo)()» | |
ok 295 - doc/Language/list.pod6 chunk 3 compiles | |
# my @a := 1, 2, 3; | |
ok 296 - doc/Language/list.pod6 chunk 4 compiles | |
# my @a = 1, 2, 3; | |
# @a = (); | |
# @a = Empty; | |
# @a = |(); | |
ok 297 - doc/Language/list.pod6 chunk 5 compiles | |
# for 1, 2, 3 { .say } # OUTPUT: «123» | |
ok 298 - doc/Language/list.pod6 chunk 6 compiles | |
# my @a = <foo bar buzz>; | |
# say @a.Set<bar buzz>; # OUTPUT: «(True True)» | |
# say so 'bar' ∈ @a; # OUTPUT: «True» | |
ok 299 - doc/Language/list.pod6 chunk 7 compiles | |
# (loop { 42.say })[2] # OUTPUT: «424242» | |
ok 300 - doc/Language/list.pod6 chunk 8 compiles | |
# my @s := Seq.new(<a b c>); CATCH { default { say .^name, ' ', .Str } } | |
# # OUTPUT«Type check failed in binding to $iter; expected Iterator but got List ($("a", "b", "c")) in block <unit> at <tmp> line 1» | |
ok 301 - doc/Language/list.pod6 chunk 9 compiles | |
# my @s := (loop { 42.say }).list; | |
# @s[2]; # says 42 three times | |
# @s[1]; # does not say anything | |
# @s[4]; # says 42 two more times | |
ok 302 - doc/Language/list.pod6 chunk 10 compiles | |
# say (1, (2, 3), 4) eqv (1, 2, 3, 4); # OUTPUT: «False» | |
# say (1, Slip.new(2, 3), 4) eqv (1, 2, 3, 4); # OUTPUT: «True» | |
# say (1, slip(2, 3), 4) eqv (1, 2, 3, 4); # OUTPUT: «True» | |
ok 303 - doc/Language/list.pod6 chunk 11 compiles | |
# say (1, |(2, 3), 4) eqv (1, 2, 3, 4); # OUTPUT: «True» | |
# say (1, |$(2, 3), 4) eqv (1, 2, 3, 4); # OUTPUT: «True» | |
# say (1, slip($(2, 3)), 4) eqv (1, 2, 3, 4); # OUTPUT: «False» | |
ok 304 - doc/Language/list.pod6 chunk 12 compiles | |
# my @l = 1,2,4,8...Inf; | |
# say @l[0..16]; | |
# # OUTPUT: «(1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536)» | |
ok 305 - doc/Language/list.pod6 chunk 13 compiles | |
# my $a = 2; | |
# (1, $a, 3)[1] = 42; | |
# $a.say; # OUTPUT: «42» | |
ok 306 - doc/Language/list.pod6 chunk 14 compiles | |
# my $i = 3; | |
# my @a = (loop { $i.say; last unless --$i }); # OUTPUT: «321» | |
# say "take off!"; | |
ok 307 - doc/Language/list.pod6 chunk 15 compiles | |
# say (1, (2, (3, 4)), 5).flat eqv (1, 2, 3, 4, 5) # OUTPUT: «True» | |
ok 308 - doc/Language/list.pod6 chunk 16 compiles | |
# for (1, (2, $(3, 4)), 5).flat { .say } # OUTPUT: «12(3 4)5» | |
ok 309 - doc/Language/list.pod6 chunk 17 compiles | |
# my @l := 2, (3, 4); | |
# for (1, @l, 5).flat { .say }; # OUTPUT: «12345» | |
# my @a = 2, (3, 4); # Arrays are special, see below | |
# for (1, @a, 5).flat { .say }; # OUTPUT: «12(3 4)5» | |
ok 310 - doc/Language/list.pod6 chunk 18 compiles | |
# Array.new(1, 2, :c(3)); | |
# Array.new: 1, 2, :c(3); | |
# new Array: 1, 2, :c(3); | |
ok 311 - doc/Language/list.pod6 chunk 19 compiles | |
Potential difficulties: | |
Redeclaration of symbol '@a' | |
at /Users/williamcoleda/sandbox/doc/EVAL_311:5 | |
------> [32mmy @a[33m⏏[31m = 1, 2, :c(3); Array.new: @a;[0m | |
Redeclaration of symbol '@a' | |
at /Users/williamcoleda/sandbox/doc/EVAL_311:6 | |
------> [32mmy @a[33m⏏[31m = 1, 2, :c(3); new Array: @a;[0m | |
# Array.new((1, 2, :c(3))); | |
# (1, 2, :c(3)).Array; | |
# my @a = 1, 2, :c(3); Array.new(@a); | |
# my @a = 1, 2, :c(3); Array.new: @a; | |
# my @a = 1, 2, :c(3); new Array: @a; | |
ok 312 - doc/Language/list.pod6 chunk 20 compiles | |
# my @a := 2, "c" => 3; | |
# Array.new(1, |@a, 4); # Array contains 1, 2, :c(3), 4 | |
# my %a = "c" => 3; | |
# Array.new(1, |%a, 4); # Array contains 1, 4 | |
ok 313 - doc/Language/list.pod6 chunk 21 compiles | |
# say ("a", "b", "c")[(1, 2), (0, 1)] eqv (("b", "c"), ("a", "b")) # OUTPUT: «True» | |
ok 314 - doc/Language/list.pod6 chunk 22 compiles | |
# my @a = 1..5; | |
# say @a[0..2]; # OUTPUT: «(1 2 3)» | |
# say @a[0..^2]; # OUTPUT: «(1 2)» | |
# say @a[0..*]; # OUTPUT: «(1 2 3 4 5)» | |
# say @a[0..^*]; # OUTPUT: «(1 2 3 4 5)» | |
# say @a[0..Inf-1]; # OUTPUT: «(1 2 3 4 5)» | |
ok 315 - doc/Language/list.pod6 chunk 23 compiles | |
WARNINGS for /Users/williamcoleda/sandbox/doc/EVAL_315: | |
Useless use of "eqv" in expression "[ 1, 2, :c(3) ] eqv Array.new((1, 2, :c(3)))" in sink context (line 2) | |
# [ 1, 2, :c(3) ] eqv Array.new((1, 2, :c(3))); # OUTPUT: «True» | |
# [while $++ < 2 { 42.say; 43 }].map: *.say; # OUTPUT: «42424343» | |
# (while $++ < 2 { 42.say; 43 }).map: *.say; # OUTPUT: «42434243» | |
ok 316 - doc/Language/list.pod6 chunk 24 compiles | |
# say Array ~~ List # OUTPUT: «True» | |
ok 317 - doc/Language/list.pod6 chunk 25 compiles | |
# sub mean(Int @a) { | |
# @a.sum / @a.elems | |
# } | |
ok 318 - doc/Language/list.pod6 chunk 26 compiles | |
# my @a; | |
# @a.of.perl.say; # OUTPUT: «Mu» | |
# @a.default.perl.say; # OUTPUT: «Any» | |
# @a[0].say; # OUTPUT: «(Any)» | |
# my Numeric @n is default(Real); | |
# @n.of.perl.say; # OUTPUT: «Numeric» | |
# @n.default.perl.say; # OUTPUT: «Real» | |
# @n[0].say; # OUTPUT: «(Real)» | |
ok 319 - doc/Language/list.pod6 chunk 27 compiles | |
# my @a[2,2]; | |
# dd @a; | |
# # OUTPUT: «Array.new(:shape(2, 2), [Any, Any], [Any, Any])» | |
# say @a.shape; | |
# # OUTPUT: «(2 2)» | |
ok 320 - doc/Language/list.pod6 chunk 28 compiles | |
# my @a[2;2] = (1,2; 3,4); | |
# @a[1;1] = 42; | |
# dd @a; | |
# # OUTPUT: «Array.new(:shape(2, 2), [1, 2], [3, 42])» | |
ok 321 - doc/Language/list.pod6 chunk 29 compiles | |
# ((1, 2), $(3, 4)).perl.say; # says "((1, 2), $(3, 4))" | |
# [(1, 2), $(3, 4)].perl.say; # says "[(1, 2), (3, 4)]" | |
# # ...but actually means: "[$(1, 2), $(3, 4)]" | |
ok 322 - doc/Language/list.pod6 chunk 30 compiles | |
# ((1, 2), $(3, 4)).flat.perl.say; # OUTPUT: «(1, 2, $(3, 4)).Seq» | |
# [(1, 2), $(3, 4)].flat.perl.say; # OUTPUT: «($(1, 2), $(3, 4)).Seq» | |
ok 323 - doc/Language/list.pod6 chunk 31 compiles | |
# (0, [(1, 2), $(3, 4)], 5).flat.perl.say; # OUTPUT: «(0, $(1, 2), $(3, 4), 5).Seq» | |
ok 324 - doc/Language/list.pod6 chunk 32 compiles | |
# say gather [0, [(1, 2), [3, 4]], $(5, 6)].deepmap: *.take; # OUTPUT: «(1 2 3 4 5 6)» | |
ok 325 - doc/Language/list.pod6 chunk 33 compiles | |
# my @a = "a", "b", "c"; | |
# @a.say; # OUTPUT: «[a b c]» | |
# @a.pop.say; # OUTPUT: «c» | |
# @a.say; # OUTPUT: «[a b]» | |
# @a.push("d"); | |
# @a.say; # OUTPUT: «[a b d]» | |
# @a[1, 3] = "c", "c"; | |
# @a.say; # OUTPUT: «[a c d c]» | |
ok 326 - doc/Language/list.pod6 chunk 34 compiles | |
# my @a; | |
# @a[0, 1, 2] = (loop { 42 }); | |
# @a.say; # OUTPUT: «[42 42 42]» | |
ok 327 - doc/Language/list.pod6 chunk 35 compiles | |
# my $b = "foo"; | |
# my @a = 1, 2, 3; | |
# @a[2] := $b; | |
# @a.say; # OUTPUT: «[1 2 "foo"]» | |
# $b = "bar"; | |
# @a.say; # OUTPUT: «[1 2 "bar"]» | |
ok 328 - doc/Language/list.pod6 chunk 36 compiles | |
# class A { | |
# method x() { say 42 } | |
# } | |
# A.x(); | |
ok 329 - doc/Language/mop.pod6 chunk 1 compiles | |
# constant A := Metamodel::ClassHOW.new_type( name => 'A' ); # class A { | |
# A.^add_method('x', my method x(A:) { say 42 }); # method x() .. . | |
# A.^compose; # } | |
# A.x(); | |
ok 330 - doc/Language/mop.pod6 chunk 2 compiles | |
# .say for (1, 2, 3); # OUTPUT: «123», not itemized | |
# .say for $(1, 2, 3); # OUTPUT: «(1 2 3)», itemized | |
# say (1, 2, 3).VAR ~~ Scalar; # OUTPUT: «False» | |
# say $(1, 2, 3).VAR ~~ Scalar; # OUTPUT: «True» | |
ok 331 - doc/Language/mop.pod6 chunk 3 compiles | |
# say "abc".uc; | |
# # OUTPUT: «ABC» | |
ok 332 - doc/Language/objects.pod6 chunk 1 compiles | |
# say 4.log: ; # OUTPUT: «1.38629436111989» ( natural logarithm of 4 ) | |
# say 4.log: +2; # OUTPUT: «2» ( base-2 logarithm of 4 ) | |
# say 4.log +2; # OUTPUT: «3.38629436111989» ( natural logarithm of 4, plus 2 ) | |
ok 333 - doc/Language/objects.pod6 chunk 2 compiles | |
# $*IN.nl-in = "\r\n"; | |
ok 334 - doc/Language/objects.pod6 chunk 3 compiles | |
# my $int-type-obj = Int; | |
ok 335 - doc/Language/objects.pod6 chunk 4 compiles | |
# my $int-type-obj = 1.WHAT; | |
ok 336 - doc/Language/objects.pod6 chunk 5 compiles | |
# sub f(Int $x) { | |
# if $x.WHAT === Int { | |
# say 'you passed an Int'; | |
# } | |
# else { | |
# say 'you passed a subtype of Int'; | |
# } | |
# } | |
ok 337 - doc/Language/objects.pod6 chunk 6 compiles | |
# class Journey { | |
# } | |
ok 338 - doc/Language/objects.pod6 chunk 7 compiles | |
# my class Journey { | |
# } | |
ok 339 - doc/Language/objects.pod6 chunk 8 compiles | |
# class Journey { | |
# has $!origin; | |
# has $!destination; | |
# has @!travelers; | |
# has $!notes; | |
# } | |
ok 340 - doc/Language/objects.pod6 chunk 9 compiles | |
# class Journey { | |
# has $.origin; | |
# has $.destination; | |
# has @!travelers; | |
# has $.notes; | |
# } | |
ok 341 - doc/Language/objects.pod6 chunk 10 compiles | |
# class Journey { | |
# has $.origin; | |
# has $.destination; | |
# has @!travelers; | |
# has $.notes is rw; | |
# } | |
ok 342 - doc/Language/objects.pod6 chunk 11 compiles | |
# class Journey { | |
# # error if origin is not provided | |
# has $.origin is required; | |
# # set the destination to Orlando as default (unless that is the origin!) | |
# has $.destination = self.origin eq 'Orlando' ?? 'Kampala' !! 'Orlando'; | |
# has @!travelers; | |
# has $.notes is rw; | |
# } | |
ok 343 - doc/Language/objects.pod6 chunk 12 compiles | |
# class Journey { | |
# has $.origin; | |
# has $.destination; | |
# has @!travelers; | |
# has $.notes is rw; | |
# method add_traveler($name) { | |
# if $name ne any(@!travelers) { | |
# push @!travelers, $name; | |
# } | |
# else { | |
# warn "$name is already going on the journey!"; | |
# } | |
# } | |
# method describe() { | |
# "From $!origin to $!destination" | |
# } | |
# } | |
ok 344 - doc/Language/objects.pod6 chunk 13 compiles | |
# class A { has $.b }; | |
# my $name = 'b'; | |
# A.new."$name"().say; | |
# # OUTPUT: «(Any)» | |
ok 345 - doc/Language/objects.pod6 chunk 14 compiles | |
# class C { | |
# my $.local = 42; | |
# has $.x = self.local | |
# }; | |
# say C.new.x | |
# # OUTPUT: «42» | |
ok 346 - doc/Language/objects.pod6 chunk 15 compiles | |
# method !do-something-private($x) { | |
# ... | |
# } | |
# method public($x) { | |
# if self.precondition { | |
# self!do-something-private(2 * $x) | |
# } | |
# } | |
ok 347 - doc/Language/objects.pod6 chunk 16 compiles | |
# class Point2D { | |
# has $.x; | |
# has $.y; | |
# submethod BUILD(:$!x, :$!y) { | |
# say "Initializing Point2D"; | |
# } | |
# } | |
# class InvertiblePoint2D is Point2D { | |
# submethod BUILD() { | |
# say "Initializing InvertiblePoint2D"; | |
# } | |
# method invert { | |
# self.new(x => - $.x, y => - $.y); | |
# } | |
# } | |
# say InvertiblePoint2D.new(x => 1, y => 2); | |
ok 348 - doc/Language/objects.pod6 chunk 17 compiles | |
# class Parent { | |
# method frob { | |
# say "the parent class frobs" | |
# } | |
# } | |
# class Child is Parent { | |
# method frob { | |
# say "the child's somewhat more fancy frob is called" | |
# } | |
# } | |
# my Parent $test; | |
# $test = Child.new; | |
# $test.frob; # calls the frob method of Child rather than Parent | |
ok 349 - doc/Language/objects.pod6 chunk 18 compiles | |
# class MyClass { | |
# method BUILDALL(|) { | |
# # initial things here | |
# callsame; # call the parent classes (or default) BUILDALL | |
# # you can do final checks here. | |
# self # return the fully built object | |
# } | |
# } | |
ok 350 - doc/Language/objects.pod6 chunk 19 compiles | |
# class RectangleWithCachedArea { | |
# has ($.x1, $.x2, $.y1, $.y2); | |
# has $.area; | |
# submethod TWEAK() { | |
# $!area = abs( ($!x2 - $!x1) * ( $!y2 - $!y1) ); | |
# } | |
# } | |
# say RectangleWithCachedArea.new( x2 => 5, x1 => 1, y2 => 1, y1 => 0).area; | |
ok 351 - doc/Language/objects.pod6 chunk 20 compiles | |
# class A { | |
# has $.a; | |
# #... | |
# method clone { | |
# nextwith(:a($.a.clone)) | |
# } | |
# } | |
ok 352 - doc/Language/objects.pod6 chunk 21 compiles | |
# class Bull { | |
# has Bool $.castrated = False; | |
# method steer { | |
# # Turn your bull into a steer | |
# $!castrated = True; | |
# return self; | |
# } | |
# } | |
# class Automobile { | |
# has $.direction; | |
# method steer($!direction) { } | |
# } | |
# class Taurus is Bull is Automobile { } | |
# my $t = Taurus.new; | |
# $t.steer; # OUTPUT: «Castrates $t» | |
ok 353 - doc/Language/objects.pod6 chunk 22 compiles | |
# role R1 { | |
# # methods here | |
# } | |
# role R2 does R1 { | |
# # methods here | |
# } | |
# class C does R2 { } | |
ok 354 - doc/Language/objects.pod6 chunk 23 compiles | |
# role R1 { | |
# # methods here | |
# } | |
# role R2 { | |
# # methods here | |
# } | |
# class C does R1 does R2 { } | |
ok 355 - doc/Language/objects.pod6 chunk 24 compiles | |
# role A is Exception { } | |
# class X::Ouch does A { } | |
# X::Ouch.^parents.say # OUTPUT: «((Exception))» | |
ok 356 - doc/Language/objects.pod6 chunk 25 compiles | |
# role Point { | |
# has $.x; | |
# has $.y; | |
# method abs { sqrt($.x * $.x + $.y * $.y) } | |
# } | |
# say Point.new(x => 6, y => 8).abs; | |
ok 357 - doc/Language/objects.pod6 chunk 26 compiles | |
# role BinaryTree[::Type] { | |
# has BinaryTree[Type] $.left; | |
# has BinaryTree[Type] $.right; | |
# has Type $.node; | |
# method visit-preorder(&cb) { | |
# cb $.node; | |
# for $.left, $.right -> $branch { | |
# $branch.visit-preorder(&cb) if defined $branch; | |
# } | |
# } | |
# method visit-postorder(&cb) { | |
# for $.left, $.right -> $branch { | |
# $branch.visit-postorder(&cb) if defined $branch; | |
# } | |
# cb $.node; | |
# } | |
# method new-from-list(::?CLASS:U: *@el) { | |
# my $middle-index = @el.elems div 2; | |
# my @left = @el[0 .. $middle-index - 1]; | |
# my $middle = @el[$middle-index]; | |
# my @right = @el[$middle-index + 1 .. *]; | |
# self.new( | |
# node => $middle, | |
# left => @left ?? self.new-from-list(@left) !! self, | |
# right => @right ?? self.new-from-list(@right) !! self, | |
# ); | |
# } | |
# } | |
# my $t = BinaryTree[Int].new-from-list(4, 5, 6); | |
# $t.visit-preorder(&say); # OUTPUT: «546» | |
# $t.visit-postorder(&say); # OUTPUT: «465» | |
ok 358 - doc/Language/objects.pod6 chunk 27 compiles | |
# use v6.c; | |
# enum Severity <debug info warn error critical>; | |
# role Logging[$filehandle = $*ERR] { | |
# method log(Severity $sev, $message) { | |
# $filehandle.print("[{uc $sev}] $message\n"); | |
# } | |
# } | |
# Logging[$*OUT].log(debug, 'here we go'); # OUTPUT: «[DEBUG] here we go» | |
ok 359 - doc/Language/objects.pod6 chunk 28 compiles | |
# role R { method Str() {'hidden!'} }; | |
# my $i = 2 but R; | |
# sub f(\bound){ put bound }; | |
# f($i); # OUTPUT: «hidden!» | |
ok 360 - doc/Language/objects.pod6 chunk 29 compiles | |
# # A counter for Table of Contents | |
# role TOC-Counter { | |
# has Int @!counters is default(0); | |
# method Str() { @!counters.join: '.' } | |
# method inc($level) { | |
# @!counters[$level - 1]++; | |
# @!counters.splice($level); | |
# self | |
# } | |
# } | |
# my Num $toc-counter = NaN; # don't do maths with Not A Number | |
# say $toc-counter; # OUTPUT: «NaN» | |
# $toc-counter does TOC-Counter; # now we mix the role in | |
# $toc-counter.inc(1).inc(2).inc(2).inc(1).inc(2).inc(2).inc(3).inc(3); | |
# put $toc-counter / 1; # OUTPUT: «NaN» (because that's numerical context) | |
# put $toc-counter; # OUTPUT: «2.2.2» (put will call TOC-Counter::Str) | |
ok 361 - doc/Language/objects.pod6 chunk 30 compiles | |
# my %seen of Int is default(0 but role :: { method Str() {'NULL'} }); | |
# say %seen<not-there>; # OUTPUT: «NULL» | |
# say %seen<not-there>.defined; # OUTPUT: «True» (0 may be False but is well defined) | |
# say Int.new(%seen<not-there>); # OUTPUT: «0» | |
ok 362 - doc/Language/objects.pod6 chunk 31 compiles | |
# say 1.HOW === 2.HOW; # OUTPUT: «True» | |
# say 1.HOW === Int.HOW; # OUTPUT: «True» | |
# say 1.HOW === Num.HOW; # OUTPUT: «False» | |
ok 363 - doc/Language/objects.pod6 chunk 32 compiles | |
# my $object = 1; | |
# my $metaobject = 1.HOW; | |
# say $metaobject.name($object); # OUTPUT: «Int» | |
# # or shorter: | |
# say 1.HOW.name(1); # OUTPUT: «Int» | |
ok 364 - doc/Language/objects.pod6 chunk 33 compiles | |
# say 1.^name; # OUTPUT: «Int» | |
# # same as | |
# say 1.HOW.name(1); # OUTPUT: «Int» | |
ok 365 - doc/Language/objects.pod6 chunk 34 compiles | |
# infix:<+>(1, 2); # same as 1 + 2 | |
# circumfix:«[ ]»(<a b c>); # same as [<a b c>] | |
ok 366 - doc/Language/operators.pod6 chunk 1 compiles | |
# my $str = 'old string'; | |
# $str ~~ s/o .+ d/new/; | |
# say $str; # OUTPUT: «new string» | |
ok 367 - doc/Language/operators.pod6 chunk 2 compiles | |
# my $str = 'foo muCKed into the lEn'; | |
# # replace second 'o' with 'x' | |
# $str ~~ s:2nd/o/x/; | |
# # replace 'M' or 'L' followed by non-whitespace stuff with 'd' | |
# # and lower-cased version of that stuff: | |
# $str ~~ s :g :i/<[ML]> (\S+)/d{lc $0}/; | |
# say $str; # OUTPUT: «fox ducked into the den» | |
ok 368 - doc/Language/operators.pod6 chunk 3 compiles | |
# my $str = 'foober'; | |
# $str ~~ s!foo!fox!; | |
# $str ~~ s{b(.)r} = " d$0n"; | |
# say $str; # OUTPUT: «fox den» | |
ok 369 - doc/Language/operators.pod6 chunk 4 compiles | |
# say S/o .+ d/new/ with 'old string'; # OUTPUT: «new string» | |
# S:g/« (.)/$0.uc()/.say for <foo bar ber>; # OUTPUT: «FooBarBer» | |
ok 370 - doc/Language/operators.pod6 chunk 5 compiles | |
# my $a = 32; | |
# $a += 10; # 42 | |
# $a -= 2; # 40 | |
# $a = 3; | |
# $a min= 5; # still 3 | |
# $a min= 2; # 2 | |
# my $s = 'a'; | |
# $s ~= 'b'; # 'ab' | |
ok 371 - doc/Language/operators.pod6 chunk 6 compiles | |
# sub infix:<space-concat> ($a, $b) { $a ~ " " ~ $b }; | |
# my $a = 'word1'; | |
# $a space-concat= 'word2'; # RESULT: «'word1 word2'» | |
ok 372 - doc/Language/operators.pod6 chunk 7 compiles | |
# my Real $a = 1/2; | |
# $a = 3.14; | |
# $a .= round; # RESULT: «3» | |
ok 373 - doc/Language/operators.pod6 chunk 8 compiles | |
# my $a = True; | |
# say so $a != True; # OUTPUT: «False» | |
# my $i = 10; | |
# my $release = Date.new(:2015year, :12month, :24day); | |
# my $today = Date.today; | |
# say so $release !before $today; # OUTPUT: «False» | |
ok 374 - doc/Language/operators.pod6 chunk 9 compiles | |
# say 4 R/ 12; # OUTPUT: «3» | |
# say [R/] 2, 4, 16; # OUTPUT: «2» | |
ok 375 - doc/Language/operators.pod6 chunk 10 compiles | |
# say (1, 2, 3) »*» 2; # OUTPUT: «(2 4 6)» | |
# say (1, 2, 3, 4) »~» <a b>; # OUTPUT: «(1a 2b 3a 4b)» | |
# say (1, 2, 3) »+« (4, 5, 6); # OUTPUT: «(5 7 9)» | |
ok 376 - doc/Language/operators.pod6 chunk 11 compiles | |
# my @a = 1, 2, 3; | |
# say @a »+=» 1; # OUTPUT: «[2 3 4]» | |
ok 377 - doc/Language/operators.pod6 chunk 12 compiles | |
# my @wisdom = True, False, True; | |
# say !« @wisdom; # OUTPUT: «[False True False]» | |
# my @a = 1, 2, 3; | |
# @a»++; # OUTPUT: «(2, 3, 4)» | |
ok 378 - doc/Language/operators.pod6 chunk 13 compiles | |
# say -« [[1, 2], 3]; # OUTPUT: «[[-1 -2] -3]» | |
ok 379 - doc/Language/operators.pod6 chunk 14 compiles | |
# class CarefulClass { method take-care {} } | |
# my CarefulClass @objs; | |
# my @results = @objs».take-care(); | |
# my @slops; # May Contain Nuts | |
# @slops».?this-method-may-not-exist(); | |
ok 380 - doc/Language/operators.pod6 chunk 15 compiles | |
# my %outer = 1, 2, 3 Z=> <a b c>; | |
# my %inner = 1, 2 Z=> <x z>; | |
# say %outer «~» %inner; # OUTPUT: «{"1" => "ax", "2" => "bz"}» | |
ok 381 - doc/Language/operators.pod6 chunk 16 compiles | |
# sub pretty-file-site (Int $size --> Str) { | |
# # rounding version of infix:</>(Int, Int) | |
# sub infix:<r/>(Int \i1, Int \i2) { | |
# round(i1 / i2, 0.1) | |
# } | |
# # we build a vector of fractions of $size and zip that with the fitting prefix | |
# for $size «[r/]« (2**60, 2**50, 2**40, 2**30, 2**20, 2**10) | |
# Z <EB PB TB GB MB KB> -> [\v,\suffix] { | |
# # starting with the biggest suffix, we take the first that is 0.5 of that suffix or bigger | |
# return v ~ ' ' ~ suffix if v > 0.4 | |
# } | |
# # this be smaller or equal then 0.4 KB | |
# return $size.Str; | |
# } | |
# for 60, 50, 40, 30, 20, 10 -> $test { | |
# my &a = { (2 ** $test) * (1/4, 1/2, 1, 10, 100).pick * (1..10).pick }; | |
# print pretty-file-site(a.Int) xx 2, ' '; | |
# } | |
# # OUTPUT: «10 EB 4 EB 2 PB 5 PB 0.5 PB 4 TB 300 GB 4.5 GB 50 MB 200 MB 9 KB 0.6 MB» | |
ok 382 - doc/Language/operators.pod6 chunk 17 compiles | |
# say (<a b>, <c d e>)».elems; # OUTPUT: «(2 3)» | |
# say (<a b>, <c d e>)».&{ .elems }; # OUTPUT: «((1 1) (1 1 1))» | |
ok 383 - doc/Language/operators.pod6 chunk 18 compiles | |
# my $neighbors = ((-1, 0), (0, -1), (0, 1), (1, 0)); | |
# my $p = (2, 3); | |
# say $neighbors »>>+<<» ($p, *); # OUTPUT: «((1 3) (2 2) (2 4) (3 3))» | |
ok 384 - doc/Language/operators.pod6 chunk 19 compiles | |
# # These two are equivalent: | |
# say [+] 1, 2, 3; # OUTPUT: «6» | |
# say reduce &infix:<+>, 1, 2, 3; # OUTPUT: «6» | |
ok 385 - doc/Language/operators.pod6 chunk 20 compiles | |
# sub plus { $^a + $^b }; | |
# say [[&plus]] 1, 2, 3; # OUTPUT: «6» | |
ok 386 - doc/Language/operators.pod6 chunk 21 compiles | |
# say [X~] (1, 2), <a b>; # OUTPUT: «1, 2 X~ <a b>» | |
ok 387 - doc/Language/operators.pod6 chunk 22 compiles | |
# my @n = [\~] 1..*; | |
# say @n[^5]; # OUTPUT: «(1 12 123 1234 12345)» | |
ok 388 - doc/Language/operators.pod6 chunk 23 compiles | |
# 1..3 X~ <a b> # RESULT: «<1a, 1b, 2a, 2b, 3a, 3b>» | |
ok 389 - doc/Language/operators.pod6 chunk 24 compiles | |
# my @l = <a b c> Z~ 1, 2, 3; # RESULT: «[a1 b2 c3]» | |
ok 390 - doc/Language/operators.pod6 chunk 25 compiles | |
# my @l = <a b c d> Z~ ':' xx *; # RESULT: «<a: b: c: d:>» | |
# @l = <a b c d> Z~ 1, 2, *; # RESULT: «<a1 b2 c2 d2>» | |
ok 391 - doc/Language/operators.pod6 chunk 26 compiles | |
# my @l = 1 Z 2; # RESULT: «[(1 2)]» | |
ok 392 - doc/Language/operators.pod6 chunk 27 compiles | |
# say so 1 S& 2 S& 3; # OUTPUT: «True» | |
ok 393 - doc/Language/operators.pod6 chunk 28 compiles | |
# my @a = 1, 2, 3; | |
# my @b = 5, 6, 7; | |
# @a X[+=] @b; | |
# say @a; # OUTPUT: «[19 20 21]» | |
ok 394 - doc/Language/operators.pod6 chunk 29 compiles | |
# say <a b c>[1]; # OUTPUT: «b» | |
ok 395 - doc/Language/operators.pod6 chunk 30 compiles | |
# multi sub p(:$a!) { say 'named' } | |
# multi sub p($a) { say 'positional' } | |
# p a => 1; # OUTPUT: «named» | |
# p (a => 1); # OUTPUT: «positional» | |
ok 396 - doc/Language/operators.pod6 chunk 31 compiles | |
# my @alphabet = 'a' .. 'z'; | |
# say @alphabet[0]; # OUTPUT: «a» | |
# say @alphabet[1]; # OUTPUT: «b» | |
# say @alphabet[*-1]; # OUTPUT: «z» | |
# say @alphabet[100]:exists; # OUTPUT: «False» | |
# say @alphabet[15, 4, 17, 11].join; # OUTPUT: «perl» | |
# say @alphabet[23 .. *].perl; # OUTPUT: «("x", "y", "z")» | |
# @alphabet[1, 2] = "B", "C"; | |
# say @alphabet[0..3].perl # OUTPUT: «("a", "B", "C", "d")» | |
ok 397 - doc/Language/operators.pod6 chunk 32 compiles | |
# my %color = kiwi => "green", banana => "yellow", cherry => "red"; | |
# say %color{"banana"}; # OUTPUT: «yellow» | |
# say %color{"cherry", "kiwi"}.perl; # OUTPUT: «("red", "green")» | |
# say %color{"strawberry"}:exists; # OUTPUT: «False» | |
# %color{"banana", "lime"} = "yellowish", "green"; | |
# %color{"cherry"}:delete; | |
# say %color; # OUTPUT: «banana => yellowish, kiwi => green, lime => green» | |
ok 398 - doc/Language/operators.pod6 chunk 33 compiles | |
# my %color = kiwi => "green", banana => "yellow", cherry => "red"; | |
# say %color<banana>; # OUTPUT: «yellow» | |
# say %color<cherry kiwi>.perl; # OUTPUT: «("red", "green")» | |
# say %color<strawberry>:exists; # OUTPUT: «False» | |
ok 399 - doc/Language/operators.pod6 chunk 34 compiles | |
# my %color = kiwi => "green", banana => "yellow", cherry => "red"; | |
# my $fruit = "kiwi"; | |
# say %color«cherry $fruit».perl; # OUTPUT: «("red", "green")» | |
ok 400 - doc/Language/operators.pod6 chunk 35 compiles | |
# my sub f($invocant){ dd $invocant; } | |
# my $i = 42; | |
# 42.&f; | |
# # OUTPUT: «Int $invocant = 42» | |
# 42.&(-> $invocant { dd $invocant }); | |
# # OUTPUT: «Int $invocant = 42» | |
ok 401 - doc/Language/operators.pod6 chunk 36 compiles | |
# my @a = <a b c>; | |
# my @b = @a».ord; # OUTPUT: «[97, 98, 99]» | |
# sub foo(Str:D $c){ $c.ord * 2 }; # The first parameter of a method is the invocant. | |
# say @a».&foo; # So we can pretend to have a method call with a sub that got a good first positional argument. | |
# say @a».&{ .ord}; # Blocks have an implicit positional arguments that lands in $_. The latter can be omitted for method calls. | |
ok 402 - doc/Language/operators.pod6 chunk 37 compiles | |
# my @a; | |
# @a[1, 2, 3]; | |
# @a.[1, 2, 3]; # Same | |
ok 403 - doc/Language/operators.pod6 chunk 38 compiles | |
# class Operation { | |
# has $.symbol; | |
# has &.function; | |
# } | |
# my $addition = Operation.new(:symbol<+>, :function{ $^a + $^b }); | |
# say $addition.function()(1, 2); # OUTPUT: «3» | |
# # OR | |
# say $addition.function.(1, 2); # OUTPUT: «3» | |
ok 404 - doc/Language/operators.pod6 chunk 39 compiles | |
# my $a = 1; | |
# say ++$a; # OUTPUT: «2» | |
# say $a.:<++>; # OUTPUT: «3» | |
ok 405 - doc/Language/operators.pod6 chunk 40 compiles | |
# class Bar { | |
# method baz { 42 } | |
# } | |
# class Foo is Bar { | |
# method baz { "nope" } | |
# } | |
# say Foo.Bar::baz; # OUTPUT: «42» | |
ok 406 - doc/Language/operators.pod6 chunk 41 compiles | |
# multi sub prefix:<++>($x is rw) is assoc<non> | |
ok 407 - doc/Language/operators.pod6 chunk 42 compiles | |
# my $x = 3; | |
# say ++$x; # OUTPUT: «4» | |
# say $x; # OUTPUT: «4» | |
ok 408 - doc/Language/operators.pod6 chunk 43 compiles | |
# multi sub prefix:<-->($x is rw) is assoc<non> | |
ok 409 - doc/Language/operators.pod6 chunk 44 compiles | |
# my $x = 3; | |
# say --$x; # OUTPUT: «2» | |
# say $x; # OUTPUT: «2» | |
ok 410 - doc/Language/operators.pod6 chunk 45 compiles | |
# multi sub postfix:<++>($x is rw) is assoc<non> | |
ok 411 - doc/Language/operators.pod6 chunk 46 compiles | |
# my $x = 3; | |
# say $x++; # OUTPUT: «3» | |
# say $x; # OUTPUT: «4» | |
ok 412 - doc/Language/operators.pod6 chunk 47 compiles | |
# my $x; | |
# say $x++; # OUTPUT: «0» | |
# say $x; # OUTPUT: «1» | |
ok 413 - doc/Language/operators.pod6 chunk 48 compiles | |
# my $filename = "somefile-001.txt"; | |
# say $filename++ for 1..3; | |
# # OUTPUT: «somefile-001.txtsomefile-002.txtsomefile-003.txt» | |
ok 414 - doc/Language/operators.pod6 chunk 49 compiles | |
# multi sub postfix:<-->($x is rw) is assoc<non> | |
ok 415 - doc/Language/operators.pod6 chunk 50 compiles | |
# my $x = 3; | |
# say $x--; # OUTPUT: «3» | |
# say $x; # OUTPUT: «2» | |
ok 416 - doc/Language/operators.pod6 chunk 51 compiles | |
# my $x; | |
# say $x--; # OUTPUT: «0» | |
# say $x; # OUTPUT: «-1» | |
ok 417 - doc/Language/operators.pod6 chunk 52 compiles | |
# my $filename = "somefile-003.txt"; | |
# say $filename-- for 1..3; | |
# # OUTPUT: «somefile-003.txtsomefile-002.txtsomefile-001.txt» | |
ok 418 - doc/Language/operators.pod6 chunk 53 compiles | |
# multi sub infix:<**>(Any, Any --> Numeric:D) is assoc<right> | |
ok 419 - doc/Language/operators.pod6 chunk 54 compiles | |
# multi sub prefix:<?>(Mu --> Bool:D) | |
ok 420 - doc/Language/operators.pod6 chunk 55 compiles | |
# multi sub prefix:<!>(Mu --> Bool:D) | |
ok 421 - doc/Language/operators.pod6 chunk 56 compiles | |
# multi sub prefix:<+>(Any --> Numeric:D) | |
ok 422 - doc/Language/operators.pod6 chunk 57 compiles | |
# multi sub prefix:<->(Any --> Numeric:D) | |
ok 423 - doc/Language/operators.pod6 chunk 58 compiles | |
# multi sub prefix:<~>(Any --> Str:D) | |
ok 424 - doc/Language/operators.pod6 chunk 59 compiles | |
# multi sub prefix:<+^>(Any --> Int:D) | |
ok 425 - doc/Language/operators.pod6 chunk 60 compiles | |
# multi sub prefix:<?^>(Mu --> Bool:D) | |
ok 426 - doc/Language/operators.pod6 chunk 61 compiles | |
# multi sub prefix:<^>(Any --> Range:D) | |
ok 427 - doc/Language/operators.pod6 chunk 62 compiles | |
# say ^5; # OUTPUT: «0..^5» | |
# for ^5 { } # 5 iterations | |
ok 428 - doc/Language/operators.pod6 chunk 63 compiles | |
# multi sub infix:<*>(Any, Any --> Numeric:D) | |
ok 429 - doc/Language/operators.pod6 chunk 64 compiles | |
# multi sub infix:</>(Any, Any --> Numeric:D) | |
ok 430 - doc/Language/operators.pod6 chunk 65 compiles | |
# multi sub infix:<div>(Int:D, Int:D --> Int:D) | |
ok 431 - doc/Language/operators.pod6 chunk 66 compiles | |
# multi sub infix:<%>($x, $y --> Numeric:D) | |
ok 432 - doc/Language/operators.pod6 chunk 67 compiles | |
# my ($x, $y) = 1,2; | |
# $x % $y == $x - floor($x / $y) * $y | |
ok 433 - doc/Language/operators.pod6 chunk 68 compiles | |
# multi sub infix:<%%>($a, $b --> Bool:D) | |
ok 434 - doc/Language/operators.pod6 chunk 69 compiles | |
# multi sub infix:<mod>(Int:D $a, Int:D $b --> Int:D) | |
ok 435 - doc/Language/operators.pod6 chunk 70 compiles | |
# multi sub infix:<+&>($a, $b --> Int:D) | |
ok 436 - doc/Language/operators.pod6 chunk 71 compiles | |
# multi sub infix:<< +< >>($a, $b --> Int:D) | |
ok 437 - doc/Language/operators.pod6 chunk 72 compiles | |
# multi sub infix:<< +> >>($a, $b --> Int:D) | |
ok 438 - doc/Language/operators.pod6 chunk 73 compiles | |
# multi sub infix:<gcd>($a, $b --> Int:D) | |
ok 439 - doc/Language/operators.pod6 chunk 74 compiles | |
# multi sub infix:<lcm>($a, $b --> Int:D) | |
ok 440 - doc/Language/operators.pod6 chunk 75 compiles | |
# multi sub infix:<+>($a, $b --> Numeric:D) | |
ok 441 - doc/Language/operators.pod6 chunk 76 compiles | |
# multi sub infix:<->($a, $b --> Numeric:D) | |
ok 442 - doc/Language/operators.pod6 chunk 77 compiles | |
# multi sub infix:<+|>($a, $b --> Int:D) | |
ok 443 - doc/Language/operators.pod6 chunk 78 compiles | |
# multi sub infix:<+^>($a, $b --> Int:D) | |
ok 444 - doc/Language/operators.pod6 chunk 79 compiles | |
# multi sub infix:<?|>($a, $b --> Bool:D) | |
ok 445 - doc/Language/operators.pod6 chunk 80 compiles | |
# sub infix:<x>($a, $b --> Str:D) | |
ok 446 - doc/Language/operators.pod6 chunk 81 compiles | |
# say 'ab' x 3; # OUTPUT: «ababab» | |
# say 42 x 3; # OUTPUT: «424242» | |
# my $a = 'a'.IO; | |
# my $b = 3.5; | |
# say $a x $b; # OUTPUT: «aaa» | |
ok 447 - doc/Language/operators.pod6 chunk 82 compiles | |
# multi sub infix:<xx>($a, $b --> List:D) | |
ok 448 - doc/Language/operators.pod6 chunk 83 compiles | |
# say [1, 2] xx 5; | |
# # OUTPUT: «([1 2] [1 2] [1 2] [1 2] [1 2])» | |
ok 449 - doc/Language/operators.pod6 chunk 84 compiles | |
# rand xx 3 | |
ok 450 - doc/Language/operators.pod6 chunk 85 compiles | |
# multi sub infix:<~>(Any, Any) | |
# multi sub infix:<~>(Str:D, Str:D) | |
ok 451 - doc/Language/operators.pod6 chunk 86 compiles | |
# say 'ab' ~ 'c'; # OUTPUT: «abc» | |
ok 452 - doc/Language/operators.pod6 chunk 87 compiles | |
# multi sub infix:<&>($a, $b --> Junction:D) is assoc<list> | |
ok 453 - doc/Language/operators.pod6 chunk 88 compiles | |
# multi sub infix:<|>($a, $b --> Junction:D) is assoc<list> | |
ok 454 - doc/Language/operators.pod6 chunk 89 compiles | |
# multi sub infix:<^>($a, $b --> Junction:D) is assoc<list> | |
ok 455 - doc/Language/operators.pod6 chunk 90 compiles | |
# sub prefix:<temp>(Mu $a is rw) | |
ok 456 - doc/Language/operators.pod6 chunk 91 compiles | |
# my $a = "three"; | |
# say $a; # OUTPUT: «three» | |
# { | |
# temp $a; | |
# say $a; # OUTPUT: «three» | |
# $a = "four"; | |
# say $a; # OUTPUT: «four» | |
# } | |
# say $a; # OUTPUT: «three» | |
ok 457 - doc/Language/operators.pod6 chunk 92 compiles | |
# sub prefix:<let>(Mu $a is rw) | |
ok 458 - doc/Language/operators.pod6 chunk 93 compiles | |
# my $answer = 42; | |
# { | |
# let $answer = 84; | |
# die if not Bool.pick; | |
# CATCH { | |
# default { say "it's been reset :(" } | |
# } | |
# say "we made it 84 sticks!"; | |
# } | |
# say $answer; | |
ok 459 - doc/Language/operators.pod6 chunk 94 compiles | |
# sub infix:<does>(Mu $obj, Mu $role) is assoc<non> | |
ok 460 - doc/Language/operators.pod6 chunk 95 compiles | |
# multi sub infix:<but>(Mu $obj1, Mu $role) is assoc<non> | |
# multi sub infix:<but>(Mu $obj1, Mu:D $obj2) is assoc<non> | |
ok 461 - doc/Language/operators.pod6 chunk 96 compiles | |
# multi sub infix:<cmp>(Any, Any) | |
# multi sub infix:<cmp>(Real:D, Real:D) | |
# multi sub infix:<cmp>(Str:D, Str:D) | |
# multi sub infix:<cmp>(Version:D, Version:D) | |
ok 462 - doc/Language/operators.pod6 chunk 97 compiles | |
# say (a => 3) cmp (a => 4); # OUTPUT: «Less» | |
# say 4 cmp 4.0; # OUTPUT: «Same» | |
# say 'b' cmp 'a'; # OUTPUT: «More» | |
ok 463 - doc/Language/operators.pod6 chunk 98 compiles | |
# multi sub infix:<leg>(Any, Any) | |
# multi sub infix:<leg>(Str:D, Str:D) | |
ok 464 - doc/Language/operators.pod6 chunk 99 compiles | |
# say 'a' leg 'b'; # OUTPUT: «Less» | |
# say 'a' leg 'a'; # OUTPUT: «Same» | |
# say 'b' leg 'a'; # OUTPUT: «More» | |
ok 465 - doc/Language/operators.pod6 chunk 100 compiles | |
# multi sub infix:«<=>»($a, $b --> Order:D) is assoc<non> | |
ok 466 - doc/Language/operators.pod6 chunk 101 compiles | |
# multi sub infix:<..>($a, $b --> Range:D) is assoc<non> | |
ok 467 - doc/Language/operators.pod6 chunk 102 compiles | |
# multi sub infix:<..^>($a, $b --> Range:D) is assoc<non> | |
ok 468 - doc/Language/operators.pod6 chunk 103 compiles | |
# multi sub infix:<^..>($a, $b --> Range:D) is assoc<non> | |
ok 469 - doc/Language/operators.pod6 chunk 104 compiles | |
# multi sub infix:<^..^>($a, $b --> Range:D) is assoc<non> | |
ok 470 - doc/Language/operators.pod6 chunk 105 compiles | |
# multi sub infix:<==>(Any, Any) | |
# multi sub infix:<==>(Int:D, Int:D) | |
# multi sub infix:<==>(Num:D, Num:D) | |
# multi sub infix:<==>(Rational:D, Rational:D) | |
# multi sub infix:<==>(Real:D, Real:D) | |
# multi sub infix:<==>(Complex:D, Complex:D) | |
# multi sub infix:<==>(Numeric:D, Numeric:D) | |
ok 471 - doc/Language/operators.pod6 chunk 106 compiles | |
# sub infix:<!=>(Mu, Mu --> Bool:D) | |
ok 472 - doc/Language/operators.pod6 chunk 107 compiles | |
# multi sub infix:«<»(Int:D, Int:D) | |
# multi sub infix:«<»(Num:D, Num:D) | |
# multi sub infix:«<»(Real:D, Real:D) | |
ok 473 - doc/Language/operators.pod6 chunk 108 compiles | |
# multi sub infix:«<=»(Int:D, Int:D) | |
# multi sub infix:«<=»(Num:D, Num:D) | |
# multi sub infix:«<=»(Real:D, Real:D) | |
ok 474 - doc/Language/operators.pod6 chunk 109 compiles | |
# multi sub infix:«>»(Int:D, Int:D) | |
# multi sub infix:«>»(Num:D, Num:D) | |
# multi sub infix:«>»(Real:D, Real:D) | |
ok 475 - doc/Language/operators.pod6 chunk 110 compiles | |
# multi sub infix:«>=»(Int:D, Int:D) | |
# multi sub infix:«>=»(Num:D, Num:D) | |
# multi sub infix:«>=»(Real:D, Real:D) | |
ok 476 - doc/Language/operators.pod6 chunk 111 compiles | |
# multi sub infix:<eq>(Any, Any) | |
# multi sub infix:<eq>(Str:D, Str:D) | |
ok 477 - doc/Language/operators.pod6 chunk 112 compiles | |
# multi sub infix:<ne>(Mu, Mu) | |
# multi sub infix:<ne>(Str:D, Str:D) | |
ok 478 - doc/Language/operators.pod6 chunk 113 compiles | |
# multi sub infix:<gt>(Mu, Mu) | |
# multi sub infix:<gt>(Str:D, Str:D) | |
ok 479 - doc/Language/operators.pod6 chunk 114 compiles | |
# multi sub infix:<ge>(Mu, Mu) | |
# multi sub infix:<ge>(Str:D, Str:D) | |
ok 480 - doc/Language/operators.pod6 chunk 115 compiles | |
# multi sub infix:<lt>(Mu, Mu) | |
# multi sub infix:<lt>(Str:D, Str:D) | |
ok 481 - doc/Language/operators.pod6 chunk 116 compiles | |
# multi sub infix:<le>(Mu, Mu) | |
# multi sub infix:<le>(Str:D, Str:D) | |
ok 482 - doc/Language/operators.pod6 chunk 117 compiles | |
# multi sub infix:<before>(Any, Any) | |
# multi sub infix:<before>(Real:D, Real:D) | |
# multi sub infix:<before>(Str:D, Str:D) | |
# multi sub infix:<before>(Version:D, Version:D) | |
ok 483 - doc/Language/operators.pod6 chunk 118 compiles | |
# multi sub infix:<after>(Any, Any) | |
# multi sub infix:<after>(Real:D, Real:D) | |
# multi sub infix:<after>(Str:D, Str:D) | |
# multi sub infix:<after>(Version:D, Version:D) | |
ok 484 - doc/Language/operators.pod6 chunk 119 compiles | |
# sub infix:<eqv>(Any, Any) | |
ok 485 - doc/Language/operators.pod6 chunk 120 compiles | |
# say [1, 2, 3] eqv [1, 2, 3]; # OUTPUT: «True» | |
# say Any eqv Any; # OUTPUT: «True» | |
# say 1 eqv 2; # OUTPUT: «False» | |
# say 1 eqv 1.0; # OUTPUT: «False» | |
ok 486 - doc/Language/operators.pod6 chunk 121 compiles | |
# my class A { | |
# has $.a; | |
# } | |
# say A.new(a => 5) eqv A.new(a => 5); # OUTPUT: «True» | |
ok 487 - doc/Language/operators.pod6 chunk 122 compiles | |
# my class A { | |
# has $.a; | |
# } | |
# multi infix:<eqv>(A $l, A $r) { $l.a eqv $r.a } | |
# say A.new(a => 5) eqv A.new(a => 5); # OUTPUT: «True» | |
ok 488 - doc/Language/operators.pod6 chunk 123 compiles | |
# sub infix:<===>(Any, Any) | |
ok 489 - doc/Language/operators.pod6 chunk 124 compiles | |
# my class A { }; | |
# my $a = A.new; | |
# say $a === $a; # OUTPUT: «True» | |
# say A.new === A.new; # OUTPUT: «False» | |
# say A === A; # OUTPUT: «True» | |
ok 490 - doc/Language/operators.pod6 chunk 125 compiles | |
# say 'a' === 'a'; # OUTPUT: «True» | |
# say 'a' === 'b'; # OUTPUT: «False» | |
# # different types | |
# say 1 === 1.0; # OUTPUT: «False» | |
ok 491 - doc/Language/operators.pod6 chunk 126 compiles | |
# multi sub infix:<=:=>(Mu \a, Mu \b) | |
ok 492 - doc/Language/operators.pod6 chunk 127 compiles | |
# my ($a, $b) = (1, 3); | |
# say $a =:= $b; # OUTPUT: «False» | |
# $b = 2; | |
# say $a; # OUTPUT: «1» | |
# $b := $a; | |
# say $a =:= $b; # OUTPUT: «True» | |
# $a = 5; | |
# say $b; # OUTPUT: «5» | |
ok 493 - doc/Language/operators.pod6 chunk 128 compiles | |
# multi sub infix:<=~=>(Any, Any) | |
# multi sub infix:<=~=>(Int:D, Int:D) | |
# multi sub infix:<=~=>(Num:D, Num:D) | |
# multi sub infix:<=~=>(Rational:D, Rational:D) | |
# multi sub infix:<=~=>(Real:D, Real:D) | |
# multi sub infix:<=~=>(Complex:D, Complex:D) | |
# multi sub infix:<=~=>(Numeric:D, Numeric:D) | |
ok 494 - doc/Language/operators.pod6 chunk 129 compiles | |
# my $x = 1; | |
# say ($x + $*TOLERANCE) =~= $x; # OUTPUT: «False» | |
# say ($x - $*TOLERANCE) =~= $x; # OUTPUT: «True» | |
ok 495 - doc/Language/operators.pod6 chunk 130 compiles | |
# { | |
# my $*TOLERANCE = .1; | |
# say 11 =~= 10; # OUTPUT: «True» | |
# } | |
ok 496 - doc/Language/operators.pod6 chunk 131 compiles | |
# { | |
# my $*TOLERANCE = 0; | |
# say 1 =~= 1; # OUTPUT: «False» | |
# } | |
ok 497 - doc/Language/operators.pod6 chunk 132 compiles | |
# sub a { 1 } | |
# sub b { 0 } | |
# sub c { die "never called" }; | |
# say a() && b() && c(); # OUTPUT: «0» | |
ok 498 - doc/Language/operators.pod6 chunk 133 compiles | |
# sub a { 0 } | |
# sub b { 1 } | |
# sub c { die "never called" }; | |
# say a() || b() || c(); # OUTPUT: «1» | |
ok 499 - doc/Language/operators.pod6 chunk 134 compiles | |
# say 0 ^^ 42; # OUTPUT: «42» | |
# say '' ^^ 0; # OUTPUT: «0» | |
# say 0 ^^ 42 ^^ 1 ^^ die "never called"; # OUTPUT: «» | |
ok 500 - doc/Language/operators.pod6 chunk 135 compiles | |
# say Any // 0 // 42; # OUTPUT: «0» | |
ok 501 - doc/Language/operators.pod6 chunk 136 compiles | |
# my $foo = 42; | |
# $foo min= 0 # read as: $foo decreases to 0 | |
ok 502 - doc/Language/operators.pod6 chunk 137 compiles | |
# my $foo = -42; | |
# $foo max= 0 # read as: $foo increases to 0 | |
ok 503 - doc/Language/operators.pod6 chunk 138 compiles | |
# sub infix:<ff>(Mu $a, Mu $b) | |
ok 504 - doc/Language/operators.pod6 chunk 139 compiles | |
# my $excerpt = q:to/END/; | |
# Here's some unimportant text. | |
# =begin code | |
# This code block is what we're after. | |
# We'll use 'ff' to get it. | |
# =end code | |
# More unimportant text. | |
# END | |
# my @codelines = gather for $excerpt.lines { | |
# take $_ if "=begin code" ff "=end code" | |
# } | |
# # this will print four lines, starting with "=begin code" and ending with | |
# # "=end code" | |
# say @codelines.join("\n"); | |
ok 505 - doc/Language/operators.pod6 chunk 140 compiles | |
# for <AB C D B E F> { | |
# say $_ if /A/ ff /B/; # OUTPUT: «AB» | |
# } | |
ok 506 - doc/Language/operators.pod6 chunk 141 compiles | |
# for <A B C D E> { | |
# say $_ if /C/ ff *; # OUTPUT: «CDE» | |
# } | |
ok 507 - doc/Language/operators.pod6 chunk 142 compiles | |
# sub infix:<^ff>(Mu $a, Mu $b) | |
ok 508 - doc/Language/operators.pod6 chunk 143 compiles | |
# my @list = <A B C>; | |
# say $_ if /A/ ff /C/ for @list; # OUTPUT: «ABC» | |
# say $_ if /A/ ^ff /C/ for @list; # OUTPUT: «BC» | |
ok 509 - doc/Language/operators.pod6 chunk 144 compiles | |
# sub infix:<ff^>(Mu $a, Mu $b) | |
ok 510 - doc/Language/operators.pod6 chunk 145 compiles | |
# my @list = <A B C>; | |
# say $_ if /A/ ff /C/ for @list; # OUTPUT: «ABC» | |
# say $_ if /A/ ff^ /C/ for @list; # OUTPUT: «AB» | |
ok 511 - doc/Language/operators.pod6 chunk 146 compiles | |
# sub infix:<^ff^>(Mu $a, Mu $b) | |
ok 512 - doc/Language/operators.pod6 chunk 147 compiles | |
# my @list = <A B C>; | |
# say $_ if /A/ ff /C/ for @list; # OUTPUT: «ABC» | |
# say $_ if /A/ ^ff^ /C/ for @list; # OUTPUT: «B» | |
ok 513 - doc/Language/operators.pod6 chunk 148 compiles | |
# sub infix:<fff>(Mu $a, Mu $b) | |
ok 514 - doc/Language/operators.pod6 chunk 149 compiles | |
# for <AB C D B E F> { | |
# say $_ if /A/ fff /B/; # OUTPUT: «ABCDB» | |
# } | |
ok 515 - doc/Language/operators.pod6 chunk 150 compiles | |
# sub infix:<^fff>(Mu $a, Mu $b) | |
ok 516 - doc/Language/operators.pod6 chunk 151 compiles | |
# my @list = <A B C>; | |
# say $_ if /A/ fff /C/ for @list; # OUTPUT: «ABC» | |
# say $_ if /A/ ^fff /C/ for @list; # OUTPUT: «BC» | |
ok 517 - doc/Language/operators.pod6 chunk 152 compiles | |
# sub infix:<fff^>(Mu $a, Mu $b) | |
ok 518 - doc/Language/operators.pod6 chunk 153 compiles | |
# my @list = <A B C>; | |
# say $_ if /A/ fff /C/ for @list; # OUTPUT: «ABC» | |
# say $_ if /A/ fff^ /C/ for @list; # OUTPUT: «AB» | |
ok 519 - doc/Language/operators.pod6 chunk 154 compiles | |
# sub infix:<^fff^>(Mu $a, Mu $b) | |
ok 520 - doc/Language/operators.pod6 chunk 155 compiles | |
# my @list = <A B C>; | |
# say $_ if /A/ fff /C/ for @list; # OUTPUT: «ABC» | |
# say $_ if /A/ ^fff^ /C/ for @list; # OUTPUT: «B» | |
ok 521 - doc/Language/operators.pod6 chunk 156 compiles | |
# sub infix:«=>»($key, Mu $value --> Pair:D) | |
ok 522 - doc/Language/operators.pod6 chunk 157 compiles | |
# my $p = a => 1; | |
# say $p.key; # OUTPUT: «a» | |
# say $p.value; # OUTPUT: «1» | |
ok 523 - doc/Language/operators.pod6 chunk 158 compiles | |
# multi sub prefix:<not>(Mu $x --> Bool:D) | |
ok 524 - doc/Language/operators.pod6 chunk 159 compiles | |
# multi sub prefix:<so>(Mu $x --> Bool:D) | |
ok 525 - doc/Language/operators.pod6 chunk 160 compiles | |
# sub infix:<,>(*@a --> List:D) is assoc<list> | |
ok 526 - doc/Language/operators.pod6 chunk 161 compiles | |
# substr('abc': 1); # same as 'abc'.substr(1) | |
ok 527 - doc/Language/operators.pod6 chunk 162 compiles | |
# sub infix:<Z>(**@lists --> Seq:D) is assoc<chain> | |
ok 528 - doc/Language/operators.pod6 chunk 163 compiles | |
# say (1, 2 Z <a b c> Z <+ ->).perl; # OUTPUT: «((1, "a", "+"), (2, "b", "-")).Seq» | |
# for <a b c> Z <1 2 3> -> [$l, $r] { | |
# say "$l:$r" | |
# } | |
# # OUTPUT: «a:1b:2c:3» | |
ok 529 - doc/Language/operators.pod6 chunk 164 compiles | |
# say 100, 200 Z+ 42, 23; # OUTPUT: «(142 223)» | |
# say 1..3 Z~ <a b c> Z~ 'x' xx 3; # OUTPUT: «(1ax 2bx 3cx)» | |
ok 530 - doc/Language/operators.pod6 chunk 165 compiles | |
# sub infix:<X>(**@lists --> List:D) | |
ok 531 - doc/Language/operators.pod6 chunk 166 compiles | |
# 1..3 X <a b c> X 9 | |
# # produces ((1 a 9) (1 b 9) (1 c 9) | |
# # (2 a 9) (2 b 9) (2 c 9) | |
# # (3 a 9) (3 b 9) (3 c 9)) | |
ok 532 - doc/Language/operators.pod6 chunk 167 compiles | |
# 1..3 X~ <a b c> X~ 9 | |
# # produces (1a9 1b9 1c9 2a9 2b9 2c9 3a9 3b9 3c9) | |
ok 533 - doc/Language/operators.pod6 chunk 168 compiles | |
# multi sub infix:<...>(**@) is assoc<list> | |
# multi sub infix:<...^>(**@) is assoc<list> | |
ok 534 - doc/Language/operators.pod6 chunk 169 compiles | |
# say 1 ... 4; # OUTPUT: «(1 2 3 4)» | |
# say 4 ... 1; # OUTPUT: «(4 3 2 1)» | |
# say 'a' ... 'e'; # OUTPUT: «(a b c d e)» | |
# say 'e' ... 'a'; # OUTPUT: «(e d c b a)» | |
ok 535 - doc/Language/operators.pod6 chunk 170 compiles | |
# say (1 ... *)[^5]; # OUTPUT: «(1 2 3 4 5)» | |
ok 536 - doc/Language/operators.pod6 chunk 171 compiles | |
# say (1, 1, -> $a, $b { $a + $b } ... *)[^8]; # OUTPUT: «(1 1 2 3 5 8 13 21)» | |
# # same but shorter | |
# say (1, 1, *+* ... *)[^8]; # OUTPUT: «(1 1 2 3 5 8 13 21)» | |
ok 537 - doc/Language/operators.pod6 chunk 172 compiles | |
# say 5, { $_ * 2 } ... 40; # OUTPUT: «5 10 20 40» | |
ok 538 - doc/Language/operators.pod6 chunk 173 compiles | |
# say 2, 4, 6 ... 12; # OUTPUT: «(2 4 6 8 10 12)» | |
# say 1, 2, 4 ... 32; # OUTPUT: «(1 2 4 8 16 32)» | |
ok 539 - doc/Language/operators.pod6 chunk 174 compiles | |
# say 1, 1, *+* ...^ *>= 100; | |
ok 540 - doc/Language/operators.pod6 chunk 175 compiles | |
# my $end = 4; | |
# say 1, 2, 4, 8, 16 ... $end; | |
# # OUTPUT: «(1 2 4)» | |
ok 541 - doc/Language/operators.pod6 chunk 176 compiles | |
# my $a = 42; | |
# my $b = $a; | |
# $b++; | |
# say $a; | |
ok 542 - doc/Language/operators.pod6 chunk 177 compiles | |
# my $a = 42; | |
# my $b := $a; | |
# $b++; | |
# say $a; | |
ok 543 - doc/Language/operators.pod6 chunk 178 compiles | |
# say [+] 1, 2, 3; # 1 + 2 + 3 = 6 | |
# my @a = (5, 6); | |
# say [*] @a; # 5 * 6 = 30 | |
ok 544 - doc/Language/operators.pod6 chunk 179 compiles | |
# say [-] 4, 3, 2; # 4-3-2 = (4-3)-2 = -1 | |
# say [**] 4, 3, 2; # 4**3**2 = 4**(3**2) = 262144 | |
ok 545 - doc/Language/operators.pod6 chunk 180 compiles | |
Potential difficulties: | |
Redeclaration of symbol '@result' | |
at /Users/williamcoleda/sandbox/doc/EVAL_545:10 | |
------> [32mmy @result[33m⏏[31m = ([0m | |
Redeclaration of symbol '@result' | |
at /Users/williamcoleda/sandbox/doc/EVAL_545:18 | |
------> [32mmy @result[33m⏏[31m =[0m | |
Redeclaration of symbol '@result' | |
at /Users/williamcoleda/sandbox/doc/EVAL_545:25 | |
------> [32mmy @result[33m⏏[31m =[0m | |
Redeclaration of symbol '@result' | |
at /Users/williamcoleda/sandbox/doc/EVAL_545:34 | |
------> [32mmy @result[33m⏏[31m =[0m | |
# # Traditional structure, read bottom-to-top | |
# my @result = | |
# sort # (4) Sort, result is <Earth People> | |
# grep { /<[PE]>/ }, # (3) Look for P or E | |
# map { .tc }, # (2) Capitalize the words | |
# <people of earth>; # (1) Start with the input | |
# # Feed (left-to-right) with parentheses, read top-to-bottom | |
# my @result = ( | |
# <people of earth> # (1) Start with the input | |
# ==> map({ .tc }) # (2) Capitalize the words | |
# ==> grep /<[PE]>/ # (3) Look for P or E | |
# ==> sort # (4) Sort, result is <Earth People> | |
# ); | |
# # For illustration, method chaining equivalent, read top-to-bottom | |
# my @result = | |
# <people of earth> # (1) Start with the input | |
# .map({ .tc }) # (2) Capitalize the words | |
# .grep(/<[PE]>/) # (3) Look for P or E | |
# .sort; # (4) Sort, result is <Earth People> | |
# # To assign without the need of parentheses use another feed operator | |
# my @result = | |
# <people of earth> | |
# ==> map({ .tc }) | |
# ==> grep /<[PE]>/ | |
# ==> sort() | |
# ==> @result; | |
# # It can be useful to capture a partial result, however, unlike | |
# # the leftward feed operator, it does require parentheses or a semicolon | |
# my @result = | |
# <people of earth> | |
# ==> map({ .tc }) | |
# ==> my @caps; @caps # also could wrap in parentheses instead | |
# ==> grep /<[PE]>/ | |
# ==> sort() | |
# ==> @result; | |
ok 546 - doc/Language/operators.pod6 chunk 181 compiles | |
Potential difficulties: | |
Redeclaration of symbol '@result' | |
at /Users/williamcoleda/sandbox/doc/EVAL_546:10 | |
------> [32mmy @result[33m⏏[31m = ([0m | |
Redeclaration of symbol '@result' | |
at /Users/williamcoleda/sandbox/doc/EVAL_546:19 | |
------> [32mmy @result[33m⏏[31m<EOL>[0m | |
Redeclaration of symbol '@result' | |
at /Users/williamcoleda/sandbox/doc/EVAL_546:26 | |
------> [32mmy @result[33m⏏[31m<EOL>[0m | |
# # Traditional structure, read bottom-to-top | |
# my @result = | |
# sort # (4) Sort, result is <Earth People> | |
# grep { /<[PE]>/ }, # (3) Look for P or E | |
# map { .tc }, # (2) Capitalize the words | |
# <people of earth>; # (1) Start with the input | |
# # Feed (right-to-left) with parentheses, read bottom-to-top | |
# my @result = ( | |
# sort() # (4) Sort, result is <Earth People> | |
# <== grep({ /<[PE]>/ }) # (3) Look for P or E | |
# <== map({ .tc }) # (2) Capitalize the words | |
# <== <people of earth> # (1) Start with the input | |
# ); | |
# # To assign without parentheses, use another feed operator | |
# my @result | |
# <== sort() # (4) Sort, result is <Earth People> | |
# <== grep({ /<[PE]>/ }) # (3) Look for P or E | |
# <== map({ .tc }) # (2) Capitalize the words | |
# <== <people of earth>; # (1) Start with the input | |
# # It can be useful to capture a partial result | |
# my @result | |
# <== sort() | |
# <== grep({ /<[PE]>/ }) | |
# <== my @caps # unlike ==>, there's no need for additional statement | |
# <== map({ .tc }) | |
# <== <people of earth>; | |
ok 547 - doc/Language/operators.pod6 chunk 182 compiles | |
# # existing code generically matches a two arg foo call: | |
# multi sub foo(Any $a, Any $b) { ... } | |
# # new variant takes over for a foo("quux", 42) call: | |
# multi sub foo("quux", Int $b) { ... } | |
ok 548 - doc/Language/performance.pod6 chunk 1 compiles | |
# use v6.c; | |
ok 549 - doc/Language/pragmas.pod6 chunk 1 compiles | |
# use nqp; | |
# nqp::say("hello world"); | |
ok 550 - doc/Language/pragmas.pod6 chunk 2 compiles | |
WARNINGS for /Users/williamcoleda/sandbox/doc/EVAL_550: | |
Useless use of constant string "Very plain" in sink context (line 2) | |
Useless use of constant string "There are no backslashes here, only lots of $$$>!" in sink context (line 6) | |
Useless use of constant string "This back\\slash stays" in sink context (lines 3, 4) | |
Useless use of constant string "No $interpolation {here}!" in sink context (line 8) | |
Useless use of constant string "This is not a closing curly brace → }, but this is → " in sink context (line 5) | |
Useless use of constant string "(Just kidding. There's no money in that string)" in sink context (line 7) | |
# 'Very plain'; | |
# q[This back\slash stays]; | |
# q[This back\\slash stays]; # Identical output | |
# q{This is not a closing curly brace → \}, but this is → }; | |
# Q :q $There are no backslashes here, only lots of \$\$\$>!$; | |
# '(Just kidding. There\'s no money in that string)'; | |
# 'No $interpolation {here}!'; | |
# Q:q!Just a literal "\n" here!; | |
ok 551 - doc/Language/quoting.pod6 chunk 1 compiles | |
# say "abc&uc("def")ghi"; | |
# # OUTPUT: «abcDEFghi» | |
ok 552 - doc/Language/quoting.pod6 chunk 2 compiles | |
# my %h = :1st; say "abc%h<st>ghi"; | |
# # OUTPUT: «abc1ghi» | |
ok 553 - doc/Language/quoting.pod6 chunk 3 compiles | |
Potential difficulties: | |
Redeclaration of symbol '$s' | |
at /Users/williamcoleda/sandbox/doc/EVAL_553:5 | |
------> [32mmy $s[33m⏏[31m = "I really \x[2661,2665,2764,1f495] Pe[0m | |
# my $s = "I \x[2665] Perl 6!"; | |
# dd $s; | |
# # OUTPUT: «Str $s = "I ♥ Perl 6!"» | |
# my $s = "I really \x[2661,2665,2764,1f495] Perl 6!"; | |
# dd $s; | |
# # OUTPUT: «Str $s = "I really ♡♥❤💕 Perl 6!"» | |
ok 554 - doc/Language/quoting.pod6 chunk 4 compiles | |
# my $s = "Camelia \c[BROKEN HEART] my \c[HEAVY BLACK HEART]!"; | |
# dd $s; | |
# # OUTPUT: «Str $s = "Str $s = "Camelia 💔 my ❤!"» | |
ok 555 - doc/Language/quoting.pod6 chunk 5 compiles | |
# my @directions = 'left', 'right,', 'up', 'down'; | |
ok 556 - doc/Language/quoting.pod6 chunk 6 compiles | |
# my @directions = qw|left right up down|; | |
ok 557 - doc/Language/quoting.pod6 chunk 7 compiles | |
# say <42 4/2 1e6 1+1i abc>.perl; | |
# # OUTPUT: «(IntStr.new(42, "42"), RatStr.new(2.0, "4/2"), NumStr.new(1000000e0, "1e6"), ComplexStr.new(<1+1i>, "1+1i"), "abc")» | |
ok 558 - doc/Language/quoting.pod6 chunk 8 compiles | |
# say <42/10>.^name; # OUTPUT: «Rat» | |
# say <1+42i>.^name; # OUTPUT: «Complex» | |
# say < 42/10 >.^name; # OUTPUT: «RatStr» | |
# say < 1+42i >.^name; # OUTPUT: «ComplexStr» | |
ok 559 - doc/Language/quoting.pod6 chunk 9 compiles | |
# say qw{"a b" c}.perl; # OUTPUT: «("\"a", "b\"", "c")» | |
ok 560 - doc/Language/quoting.pod6 chunk 10 compiles | |
# say qww{"a b" c}.perl; # OUTPUT: «("a b", "c")» | |
ok 561 - doc/Language/quoting.pod6 chunk 11 compiles | |
# my $a = 42; say qw{$a b c}; # OUTPUT: «$a b c» | |
ok 562 - doc/Language/quoting.pod6 chunk 12 compiles | |
# my $a = 42; | |
# my @list = qqw{$a b c}; | |
# say @list; # OUTPUT: «42 b c» | |
ok 563 - doc/Language/quoting.pod6 chunk 13 compiles | |
# my $a = "a b"; | |
# my @list = qqw{$a c}; | |
# .say for @list; # OUTPUT: «abc» | |
ok 564 - doc/Language/quoting.pod6 chunk 14 compiles | |
# my $a = 42; say qqw{"$a b" c}.perl; # OUTPUT: «("\"42", "b\"", "c")» | |
ok 565 - doc/Language/quoting.pod6 chunk 15 compiles | |
# my $a = 42; say qqww{"$a b" c}.perl; # OUTPUT: «("42 b", "c")» | |
ok 566 - doc/Language/quoting.pod6 chunk 16 compiles | |
Potential difficulties: | |
Redeclaration of symbol '$a' | |
at /Users/williamcoleda/sandbox/doc/EVAL_566:3 | |
------> [32mmy $a[33m⏏[31m = 42; say «"$a b" c».perl; # OUTPUT[0m | |
# my $a = 42; say <<"$a b" c>>.perl; # OUTPUT: «("42 b", "c")» | |
# my $a = 42; say «"$a b" c».perl; # OUTPUT: «("42 b", "c")» | |
ok 567 - doc/Language/quoting.pod6 chunk 17 compiles | |
# my $a = "1 2"; | |
# say qqww{"$a" $a}.perl; # OUTPUT: «("1 2", "1", "2")» | |
# my $b = "1 \"2 3\""; | |
# say qqww{"$b" $b}.perl; # OUTPUT: «("1 \"2 3\"", "1", "\"2", "3\"")» | |
ok 568 - doc/Language/quoting.pod6 chunk 18 compiles | |
# my $world = "there"; | |
# say qx{echo "hello $world"} | |
ok 569 - doc/Language/quoting.pod6 chunk 19 compiles | |
# my $output = qx{echo "hello!"}; | |
# say $output; # OUTPUT: «hello!» | |
ok 570 - doc/Language/quoting.pod6 chunk 20 compiles | |
# my $world = "there"; | |
# say qqx{echo "hello $world"}; # OUTPUT: «hello there» | |
ok 571 - doc/Language/quoting.pod6 chunk 21 compiles | |
# my $word = "cool"; | |
# my $option = "-i"; | |
# my $file = "/usr/share/dict/words"; | |
# my $output = qqx{grep $option $word $file}; | |
# # runs the command: grep -i cool /usr/share/dict/words | |
# say $output; # OUTPUT: «CooleyCooley'sCoolidgeCoolidge'scool...» | |
ok 572 - doc/Language/quoting.pod6 chunk 22 compiles | |
# say q:to/END/; | |
# Here is | |
# some multi-line | |
# string | |
# END | |
ok 573 - doc/Language/quoting.pod6 chunk 23 compiles | |
# say q:to/END/; | |
# Here is | |
# some multi line | |
# string | |
# END | |
ok 574 - doc/Language/quoting.pod6 chunk 24 compiles | |
# my $f = 'db.7.3.8'; | |
# my $s = qq:to/END/; | |
# option \{ | |
# file "$f"; | |
# }; | |
# END | |
# say $s; | |
ok 575 - doc/Language/quoting.pod6 chunk 25 compiles | |
# my ($first, $second) = qq:to/END1/, qq:to/END2/; | |
# FIRST | |
# MULTILINE | |
# STRING | |
# END1 | |
# SECOND | |
# MULTILINE | |
# STRING | |
# END2 | |
ok 576 - doc/Language/quoting.pod6 chunk 26 compiles | |
# m/abc/; # a regex that is immediately matched against $_ | |
# rx/abc/; # a Regex object | |
# /abc/; # a Regex object | |
ok 577 - doc/Language/regexes.pod6 chunk 1 compiles | |
# m{abc}; | |
# rx{abc}; | |
ok 578 - doc/Language/regexes.pod6 chunk 2 compiles | |
# if 'properly' ~~ m/ perl / { | |
# say "'properly' contains 'perl'"; | |
# } | |
ok 579 - doc/Language/regexes.pod6 chunk 3 compiles | |
# / 'two words' /; # matches 'two words' including the blank | |
# / "a:b" /; # matches 'a:b' including the colon | |
# / '#' /; # matches a hash character | |
ok 580 - doc/Language/regexes.pod6 chunk 4 compiles | |
# if 'abcdef' ~~ / de / { | |
# say ~$/; # OUTPUT: «de» | |
# say $/.prematch; # OUTPUT: «abc» | |
# say $/.postmatch; # OUTPUT: «f» | |
# say $/.from; # OUTPUT: «3» | |
# say $/.to; # OUTPUT: «5» | |
# }; | |
ok 581 - doc/Language/regexes.pod6 chunk 5 compiles | |
# 'perl' ~~ /per./; # matches the whole string | |
# 'perl' ~~ / per . /; # the same; whitespace is ignored | |
# 'perl' ~~ / pe.l /; # the . matches the r | |
# 'speller' ~~ / pe.l/; # the . matches the first l | |
ok 582 - doc/Language/regexes.pod6 chunk 6 compiles | |
# 'perl' ~~ /. per /; | |
ok 583 - doc/Language/regexes.pod6 chunk 7 compiles | |
# 'ab42' ~~ /\d/ and say ~$/; # OUTPUT: «4» | |
# 'ab42' ~~ /\D/ and say ~$/; # OUTPUT: «a» | |
ok 584 - doc/Language/regexes.pod6 chunk 8 compiles | |
# if 'contains a word starting with "w"' ~~ / w \S+ / { | |
# say ~$/; # OUTPUT: «word» | |
# } | |
ok 585 - doc/Language/regexes.pod6 chunk 9 compiles | |
# "a".uniprop('Script'); # OUTPUT: «Latin» | |
# "a" ~~ / <:Script<Latin>> /; | |
# "a".uniprop('Block'); # OUTPUT: «Basic Latin» | |
# "a" ~~ / <:Block('Basic Latin')> /; | |
ok 586 - doc/Language/regexes.pod6 chunk 10 compiles | |
# 'perl6' ~~ m{\w+(<:Ll+:N>)} # OUTPUT: «0 => 「6」» | |
ok 587 - doc/Language/regexes.pod6 chunk 11 compiles | |
# "abacabadabacaba" ~~ / <[ a .. c 1 2 3 ]> /; | |
# # Unicode hex codepoint range | |
# "ÀÁÂÃÄÅÆ" ~~ / <[ \x[00C0] .. \x[00C6] ]> /; | |
# # Unicode named codepoint range | |
# "ÀÁÂÃÄÅÆ" ~~ / <[ \c[LATIN CAPITAL LETTER A WITH GRAVE] .. \c[LATIN CAPITAL LETTER AE] ]> /; | |
ok 588 - doc/Language/regexes.pod6 chunk 12 compiles | |
# / <[\d] - [13579]> /; | |
# # starts with \d and removes odd ASCII digits, but not quite the same as | |
# / <[02468]> /; | |
# # because the first one also contains "weird" unicodey digits | |
ok 589 - doc/Language/regexes.pod6 chunk 13 compiles | |
# say 'no quotes' ~~ / <-[ " ]> + /; # matches characters except " | |
ok 590 - doc/Language/regexes.pod6 chunk 14 compiles | |
# say '"in quotes"' ~~ / '"' <-[ " ]> * '"'/; | |
ok 591 - doc/Language/regexes.pod6 chunk 15 compiles | |
# / <+[123]> / # same as <[123]> | |
ok 592 - doc/Language/regexes.pod6 chunk 16 compiles | |
# / \w+ '=' \w+ / | |
ok 593 - doc/Language/regexes.pod6 chunk 17 compiles | |
# / a \s* b / | |
ok 594 - doc/Language/regexes.pod6 chunk 18 compiles | |
# say so 'a' ~~ /a ** 2..5/; # OUTPUT: «False» | |
# say so 'aaa' ~~ /a ** 2..5/; # OUTPUT: «True» | |
ok 595 - doc/Language/regexes.pod6 chunk 19 compiles | |
# say so 'aaaaa' ~~ /a ** 5/; # OUTPUT: «True» | |
ok 596 - doc/Language/regexes.pod6 chunk 20 compiles | |
# say so 'a' ~~ /a ** 1^..^6/; # OUTPUT: «False» -- there are 2 to 5 'a's in a row | |
# say so 'aaaa' ~~ /a ** 1^..^6/; # OUTPUT: «True» | |
ok 597 - doc/Language/regexes.pod6 chunk 21 compiles | |
# say so 'aaa' ~~ /a ** ^6/; # OUTPUT: «True» -- there are 0 to 5 'a's in a row | |
ok 598 - doc/Language/regexes.pod6 chunk 22 compiles | |
# say so 'aaaa' ~~ /a ** 1^..*/; # OUTPUT: «True» -- there are 2 or more 'a's in a row | |
ok 599 - doc/Language/regexes.pod6 chunk 23 compiles | |
# 'abababa' ~~ /a .* a/ && say ~$/; # OUTPUT: «abababa» | |
ok 600 - doc/Language/regexes.pod6 chunk 24 compiles | |
# 'abababa' ~~ /a .*? a/ && say ~$/; # OUTPUT: «aba» | |
ok 601 - doc/Language/regexes.pod6 chunk 25 compiles | |
# say so 'abababa' ~~ /a .* aba/; # OUTPUT: «True» | |
# say so 'abababa' ~~ /a .*: aba/; # OUTPUT: «False» | |
ok 602 - doc/Language/regexes.pod6 chunk 26 compiles | |
# / '[' \w+ ']' || \S+ \s* '=' \s* \S* / | |
ok 603 - doc/Language/regexes.pod6 chunk 27 compiles | |
# say ('abc' ~~ / a | .b /).Str; # OUTPUT: «ab» | |
ok 604 - doc/Language/regexes.pod6 chunk 28 compiles | |
# say so 'properly' ~~ / perl/; # OUTPUT: «True» | |
# # ^^^^ | |
ok 605 - doc/Language/regexes.pod6 chunk 29 compiles | |
# say so 'properly' ~~ / perl/; # OUTPUT: «True» | |
# say so 'properly' ~~ /^ perl/; # OUTPUT: «False» | |
# say so 'perly' ~~ /^ perl/; # OUTPUT: «True» | |
# say so 'perl' ~~ /^ perl/; # OUTPUT: «True» | |
ok 606 - doc/Language/regexes.pod6 chunk 30 compiles | |
# say so 'use perl' ~~ / perl /; # OUTPUT: «True» | |
# say so 'use perl' ~~ / perl $/; # OUTPUT: «True» | |
# say so 'perly' ~~ / perl $/; # OUTPUT: «False» | |
ok 607 - doc/Language/regexes.pod6 chunk 31 compiles | |
# say so 'use perl' ~~ /^ perl $/; # OUTPUT: «False» | |
# say so 'perl' ~~ /^ perl $/; # OUTPUT: «True» | |
ok 608 - doc/Language/regexes.pod6 chunk 32 compiles | |
# my $str = q:to/EOS/; | |
# Keep it secret | |
# and keep it safe | |
# EOS | |
# say so $str ~~ /safe $/; # OUTPUT: «True» -- 'safe' is at the end of the string | |
# say so $str ~~ /secret $/; # OUTPUT: «False» -- 'secret' is at the end of a line -- not the string | |
# say so $str ~~ /^Keep /; # OUTPUT: «True» -- 'Keep' is at the start of the string | |
# say so $str ~~ /^and /; # OUTPUT: «False» -- 'and' is at the start of a line -- not the string | |
ok 609 - doc/Language/regexes.pod6 chunk 33 compiles | |
# my $str = q:to/EOS/; | |
# There was a young man of Japan | |
# Whose limericks never would scan. | |
# When asked why this was, | |
# He replied "It's because | |
# I always try to fit as many syllables into the last line as ever I possibly can." | |
# EOS | |
# say so $str ~~ /^^ There/; # OUTPUT: «True» -- start of string | |
# say so $str ~~ /^^ limericks/; # OUTPUT: «False» -- not at the start of a line | |
# say so $str ~~ /^^ I/; # OUTPUT: «True» -- start of the last line | |
# say so $str ~~ /^^ When/; # OUTPUT: «False» -- there are blanks between | |
# # start of line and the "When" | |
# say so $str ~~ / Japan $$/; # OUTPUT: «True» -- end of first line | |
# say so $str ~~ / scan $$/; # OUTPUT: «False» -- there's a . between "scan" | |
# # and the end of line | |
# say so $str ~~ / '."' $$/; # OUTPUT: «True» -- at the last line | |
ok 610 - doc/Language/regexes.pod6 chunk 34 compiles | |
# my $str = 'The quick brown fox'; | |
# say so $str ~~ /br/; # OUTPUT: «True» | |
# say so $str ~~ /<< br/; # OUTPUT: «True» | |
# say so $str ~~ /br >>/; # OUTPUT: «False» | |
# say so $str ~~ /own/; # OUTPUT: «True» | |
# say so $str ~~ /<< own/; # OUTPUT: «False» | |
# say so $str ~~ /own >>/; # OUTPUT: «True» | |
ok 611 - doc/Language/regexes.pod6 chunk 35 compiles | |
# my $str = 'The quick brown fox'; | |
# say so $str ~~ /« own/; # OUTPUT: «False» | |
# say so $str ~~ /own »/; # OUTPUT: «True» | |
ok 612 - doc/Language/regexes.pod6 chunk 36 compiles | |
# say 1 + 4 * 2; # 9, parsed as 1 + (4 * 2) | |
# say (1 + 4) * 2; # OUTPUT: «10» | |
ok 613 - doc/Language/regexes.pod6 chunk 37 compiles | |
Potential difficulties: | |
Space is not significant here; please use quotes or :s (:sigspace) modifier (or, to suppress this warning, omit the space, or otherwise change the spacing) | |
at /Users/williamcoleda/sandbox/doc/EVAL_613:2 | |
------> [32m class :: {/ a || b[33m⏏[31m c /; # matches 'a' or 'bc'[0m | |
# / a || b c /; # matches 'a' or 'bc' | |
# / ( a || b ) c /; # matches 'ac' or 'bc' | |
ok 614 - doc/Language/regexes.pod6 chunk 38 compiles | |
Potential difficulties: | |
Space is not significant here; please use quotes or :s (:sigspace) modifier (or, to suppress this warning, omit the space, or otherwise change the spacing) | |
at /Users/williamcoleda/sandbox/doc/EVAL_614:2 | |
------> [32m class :: {/ a[33m⏏[31m b+ /; # matches an 'a' follo[0m | |
Space is not significant here; please use quotes or :s (:sigspace) modifier (or, to suppress this warning, omit the space, or otherwise change the spacing) | |
at /Users/williamcoleda/sandbox/doc/EVAL_614:3 | |
------> [32m/ (a[33m⏏[31m b)+ /; # matches one or more s[0m | |
# / a b+ /; # matches an 'a' followed by one or more 'b's | |
# / (a b)+ /; # matches one or more sequences of 'ab' | |
# / (a || b)+ /; # matches a sequence of 'a's and 'b's, at least one long | |
ok 615 - doc/Language/regexes.pod6 chunk 39 compiles | |
# my $str = 'number 42'; | |
# if $str ~~ /'number ' (\d+) / { | |
# say "The number is $0"; # the number is 42 | |
# # or | |
# say "The number is $/[0]"; # the number is 42 | |
# } | |
ok 616 - doc/Language/regexes.pod6 chunk 40 compiles | |
# if 'abc' ~~ /(a) b (c)/ { | |
# say "0: $0; 1: $1"; # OUTPUT: «0: a; 1: c» | |
# } | |
ok 617 - doc/Language/regexes.pod6 chunk 41 compiles | |
# if 'abc' ~~ /(a) b (c)/ { | |
# say $/.list.join: ', ' # OUTPUT: «a, c» | |
# } | |
ok 618 - doc/Language/regexes.pod6 chunk 42 compiles | |
# if 'abc' ~~ / [a||b] (c) / { | |
# say ~$0; # OUTPUT: «c» | |
# } | |
ok 619 - doc/Language/regexes.pod6 chunk 43 compiles | |
# / (x) (y) || (a) (.) (.) / | |
# # $0 $1 $0 $1 $2 | |
ok 620 - doc/Language/regexes.pod6 chunk 44 compiles | |
# if 'abc' ~~ /(x)(y) || (a)(.)(.)/ { | |
# say ~$1; # b | |
# } | |
ok 621 - doc/Language/regexes.pod6 chunk 45 compiles | |
# $_ = 'abcd'; | |
# if / a [ b (.) || (x) (y) ] (.) / { | |
# # $0 $0 $1 $2 | |
# say ~$2; # d | |
# } | |
ok 622 - doc/Language/regexes.pod6 chunk 46 compiles | |
# if 'abc' ~~ / ( a (.) (.) ) / { | |
# say "Outer: $0"; # Outer: abc | |
# say "Inner: $0[0] and $0[1]"; # Inner: b and c | |
# } | |
ok 623 - doc/Language/regexes.pod6 chunk 47 compiles | |
# if 'abc' ~~ / $<myname> = [ \w+ ] / { | |
# say ~$<myname> # OUTPUT: «abc» | |
# } | |
ok 624 - doc/Language/regexes.pod6 chunk 48 compiles | |
# if 'abc-abc-abc' ~~ / $<string>=( [ $<part>=[abc] ]* % '-' ) / { | |
# say ~$<string>; # OUTPUT: «abc-abc-abc» | |
# say ~$<string><part>; # OUTPUT: «[abc, abc, abc]» | |
# } | |
ok 625 - doc/Language/regexes.pod6 chunk 49 compiles | |
# if 'count=23' ~~ / $<variable>=\w+ '=' $<value>=\w+ / { | |
# my %h = $/.hash; | |
# say %h.keys.sort.join: ', '; # OUTPUT: «value, variable» | |
# say %h.values.sort.join: ', '; # OUTPUT: «23, count» | |
# for %h.kv -> $k, $v { | |
# say "Found value '$v' with key '$k'"; | |
# # outputs two lines: | |
# # Found value 'count' with key 'variable' | |
# # Found value '23' with key 'value' | |
# } | |
# } | |
ok 626 - doc/Language/regexes.pod6 chunk 50 compiles | |
# s|replace|with|; | |
# s!replace!with!; | |
# s,replace,with,; | |
ok 627 - doc/Language/regexes.pod6 chunk 51 compiles | |
# $_ = 'The Replacements'; | |
# s/Replace/Entrap/; | |
# .say; # OUTPUT: «The Entrapments» | |
ok 628 - doc/Language/regexes.pod6 chunk 52 compiles | |
# $_ = 'Space: 1999'; | |
# s/Space\:/Party like it's/; | |
# .say # OUTPUT: «Party like it's 1999» | |
ok 629 - doc/Language/regexes.pod6 chunk 53 compiles | |
# $_ = 'There can be twly two'; | |
# s/tw/on/; # replace 'tw' with 'on' once | |
# .say; # OUTPUT: «there can be only two» | |
ok 630 - doc/Language/regexes.pod6 chunk 54 compiles | |
# $_ = "Blake's 9"; | |
# s/\d+/7/; # replace any sequence of digits with '7' | |
# .say; # OUTPUT: «Blake's 7» | |
ok 631 - doc/Language/regexes.pod6 chunk 55 compiles | |
# $_ = '2016-01-23 18:09:00'; | |
# s/ (\d+)\-(\d+)\-(\d+) /today/; # replace YYYY-MM-DD with 'today' | |
# .say; # OUTPUT: «today 18:09:00» | |
# "$1-$2-$0".say; # OUTPUT: «01-23-2016» | |
# "$/[1]-$/[2]-$/[0]".say; # OUTPUT: «01-23-2016» | |
ok 632 - doc/Language/regexes.pod6 chunk 56 compiles | |
# $_ = '2016-01-23 18:09:00'; | |
# s/ (\d+)\-(\d+)\-(\d+) /$1-$2-$0/; # transform YYYY-MM-DD to MM-DD-YYYY | |
# .say; # OUTPUT: «01-23-2016 18:09:00» | |
ok 633 - doc/Language/regexes.pod6 chunk 57 compiles | |
# $_ = '18:38'; | |
# s/(\d+)\:(\d+)/{$0 % 12}\:$1 {$0 < 12 ?? 'AM' !! 'PM'}/; | |
# .say; # OUTPUT: «6:38 PM» | |
ok 634 - doc/Language/regexes.pod6 chunk 58 compiles | |
# $_ = q{I can say "banana" but I don't know when to stop}; | |
# s:g/na/nana,/; # substitute 'nana,' for 'na' | |
# .say; # OUTPUT: «I can say "banana,nana," but I don't ...» | |
ok 635 - doc/Language/regexes.pod6 chunk 59 compiles | |
# $_ = 'Fruit'; | |
# s/fruit/vegetable/; | |
# .say; # OUTPUT: «Fruit» | |
# s:i/fruit/vegetable/; | |
# .say; # OUTPUT: «vegetable» | |
ok 636 - doc/Language/regexes.pod6 chunk 60 compiles | |
# / '(' ~ ')' <expression> / | |
ok 637 - doc/Language/regexes.pod6 chunk 61 compiles | |
# / '(' <expression> ')' / | |
ok 638 - doc/Language/regexes.pod6 chunk 62 compiles | |
# grammar A { token TOP { '[' ~ ']' \w+ }; | |
# method FAILGOAL($goal) { | |
# die "Cannot find $goal near position {self.pos}" | |
# } | |
# } | |
# A.parse: '[good]'; # OUTPUT: «「[good]」» | |
# A.parse: '[bad'; # will throw FAILGOAL exception | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::AdHoc: Cannot find ']' near position 5» | |
ok 639 - doc/Language/regexes.pod6 chunk 63 compiles | |
# "3)" ~~ / <?> ~ ')' \d+ /; # RESULT: «「3)」» | |
# "(3)" ~~ / <?> ~ ')' \d+ /; # RESULT: «「3)」» | |
ok 640 - doc/Language/regexes.pod6 chunk 64 compiles | |
# "abc" ~~ /a ~ (c) (b)/; | |
# say $0; # OUTPUT: «「c」» | |
# say $1; # OUTPUT: «「b」» | |
ok 641 - doc/Language/regexes.pod6 chunk 65 compiles | |
# my regex line { \N*\n } | |
# if "abc\ndef" ~~ /<line> def/ { | |
# say "First line: ", $<line>.chomp; # OUTPUT: «First line: abc» | |
# } | |
ok 642 - doc/Language/regexes.pod6 chunk 66 compiles | |
# my regex header { \s* '[' (\w+) ']' \h* \n+ } | |
# my regex identifier { \w+ } | |
# my regex kvpair { \s* <key=identifier> '=' <value=identifier> \n+ } | |
# my regex section { | |
# <header> | |
# <kvpair>* | |
# } | |
# my $contents = q:to/EOI/; | |
# [passwords] | |
# jack=password1 | |
# joy=muchmoresecure123 | |
# [quotas] | |
# jack=123 | |
# joy=42 | |
# EOI | |
# my %config; | |
# if $contents ~~ /<section>*/ { | |
# for $<section>.list -> $section { | |
# my %section; | |
# for $section<kvpair>.list -> $p { | |
# say $p<value>; | |
# %section{ $p<key> } = ~$p<value>; | |
# } | |
# %config{ $section<header>[0] } = %section; | |
# } | |
# } | |
# say %config.perl; | |
# # OUTPUT: «("passwords" => {"jack" => "password1", "joy" => "muchmoresecure123"}, | |
# # "quotas" => {"jack" => "123", "joy" => "42"}).hash» | |
ok 643 - doc/Language/regexes.pod6 chunk 67 compiles | |
# my $regex = /../; # definition | |
# if 'abc'.match($regex) { # matching | |
# say "'abc' has at least two characters"; | |
# } | |
ok 644 - doc/Language/regexes.pod6 chunk 68 compiles | |
# my $regex = /:i . a/; | |
# for 'baA'.match($regex, :overlap) -> $m { | |
# say ~$m; | |
# } | |
# # OUTPUT: «baaA» | |
ok 645 - doc/Language/regexes.pod6 chunk 69 compiles | |
# my $rx1 = rx:i/a/; # before | |
# my $rx2 = m:i/a/; # before | |
# my $rx3 = /:i a/; # inside | |
ok 646 - doc/Language/regexes.pod6 chunk 70 compiles | |
# my $rx1 = rx:i/a/; # before | |
# my $rx2 = rx/:i a/; # inside | |
ok 647 - doc/Language/regexes.pod6 chunk 71 compiles | |
Potential difficulties: | |
Space is not significant here; please use quotes or :s (:sigspace) modifier (or, to suppress this warning, omit the space, or otherwise change the spacing) | |
at /Users/williamcoleda/sandbox/doc/EVAL_647:3 | |
------> [32mmy $rx4 = rx/:i a[33m⏏[31m b/; # matches completely case insensi[0m | |
# my $rx3 = rx/a :i b/; # matches only the b case insensitively | |
# my $rx4 = rx/:i a b/; # matches completely case insensitively | |
ok 648 - doc/Language/regexes.pod6 chunk 72 compiles | |
Potential difficulties: | |
Space is not significant here; please use quotes or :s (:sigspace) modifier (or, to suppress this warning, omit the space, or otherwise change the spacing) | |
at /Users/williamcoleda/sandbox/doc/EVAL_648:2 | |
------> [32m class :: {/ (:i a[33m⏏[31m b) c /; # matches 'ABc' but not[0m | |
Space is not significant here; please use quotes or :s (:sigspace) modifier (or, to suppress this warning, omit the space, or otherwise change the spacing) | |
at /Users/williamcoleda/sandbox/doc/EVAL_648:3 | |
------> [32m/ [:i a[33m⏏[31m b] c /; # matches 'ABc' but not[0m | |
# / (:i a b) c /; # matches 'ABc' but not 'ABC' | |
# / [:i a b] c /; # matches 'ABc' but not 'ABC' | |
ok 649 - doc/Language/regexes.pod6 chunk 73 compiles | |
# say so 'abc' ~~ / \w+ . /; # OUTPUT: «True» | |
# say so 'abc' ~~ / :r \w+ . /; # OUTPUT: «False» | |
ok 650 - doc/Language/regexes.pod6 chunk 74 compiles | |
# grammar Demo { | |
# token ws { | |
# <!ww> # only match when not within a word | |
# \h* # only match horizontal whitespace | |
# } | |
# rule TOP { # called by Demo.parse; | |
# a b '.' | |
# } | |
# } | |
# # doesn't parse, whitespace required between a and b | |
# say so Demo.parse("ab."); # OUTPUT: «False» | |
# say so Demo.parse("a b."); # OUTPUT: «True» | |
# say so Demo.parse("a\tb ."); # OUTPUT: «True» | |
# # \n is vertical whitespace, so no match | |
# say so Demo.parse("a\tb\n."); # OUTPUT: «False» | |
ok 651 - doc/Language/regexes.pod6 chunk 75 compiles | |
# given 'a1xa2' { | |
# say ~m/a./; # OUTPUT: «a1» | |
# say ~m:c(2)/a./; # OUTPUT: «a2» | |
# } | |
ok 652 - doc/Language/regexes.pod6 chunk 76 compiles | |
# say "abcdefg" ~~ m:c(3)/e.+/; # OUTPUT: «「efg」» | |
# say "abcdefg" ~~ m:p(3)/e.+/; # OUTPUT: «False» | |
ok 653 - doc/Language/regexes.pod6 chunk 77 compiles | |
# given 'abracadabra' { | |
# for m:exhaustive/ a .* a / -> $match { | |
# say ' ' x $match.from, ~$match; | |
# } | |
# } | |
ok 654 - doc/Language/regexes.pod6 chunk 78 compiles | |
# given 'several words here' { | |
# my @matches = m:global/\w+/; | |
# say @matches.elems; # OUTPUT: «3» | |
# say ~@matches[2]; # OUTPUT: «here» | |
# } | |
ok 655 - doc/Language/regexes.pod6 chunk 79 compiles | |
# given 'abcdef' { | |
# my $match = m:pos(2)/.*/; | |
# say $match.from; # OUTPUT: «2» | |
# say ~$match; # OUTPUT: «cdef» | |
# } | |
ok 656 - doc/Language/regexes.pod6 chunk 80 compiles | |
# say "abcdefg" ~~ m:c(3)/e.+/; # OUTPUT: «「efg」» | |
# say "abcdefg" ~~ m:p(3)/e.+/; # OUTPUT: «False» | |
ok 657 - doc/Language/regexes.pod6 chunk 81 compiles | |
# given 'abracadabra' { | |
# for m:overlap/ a .* a / -> $match { | |
# say ' ' x $match.from, ~$match; | |
# } | |
# } | |
ok 658 - doc/Language/regexes.pod6 chunk 82 compiles | |
# <?before pattern> | |
ok 659 - doc/Language/regexes.pod6 chunk 83 compiles | |
# rx{ foo <?before bar> } | |
ok 660 - doc/Language/regexes.pod6 chunk 84 compiles | |
# say "foobar" ~~ rx{ foo <?before bar> }; # OUTPUT: «foo» | |
ok 661 - doc/Language/regexes.pod6 chunk 85 compiles | |
# <!before pattern> | |
ok 662 - doc/Language/regexes.pod6 chunk 86 compiles | |
# rx{ foo <!before bar> } | |
ok 663 - doc/Language/regexes.pod6 chunk 87 compiles | |
# <?after pattern> | |
ok 664 - doc/Language/regexes.pod6 chunk 88 compiles | |
# rx{ <?after foo> bar } | |
ok 665 - doc/Language/regexes.pod6 chunk 89 compiles | |
# say "foobar" ~~ rx{ <?after foo> bar }; # OUTPUT: «bar» | |
ok 666 - doc/Language/regexes.pod6 chunk 90 compiles | |
# <!after pattern> | |
ok 667 - doc/Language/regexes.pod6 chunk 91 compiles | |
# rx{ <!after foo> bar } | |
ok 668 - doc/Language/regexes.pod6 chunk 92 compiles | |
# my regex float { <[+-]>?\d*'.'\d+[e<[+-]>?\d+]? } | |
ok 669 - doc/Language/regexes.pod6 chunk 93 compiles | |
# my regex float { | |
# <[+-]>? # optional sign | |
# \d* # leading digits, optional | |
# '.' | |
# \d+ | |
# [ # optional exponent | |
# e <[+-]>? \d+ | |
# ]? | |
# } | |
ok 670 - doc/Language/regexes.pod6 chunk 94 compiles | |
# my regex example { | |
# <preamble> | |
# [ | |
# || <choice_1> | |
# || <choice_2> | |
# || <choice_3> | |
# ]+ | |
# <postamble> | |
# } | |
ok 671 - doc/Language/regexes.pod6 chunk 95 compiles | |
# my regex float { | |
# <[+-]>? # optional sign | |
# \d* # leading digits, optional | |
# '.' | |
# \d+ | |
# [ # optional exponent | |
# e <[+-]>? \d+ | |
# ]? | |
# } | |
ok 672 - doc/Language/regexes.pod6 chunk 96 compiles | |
# my token sign { <[+-]> } | |
# my token decimal { \d+ } | |
# my token exponent { 'e' <sign>? <decimal> } | |
# my regex float { | |
# <sign>? | |
# <decimal>? | |
# '.' | |
# <decimal> | |
# <exponent>? | |
# } | |
ok 673 - doc/Language/regexes.pod6 chunk 97 compiles | |
# my regex float { | |
# <sign>? | |
# [ | |
# || <decimal>? '.' <decimal> <exponent>? | |
# || <decimal> <exponent> | |
# ] | |
# } | |
ok 674 - doc/Language/regexes.pod6 chunk 98 compiles | |
# token header { '[' <-[ \[\] ]>+ ']' } | |
ok 675 - doc/Language/regexes.pod6 chunk 99 compiles | |
# token header { '[' <-[ \[\] \n ]>+ ']' } | |
ok 676 - doc/Language/regexes.pod6 chunk 100 compiles | |
# my regex kvpair { \s* <key=identifier> '=' <value=identifier> \n+ } | |
ok 677 - doc/Language/regexes.pod6 chunk 101 compiles | |
# my regex kvpair { \s* <key=identifier> \s* '=' \s* <value=identifier> \n+ } | |
ok 678 - doc/Language/regexes.pod6 chunk 102 compiles | |
# my rule kvpair { <key=identifier> '=' <value=identifier> \n+ } | |
ok 679 - doc/Language/regexes.pod6 chunk 103 compiles | |
# grammar IniFormat { | |
# token ws { <!ww> \h* } | |
# rule header { \s* '[' (\w+) ']' \n+ } | |
# token identifier { \w+ } | |
# rule kvpair { \s* <key=identifier> '=' <value=identifier> \n+ } | |
# token section { | |
# <header> | |
# <kvpair>* | |
# } | |
# token TOP { | |
# <section>* | |
# } | |
# } | |
# my $contents = q:to/EOI/; | |
# [passwords] | |
# jack = password1 | |
# joy = muchmoresecure123 | |
# [quotas] | |
# jack = 123 | |
# joy = 42 | |
# EOI | |
# say so IniFormat.parse($contents); | |
ok 680 - doc/Language/regexes.pod6 chunk 104 compiles | |
# token ws { <!ww> \h* } | |
ok 681 - doc/Language/regexes.pod6 chunk 105 compiles | |
# multi sub infix:<(elem)>($a, Any $b --> Bool) | |
# multi sub infix:<(elem)>($a, Set $b --> Bool) | |
ok 682 - doc/Language/setbagmix.pod6 chunk 1 compiles | |
# only sub infix:<∈>($a, $b --> Bool) | |
ok 683 - doc/Language/setbagmix.pod6 chunk 2 compiles | |
# only sub infix:<∉>($a, $b --> Bool) | |
ok 684 - doc/Language/setbagmix.pod6 chunk 3 compiles | |
# multi sub infix:<(cont)>(Any $a, $b --> Bool) | |
# multi sub infix:<(cont)>(Set $a, $b --> Bool) | |
ok 685 - doc/Language/setbagmix.pod6 chunk 4 compiles | |
# only sub infix:<∋>($a, $b --> Bool) | |
ok 686 - doc/Language/setbagmix.pod6 chunk 5 compiles | |
# only sub infix:<∌>($a, $b --> Bool) | |
ok 687 - doc/Language/setbagmix.pod6 chunk 6 compiles | |
# multi sub infix:<<(<=)>>(Any $a, Any $b --> Bool) | |
# multi sub infix:<<(<=)>>(Setty $a, Setty $b --> Bool) | |
ok 688 - doc/Language/setbagmix.pod6 chunk 7 compiles | |
# only sub infix:<⊆>($a, $b --> Bool) | |
ok 689 - doc/Language/setbagmix.pod6 chunk 8 compiles | |
# only sub infix:<⊈>($a, $b --> Bool) | |
ok 690 - doc/Language/setbagmix.pod6 chunk 9 compiles | |
# multi sub infix:<<(<)>>(Any $a, Any $b --> Bool) | |
# multi sub infix:<<(<)>>(Setty $a, Setty $b --> Bool) | |
ok 691 - doc/Language/setbagmix.pod6 chunk 10 compiles | |
# only sub infix:<⊂>($a, $b --> Bool) | |
ok 692 - doc/Language/setbagmix.pod6 chunk 11 compiles | |
# only sub infix:<⊄>($a, $b --> Bool) | |
ok 693 - doc/Language/setbagmix.pod6 chunk 12 compiles | |
# multi sub infix:<<(>=)>>(Any $a, Any $b --> Bool) | |
# multi sub infix:<<(>=)>>(Setty $a, Setty $b --> Bool) | |
ok 694 - doc/Language/setbagmix.pod6 chunk 13 compiles | |
# only sub infix:<⊇>($a, $b --> Bool) | |
ok 695 - doc/Language/setbagmix.pod6 chunk 14 compiles | |
# only sub infix:<⊉>($a, $b --> Bool) | |
ok 696 - doc/Language/setbagmix.pod6 chunk 15 compiles | |
# multi sub infix:<<(>)>>(Any $a, Any $b --> Bool) | |
# multi sub infix:<<(>)>>(Setty $a, Setty $b --> Bool) | |
ok 697 - doc/Language/setbagmix.pod6 chunk 16 compiles | |
# only sub infix:<⊃>($a, $b --> Bool) | |
ok 698 - doc/Language/setbagmix.pod6 chunk 17 compiles | |
# only sub infix:<⊅>($a, $b --> Bool) | |
ok 699 - doc/Language/setbagmix.pod6 chunk 18 compiles | |
# multi sub infix:<<(<+)>>(Any $a, Any $b --> Bool) | |
# multi sub infix:<<(<+)>>(Baggy $a, Baggy $b --> Bool) | |
ok 700 - doc/Language/setbagmix.pod6 chunk 19 compiles | |
# only sub infix:<≼>($a, $b --> Bool) | |
ok 701 - doc/Language/setbagmix.pod6 chunk 20 compiles | |
# multi sub infix:<<(>+)>>(Baggy $a, Baggy $b --> Bool) | |
# multi sub infix:<<(>+)>>(Any $a, Any $b --> Bool) | |
ok 702 - doc/Language/setbagmix.pod6 chunk 21 compiles | |
# only sub infix:<≽>($a, $b --> Bool) | |
ok 703 - doc/Language/setbagmix.pod6 chunk 22 compiles | |
# only sub infix:<(|)>(**@p) | |
ok 704 - doc/Language/setbagmix.pod6 chunk 23 compiles | |
# only sub infix:<∪>(|p) | |
ok 705 - doc/Language/setbagmix.pod6 chunk 24 compiles | |
# only sub infix:<(&)>(**@p) | |
ok 706 - doc/Language/setbagmix.pod6 chunk 25 compiles | |
# only sub infix:<∩>(|p) | |
ok 707 - doc/Language/setbagmix.pod6 chunk 26 compiles | |
# only sub infix:<(-)>(**@p) | |
ok 708 - doc/Language/setbagmix.pod6 chunk 27 compiles | |
# only sub infix:<<"\x2216">>(|p) | |
ok 709 - doc/Language/setbagmix.pod6 chunk 28 compiles | |
# multi sub infix:<(^)>(Any $a, Any $b --> Setty) | |
# multi sub infix:<(^)>(Set $a, Set $b --> Setty) | |
ok 710 - doc/Language/setbagmix.pod6 chunk 29 compiles | |
# only sub infix:<⊖>($a, $b --> Setty) | |
ok 711 - doc/Language/setbagmix.pod6 chunk 30 compiles | |
# only sub infix:<(.)>(**@p) | |
ok 712 - doc/Language/setbagmix.pod6 chunk 31 compiles | |
# only sub infix:<⊍>(|p) | |
ok 713 - doc/Language/setbagmix.pod6 chunk 32 compiles | |
# only sub infix:<(+)>(**@p) | |
ok 714 - doc/Language/setbagmix.pod6 chunk 33 compiles | |
# only sub infix:<⊎>(|p) | |
ok 715 - doc/Language/setbagmix.pod6 chunk 34 compiles | |
# say "__Hello__".match(/__(.*)__/)[0]; # OUTPUT: «「Hello」» | |
# say "__Hello__".match(/__(.*)__/).[0]; # same, in method notation | |
ok 716 - doc/Language/subscripts.pod6 chunk 1 compiles | |
# my @array1; say @array1[10]; # OUTPUT: «(Any)» | |
# my Int @array2; say @array2[10]; # OUTPUT: «(Int)» | |
# my %hash1; say %hash1<foo>; # OUTPUT: «(Any)» | |
# my Int %hash2; say %hash2<foo>; # OUTPUT: «(Int)» | |
ok 717 - doc/Language/subscripts.pod6 chunk 2 compiles | |
# say (0, 10, 20)[3]; # OUTPUT: «Nil» | |
# say bag(<a a b b b>)<c>; # OUTPUT: «0» | |
# say array[uint8].new(1, 2)[2] # OUTPUT: «0» | |
ok 718 - doc/Language/subscripts.pod6 chunk 3 compiles | |
# my @alphabet = 'A' .. 'Z'; | |
# say @alphabet[*-1]; # OUTPUT: «Z» | |
# say @alphabet[*-2]; # OUTPUT: «Y» | |
# say @alphabet[*-3]; # OUTPUT: «X» | |
ok 719 - doc/Language/subscripts.pod6 chunk 4 compiles | |
# my @alphabet = 'a' .. 'z'; | |
# dd @alphabet[15, 4, *-9, 11]; # OUTPUT: «("p", "e", "r", "l")» | |
ok 720 - doc/Language/subscripts.pod6 chunk 5 compiles | |
# my %color = kiwi => "green", banana => "yellow", cherry => "red"; | |
# dd %color{"cherry", "kiwi"}; # OUTPUT: «("red", "green")» | |
# dd %color<cherry kiwi>; # OUTPUT: «("red", "green")» | |
# dd %color{*}; # OUTPUT: «("green", "red", "yellow")» | |
ok 721 - doc/Language/subscripts.pod6 chunk 6 compiles | |
# my @letters = <a b c d e f>; | |
# dd @letters[3, 4, 5, 6, 7]; # OUTPUT: «("d", "e", "f", Any, Any)» | |
# dd @letters[3 .. 7]; # OUTPUT: «("d", "e", "f")» | |
ok 722 - doc/Language/subscripts.pod6 chunk 7 compiles | |
# my %bag := ("orange" => 1, "apple" => 3).Bag; | |
# dd %bag<>; # OUTPUT: «("orange"=>1,"apple"=>3).Bag» | |
# dd %bag{}; # OUTPUT: «("orange"=>1,"apple"=>3).Bag» | |
# dd %bag{*}; # OUTPUT: «(1, 3)» | |
# dd %bag{()}; # OUTPUT: «()» | |
ok 723 - doc/Language/subscripts.pod6 chunk 8 compiles | |
# my @words = "cruel", "world"; | |
# say "Hello, @words[]!" # OUTPUT: «Hello, cruel world!» | |
ok 724 - doc/Language/subscripts.pod6 chunk 9 compiles | |
# my @twodim = (<a b c>, (1, 2, 3)); | |
# dd @twodim; | |
# # OUTPUT: «Array @twodim = [("a", "b", "c"), (1, 2, 3)]» | |
# dd @twodim[0,1;1]; # 2nd element of both lists | |
# # OUTPUT: «("b", 2)» | |
ok 725 - doc/Language/subscripts.pod6 chunk 10 compiles | |
# my @toomany = [[<a b>], [1, 2]]; | |
# dd @toomany; | |
# # OUTPUT: «Array @toomany = [["a", "b"], [1, 2]]» | |
# dd @toomany[*;*]; | |
# # OUTPUT: «("a", "b", 1, 2)» | |
ok 726 - doc/Language/subscripts.pod6 chunk 11 compiles | |
Potential difficulties: | |
Redeclaration of symbol '@a' | |
at /Users/williamcoleda/sandbox/doc/EVAL_726:5 | |
------> [32mmy @a[33m⏏[31m = (<1 c 6>, <2 a 4>, <5 b 3>);[0m | |
# my @a = [[1,2], [3,4]]; | |
# say @a[*;1]; # 2nd element of each sub list | |
# # OUTPUT: «(2 4)» | |
# my @a = (<1 c 6>, <2 a 4>, <5 b 3>); | |
# say @a.sort(*[1]); # sort by 2nd column | |
# # OUTPUT: «((2 a 4) (5 b 3) (1 c 6))» | |
ok 727 - doc/Language/subscripts.pod6 chunk 12 compiles | |
# my $beatles; | |
# $beatles{"White Album"}[0] = "Back in the U.S.S.R."; # autovivification! | |
# say $beatles.perl; # OUTPUT: «{"White Album" => ["Back in the U.S.S.R."]}» | |
ok 728 - doc/Language/subscripts.pod6 chunk 13 compiles | |
# my @a = 10, 11, 12, 13; | |
# my $x = 1; | |
# @a[2] := $x; # binding! (@a[2] and $x refer to the same container now.) | |
# $x++; @a[2]++; | |
# dd @a; # OUTPUT: «[10, 11, 3, 13]<>» | |
# dd $x; # OUTPUT: «3» | |
ok 729 - doc/Language/subscripts.pod6 chunk 14 compiles | |
# my @foo = Any, 10; | |
# dd @foo[0].defined; # OUTPUT: «False» | |
# dd @foo[0]:exists; # OUTPUT: «True» | |
# dd @foo[2]:exists; # OUTPUT: «False» | |
# dd @foo[0, 2]:exists; # OUTPUT: «(True, False)» | |
# my %fruit = apple => Any, orange => 10; | |
# dd %fruit<apple>.defined; # OUTPUT: «False» | |
# dd %fruit<apple>:exists; # OUTPUT: «True» | |
# dd %fruit<banana>:exists; # OUTPUT: «False» | |
# dd %fruit<apple banana>:exists; # OUTPUT: «(True, False)» | |
ok 730 - doc/Language/subscripts.pod6 chunk 15 compiles | |
# my @tens = 0, 10, 20, 30; | |
# dd @tens[3]:delete; # OUTPUT: «30» | |
# dd @tens; # OUTPUT: «[0, 10, 20]<>» | |
# my %fruit = apple => 5, orange => 10, banana => 4, peach => 17; | |
# dd %fruit<apple>:delete; # OUTPUT: «5» | |
# dd %fruit<peach orange>:delete; # OUTPUT: «(17, 10)» | |
# dd %fruit; # OUTPUT: «{banana => 4}<>» | |
ok 731 - doc/Language/subscripts.pod6 chunk 16 compiles | |
# my @a = 1, 2, 3; | |
# @a[1]:delete; | |
# say @a[1]:exists; | |
# # OUTPUT: «False» | |
# .say for @a; | |
# # OUTPUT: «1(Any)3» | |
ok 732 - doc/Language/subscripts.pod6 chunk 17 compiles | |
# my @tens = 0, 10, 20, 30; | |
# dd @tens[1]:p; # OUTPUT: «1 => 10» | |
# dd @tens[0, 4, 2]:p; # OUTPUT: «(0 => 0, 2 => 20)» | |
# my %month = Jan => 1, Feb => 2, Mar => 3; | |
# dd %month<Feb>:p; # OUTPUT: «"Feb" => 2» | |
# dd %month<Jan Foo Mar>:p; # OUTPUT: «("Jan" => 1, "Mar" => 3)» | |
ok 733 - doc/Language/subscripts.pod6 chunk 18 compiles | |
# my @tens = 0, 10, 20, 30; | |
# dd @tens[1]:kv; # OUTPUT: «(1, 10)» | |
# dd @tens[0, 4, 2]:kv; # OUTPUT: «(0, 0, 2, 20)» | |
# my %month = Jan => 1, Feb => 2, Mar => 3; | |
# dd %month<Feb>:kv; # OUTPUT: «("Feb", 2)» | |
# dd %month<Jan Foo Mar>:kv; # OUTPUT: «("Jan", 1, "Mar", 3)» | |
ok 734 - doc/Language/subscripts.pod6 chunk 19 compiles | |
# my @tens = 0, 10, 20, 30; | |
# dd @tens[1]:k; # OUTPUT: «1» | |
# dd @tens[0, 4, 2]:k; # OUTPUT: «(0, 2)» | |
# my %month = Jan => 1, Feb => 2, Mar => 3; | |
# dd %month<Feb>:k; # OUTPUT: «"Feb"» | |
# dd %month<Jan Foo Mar>:k; # OUTPUT: «("Jan", "Mar")» | |
ok 735 - doc/Language/subscripts.pod6 chunk 20 compiles | |
# multi method elems(::?CLASS:D:) | |
ok 736 - doc/Language/subscripts.pod6 chunk 21 compiles | |
# multi method AT-POS (::?CLASS:D: $index) | |
ok 737 - doc/Language/subscripts.pod6 chunk 22 compiles | |
# multi method EXISTS-POS (::?CLASS:D: $index) | |
ok 738 - doc/Language/subscripts.pod6 chunk 23 compiles | |
# multi method DELETE-POS (::?CLASS:D: $index) | |
ok 739 - doc/Language/subscripts.pod6 chunk 24 compiles | |
# multi method ASSIGN-POS (::?CLASS:D: $index, $new) | |
ok 740 - doc/Language/subscripts.pod6 chunk 25 compiles | |
# multi method BIND-POS (::?CLASS:D: $index, \new) | |
ok 741 - doc/Language/subscripts.pod6 chunk 26 compiles | |
# multi method AT-KEY (::?CLASS:D: $key) | |
ok 742 - doc/Language/subscripts.pod6 chunk 27 compiles | |
# multi method EXISTS-KEY (::?CLASS:D: $key) | |
ok 743 - doc/Language/subscripts.pod6 chunk 28 compiles | |
# multi method DELETE-KEY (::?CLASS:D: $key) | |
ok 744 - doc/Language/subscripts.pod6 chunk 29 compiles | |
# multi method ASSIGN-KEY (::?CLASS:D: $key, $new) | |
ok 745 - doc/Language/subscripts.pod6 chunk 30 compiles | |
# multi method BIND-KEY (::?CLASS:D: $key, \new) | |
ok 746 - doc/Language/subscripts.pod6 chunk 31 compiles | |
# if True { | |
# say "Hello"; | |
# } | |
ok 747 - doc/Language/syntax.pod6 chunk 1 compiles | |
# if True { | |
# say "Hello"; | |
# } | |
ok 748 - doc/Language/syntax.pod6 chunk 2 compiles | |
# if True { say "Hello" } | |
ok 749 - doc/Language/syntax.pod6 chunk 3 compiles | |
# if True {say "Hello"} | |
ok 750 - doc/Language/syntax.pod6 chunk 4 compiles | |
# sub alignment(+@l) { +@l }; | |
# sub long-name-alignment(+@l) { +@l }; | |
# alignment\ (1,2,3,4).say; | |
# long-name-alignment(3,5)\ .say; | |
ok 751 - doc/Language/syntax.pod6 chunk 5 compiles | |
# if True { | |
# say "Hello"; | |
# } | |
# say "world"; | |
ok 752 - doc/Language/syntax.pod6 chunk 6 compiles | |
# if True { say "Hello" }; say "world"; | |
# # ^^^ this ; is required | |
ok 753 - doc/Language/syntax.pod6 chunk 7 compiles | |
# if #`( why would I ever write an inline comment here? ) True { | |
# say "something stupid"; | |
# } | |
ok 754 - doc/Language/syntax.pod6 chunk 8 compiles | |
# say "this is code"; | |
# =begin comment | |
# Here are several | |
# lines | |
# of comment | |
# =end comment | |
# say 'code again'; | |
ok 755 - doc/Language/syntax.pod6 chunk 9 compiles | |
# my Int $Foo::Bar::buzz = 42; | |
# dd $Foo::Bar::buzz; # OUTPUT: «Int $v = 42» | |
ok 756 - doc/Language/syntax.pod6 chunk 10 compiles | |
# my $foo:bar = 1; | |
# my $foo:bar<2> = 2; | |
# dd MY::.keys; | |
# # OUTPUT: «("\$=pod", "!UNIT_MARKER", "EXPORT", "\$_", "\$!", "::?PACKAGE", | |
# # "GLOBALish", "\$¢", "\$=finish", "\$/", "\$foo:bar<1>", "\$foo:bar<2>", | |
# # "\$?PACKAGE").Seq» | |
ok 757 - doc/Language/syntax.pod6 chunk 11 compiles | |
# constant $c = 42; | |
# my $a:foo<42> = "answer"; | |
# say $a:foo«$c»; | |
# # OUTPUT: «answer» | |
ok 758 - doc/Language/syntax.pod6 chunk 12 compiles | |
# use Test; plan 1; constant &term:<👍> = &ok.assuming(True); | |
# 👍 | |
# # OUTPUT: «1..1ok 1 - » | |
ok 759 - doc/Language/syntax.pod6 chunk 13 compiles | |
# my $x = do if True { 42 }; | |
ok 760 - doc/Language/syntax.pod6 chunk 14 compiles | |
# # declaration: | |
# my $number = 21; | |
# # usage: | |
# say $number * 2; | |
ok 761 - doc/Language/syntax.pod6 chunk 15 compiles | |
# say Int; # OUTPUT: «(Int)» | |
# # ^^^ type name (built in) | |
# constant answer = 42; | |
# say answer; | |
# # ^^^^^^ constant | |
# class Foo { | |
# method type-name { | |
# self.^name; | |
# # ^^^^ built-in term 'self' | |
# } | |
# } | |
# say Foo.type-name; # OUTPUT: «Foo» | |
# # ^^^ type name | |
ok 762 - doc/Language/syntax.pod6 chunk 16 compiles | |
# say 'a string literal'; | |
# say "a string literal\nthat interprets escape sequences"; | |
ok 763 - doc/Language/syntax.pod6 chunk 17 compiles | |
# say ['a', 'b', 42].join(' '); # OUTPUT: «a b 42» | |
# # ^^^^^^^^^^^^^^ Array constructor | |
ok 764 - doc/Language/syntax.pod6 chunk 18 compiles | |
# my @a = 1, 2; | |
# # flattens: | |
# say [@a, 3, 4].elems; # OUTPUT: «4» | |
# # does not flatten: | |
# say [[@a], [3, 4]].elems; # OUTPUT: «2» | |
ok 765 - doc/Language/syntax.pod6 chunk 19 compiles | |
# say { a => 3, b => 23, :foo, :dog<cat>, "french", "fries" }; | |
# # OUTPUT: «a => 3, b => 23, dog => cat, foo => True, french => fries» | |
# say {a => 73, foo => "fish"}.keys.join(" "); # OUTPUT: «a foo» | |
# # ^^^^^^^^^^^^^^^^^^^^^^^^ Hash constructor | |
ok 766 - doc/Language/syntax.pod6 chunk 20 compiles | |
# my %ages = fred => 23, jean => 87, ann => 4; | |
ok 767 - doc/Language/syntax.pod6 chunk 21 compiles | |
# my $when = :{ (now) => "Instant", (DateTime.now) => "DateTime" }; | |
ok 768 - doc/Language/syntax.pod6 chunk 22 compiles | |
# :{ -1 => 41, 0 => 42, 1 => 43 }<0>; # OUTPUT: «Any» | |
# :{ -1 => 41, 0 => 42, 1 => 43 }{0}; # OUTPUT: «42» | |
ok 769 - doc/Language/syntax.pod6 chunk 23 compiles | |
# say "match!" if 5, "fish" ~~ :(Int, Str); # OUTPUT: «match!» | |
# my $sig = :(Int $a, Str); | |
# say "match!" if (5, "fish") ~~ $sig; # OUTPUT: «match!» | |
# given "foo", 42 { | |
# when :(Str, Str) { "This won't match" } | |
# when :(Str, Int $n where $n > 20) { "This will!" } | |
# } | |
ok 770 - doc/Language/syntax.pod6 chunk 24 compiles | |
Potential difficulties: | |
Redeclaration of symbol '$x' | |
at /Users/williamcoleda/sandbox/doc/EVAL_773:3 | |
------> [32mmy $x[33m⏏[31m = 7; # initialize [0m | |
Redeclaration of symbol '$x' | |
at /Users/williamcoleda/sandbox/doc/EVAL_773:4 | |
------> [32mmy Int $x[33m⏏[31m = 7; # declare the typ[0m | |
Redeclaration of symbol '$x' | |
at /Users/williamcoleda/sandbox/doc/EVAL_773:5 | |
------> [32mmy Int:D $x[33m⏏[31m = 7; # specify that the [0m | |
Redeclaration of symbol '$x' | |
at /Users/williamcoleda/sandbox/doc/EVAL_773:6 | |
------> [32mmy Int $x where { $_ > 3 }[33m⏏[31m = 7; # constrain the value based on a f[0m | |
Redeclaration of symbol '$x' | |
at /Users/williamcoleda/sandbox/doc/EVAL_773:7 | |
------> [32mmy Int $x where * > 3[33m⏏[31m = 7; # same constraint, but using [0m | |
# my $x; # simple lexical variable | |
# my $x = 7; # initialize the variable | |
# my Int $x = 7; # declare the type | |
# my Int:D $x = 7; # specify that the value must be defined (not undef) | |
# my Int $x where { $_ > 3 } = 7; # constrain the value based on a function | |
# my Int $x where * > 3 = 7; # same constraint, but using L<Whatever> short-hand | |
ok 771 - doc/Language/syntax.pod6 chunk 25 compiles | |
# # The signature is optional | |
# sub foo { say "Hello!" } | |
# sub say-hello($to-whom) { say "Hello $to-whom!" } | |
ok 772 - doc/Language/syntax.pod6 chunk 26 compiles | |
Potential difficulties: | |
Redeclaration of symbol '&f' | |
at /Users/williamcoleda/sandbox/doc/EVAL_775:3 | |
------> [32mmy &f[33m⏏[31m = -> { say "Hello!" } # Lambda style s[0m | |
# my &f = sub { say "Hello!" } # Un-named sub | |
# my &f = -> { say "Hello!" } # Lambda style syntax. The & sigil indicates the variable holds a function | |
# my $f = -> { say "Hello!" } # Functions can also be put into scalars | |
ok 773 - doc/Language/syntax.pod6 chunk 27 compiles | |
# module Gar { } | |
# class Foo { } | |
# role Bar { } | |
# grammar Baz { } | |
ok 774 - doc/Language/syntax.pod6 chunk 28 compiles | |
# multi sub foo() { say "Hello!" } | |
# multi sub foo($name) { say "Hello $name!" } | |
ok 775 - doc/Language/syntax.pod6 chunk 29 compiles | |
# multi method greet { } | |
# multi method greet(Str $name) { } | |
ok 776 - doc/Language/syntax.pod6 chunk 30 compiles | |
# [+] <1 2 3 4 5>; # OUTPUT: «15» | |
# (((1 + 2) + 3) + 4) + 5 # equivalent expanded version | |
ok 777 - doc/Language/syntax.pod6 chunk 31 compiles | |
# <1 2 3> «+» <4 5 6> # OUTPUT: «<5 7 9>» | |
ok 778 - doc/Language/syntax.pod6 chunk 32 compiles | |
# -« <1 2 3> # OUTPUT: «<-1 -2 -3>» | |
ok 779 - doc/Language/syntax.pod6 chunk 33 compiles | |
# sub term:<forty-two> { 42 }; | |
# say forty-two | |
ok 780 - doc/Language/terms.pod6 chunk 1 compiles | |
# constant forty-two = 42; | |
# say forty-two; | |
ok 781 - doc/Language/terms.pod6 chunk 2 compiles | |
# constant SpeedOfLight = 299792458; # m/s | |
# constant PHI = 1.61803398875; # The golden ratio is everywhere! | |
# constant POW2 = do { my int @table; @table = 1, 2, 4 ... 2**32; @table }; | |
# say POW2[16]; | |
# # OUTPUT: «65536» | |
ok 782 - doc/Language/terms.pod6 chunk 3 compiles | |
# # Use "my" to make it only visible within the current block | |
# my constant SpeedOfLight = 186200; # mi/s (watch out, not SI units) | |
ok 783 - doc/Language/terms.pod6 chunk 4 compiles | |
# my $a = 1; | |
# $a = Nil; | |
# say $a.WHAT; | |
# # OUTPUT: «(Any)» | |
# class C {}; | |
# say C.^parents(:all); | |
# # OUTPUT: «((Any) (Mu))» | |
ok 784 - doc/Language/typesystem.pod6 chunk 1 compiles | |
# my $a = Int; | |
# say so $a // $a === $a.WHAT; | |
# # OUTPUT: «True» | |
ok 785 - doc/Language/typesystem.pod6 chunk 2 compiles | |
# my Int $i = 1 but role :: { method defined { False } }; | |
# say $i // "undefined"; | |
# # OUTPUT: «undefined» | |
ok 786 - doc/Language/typesystem.pod6 chunk 3 compiles | |
# class C { | |
# has $.int; | |
# method this-is-c { put 'oi' x $!int ~ '‽' } | |
# } | |
# use MONKEY-TYPING; | |
# augment class Int { | |
# method C { C.new(:int(self))} | |
# } | |
# my $i = 10; | |
# $i.=C; | |
# $i.this-is-c(); | |
# # OUTPUT: «oioioioioioioioioioi‽» | |
ok 787 - doc/Language/typesystem.pod6 chunk 4 compiles | |
# my $whatever = "123.6"; | |
# say $whatever.round; | |
# # OUTPUT: «124» | |
# say <a b c d>.starts-with("ab"); | |
# # OUTPUT: «False» | |
ok 788 - doc/Language/typesystem.pod6 chunk 5 compiles | |
# class Foo::Bar::C {}; | |
# put Foo::Bar::.keys; | |
# # OUTPUT: «C» | |
ok 789 - doc/Language/typesystem.pod6 chunk 6 compiles | |
# class C {...} | |
# # many lines later | |
# class C { has $.attr } | |
ok 790 - doc/Language/typesystem.pod6 chunk 7 compiles | |
# class A {} | |
# role R { method m { say 'oi‽' } } | |
# my R $A = A but R; | |
# my $a1 = $A.new; | |
# $a1.m; | |
# say [$A ~~ R, $a1 ~~ R]; | |
# # OUTPUT: «oi‽[True True]» | |
ok 791 - doc/Language/typesystem.pod6 chunk 8 compiles | |
# class C {}; | |
# say C.HOW ~~ Metamodel::ClassHOW; | |
# # OUTPUT: «True» | |
ok 792 - doc/Language/typesystem.pod6 chunk 9 compiles | |
# class C { | |
# has $!priv; | |
# submethod BUILD { $!priv = 42 } | |
# }; | |
# say (.name, .package, .has_accessor) for C.new.^attributes; | |
# # OUTPUT: «($!priv (C) False)» | |
ok 793 - doc/Language/typesystem.pod6 chunk 10 compiles | |
# class A { | |
# multi method m(Int $i){ say 'Int' } | |
# multi method m(int $i){ say 'int' } | |
# } | |
# class B is A { | |
# method m(Int $i){ say 'B::Int' } | |
# } | |
# my int $i; | |
# B.new.m($i); | |
# # OUTPUT: «B::Int» | |
ok 794 - doc/Language/typesystem.pod6 chunk 11 compiles | |
# class C { | |
# has $.attr; | |
# submethod BUILD (:$attr = 42) { | |
# $!attr = $attr | |
# }; | |
# multi method new($positional) { | |
# self.bless(:attr($positional), |%_) | |
# } | |
# }; | |
# C.new.say; C.new('answer').say; | |
# # OUTPUT: «C.new(attr => 42) | |
# # C.new(attr => "answer")» | |
ok 795 - doc/Language/typesystem.pod6 chunk 12 compiles | |
# class Magic { | |
# method FALLBACK ($name, |c(Int, Str)) { | |
# put "$name called with parameters {c.perl}" } | |
# }; | |
# Magic.new.simsalabim(42, "answer"); | |
# # OUTPUT: «simsalabim called with parameters ⌈\(42, "answer")⌋» | |
ok 796 - doc/Language/typesystem.pod6 chunk 13 compiles | |
# class A { | |
# method WHAT { "ain't gonna happen" } | |
# }; | |
# say A.new.WHAT; # OUTPUT: «(A)» | |
# say A.new."WHAT"() # OUTPUT: «ain't gonna happen» | |
ok 797 - doc/Language/typesystem.pod6 chunk 14 compiles | |
# class C { | |
# our method packaged {}; | |
# method loose {} | |
# }; | |
# dd C::.keys | |
# # OUTPUT: «("\&packaged",).Seq» | |
ok 798 - doc/Language/typesystem.pod6 chunk 15 compiles | |
# class A { has $.i = 42 }; | |
# class B { | |
# has $.i = "answer"; | |
# method m() { A.new(:$.i) } | |
# }; | |
# my $a = B.new.m; | |
# say $a.i; # OUTPUT: «answer» | |
ok 799 - doc/Language/typesystem.pod6 chunk 16 compiles | |
# dd [[1,2,3],[4,5]]>>.elems; | |
# # OUTPUT: «(3, 2)» | |
ok 800 - doc/Language/typesystem.pod6 chunk 17 compiles | |
# multi sub trait_mod:<handles>(Attribute:D $target, $thunk) | |
ok 801 - doc/Language/typesystem.pod6 chunk 18 compiles | |
# class A { method m(){ 'A::m has been called.' } } | |
# class B is A { method m(){ 'B::m has been called.' } } | |
# class C { | |
# has A $.delegate handles 'm'; | |
# method new($delegate){ self.bless(delegate => $delegate) } | |
# }; | |
# say C.new(B.new).m(); # OUTPUT: «B::m has been called.» | |
ok 802 - doc/Language/typesystem.pod6 chunk 19 compiles | |
# class A { | |
# method m1(){} | |
# method m2(){} | |
# } | |
# class C { | |
# has $.delegate handles <m1 m2> = A.new() | |
# } | |
# C.new.m2; | |
# class D { | |
# has $.delegate handles /m\d/ = A.new() | |
# } | |
# D.new.m1; | |
# class E { | |
# has $.delegate handles (em1 => 'm1') = A.new() | |
# } | |
# E.new.em1; | |
ok 803 - doc/Language/typesystem.pod6 chunk 20 compiles | |
# multi sub trait_mod:<is>(Mu:U $child, Mu:U $parent) | |
ok 804 - doc/Language/typesystem.pod6 chunk 21 compiles | |
# class A { | |
# multi method from-a(){ 'A::from-a' } | |
# } | |
# dd A.new.^parents(:all); | |
# # OUTPUT: «(Any, Mu)» | |
# class B { | |
# method from-b(){ 'B::from-b ' } | |
# multi method from-a(){ 'B::from-A' } | |
# } | |
# class C is A is B {} | |
# dd C.new.from-a(); | |
# # OUTPUT: «"A::from-a"» | |
ok 805 - doc/Language/typesystem.pod6 chunk 22 compiles | |
# sub trait_mod:<is>(Mu:U $type, :$rw!) | |
ok 806 - doc/Language/typesystem.pod6 chunk 23 compiles | |
# class C is rw { | |
# has $.a; | |
# }; | |
# my $c = C.new.a = 42; | |
# dd $c; # OUTPUT: «Int $c = 42» | |
ok 807 - doc/Language/typesystem.pod6 chunk 24 compiles | |
# multi sub trait_mod:<is>(Attribute $attr, :$required!) | |
ok 808 - doc/Language/typesystem.pod6 chunk 25 compiles | |
# class Correct { | |
# has $.attr is required; | |
# submethod BUILD (:$attr) { $!attr = $attr } | |
# } | |
# say Correct.new(attr => 42); | |
# # OUTPUT: «Correct.new(attr => 42)» | |
# class C { | |
# has $.attr is required; | |
# } | |
# C.new; | |
# CATCH { default { say .^name => .Str } } | |
# # OUTPUT: «X::Attribute::Required => The attribute '$!attr' is required, but you did not provide a value for it.» | |
ok 809 - doc/Language/typesystem.pod6 chunk 26 compiles | |
# class A { | |
# method m { say 'i am hidden' } | |
# } | |
# class B hides A { | |
# method m { nextsame } | |
# method n { self.A::m } | |
# }; | |
# B.new.m; | |
# B.new.n; | |
# # OUTPUT: «i am hidden» | |
ok 810 - doc/Language/typesystem.pod6 chunk 27 compiles | |
# class A is hidden { | |
# method m { say 'i am hidden' } | |
# } | |
# class B is A { | |
# method m { nextsame } | |
# method n { self.A::m } | |
# } | |
# B.new.m; | |
# B.new.n; | |
# # OUTPUT: «i am hidden» | |
ok 811 - doc/Language/typesystem.pod6 chunk 28 compiles | |
# class B {...}; | |
# class A { | |
# trusts B; | |
# has $!foo; | |
# method !foo { return-rw $!foo } | |
# method perl { "A.new(foo => $!foo)" } | |
# }; | |
# class B { | |
# has A $.a .= new; | |
# method change { $!a!A::foo = 42; self } | |
# }; | |
# say B.new.change; | |
# # OUTPUT: «B.new(a => A.new(foo => 42))» | |
ok 812 - doc/Language/typesystem.pod6 chunk 29 compiles | |
# class C:ver<4.2.3>:auth<me@here.local> {} | |
# say [C.^ver, C.^auth]; | |
# # OUTPUT: «[v4.2.3 me@here.local]» | |
ok 813 - doc/Language/typesystem.pod6 chunk 30 compiles | |
# role Serialize { | |
# method to-string { self.Str } | |
# method to-number { self.Num } | |
# } | |
# class A does Serialize {} | |
# class B does Serialize {} | |
# my Serialize @list; | |
# @list.push: A.new; | |
# @list.push: B.new; | |
# say @list».to-string; | |
# # OUTPUT: «[A<57192848> B<57192880>]» | |
ok 814 - doc/Language/typesystem.pod6 chunk 31 compiles | |
# EVAL 'role R { method overload-this(){...} }; class A does R {}; '; | |
# CATCH { default { say .^name, ' ', .Str } } | |
# # OUTPUT: «X::Comp::AdHoc Method 'overload-this' must be implemented by A because it is required by a role» | |
ok 815 - doc/Language/typesystem.pod6 chunk 32 compiles | |
# role R { method m { say 'oi‽' } }; | |
# R.new.^mro.say; | |
# # OUTPUT: «((R) (Any) (Mu))» | |
# say R.new.^mro[0].HOW.^name; | |
# # OUTPUT: «Perl6::Metamodel::ClassHOW» | |
# say R.new ~~ R; | |
# # OUTPUT: «True» | |
ok 816 - doc/Language/typesystem.pod6 chunk 33 compiles | |
# role R2 {...}; | |
# role R1 does R2 {}; | |
# role R2 {}; | |
# class C does R1 {}; | |
# say [C ~~ R1, C ~~ R2]; | |
# # OUTPUT: «[True True]» | |
ok 817 - doc/Language/typesystem.pod6 chunk 34 compiles | |
# role R[$d] { has $.a = $d }; | |
# class C does R["default"] { }; | |
# my $c = C.new; | |
# dd $c; | |
# # OUTPUT: «C $c = C.new(a => "default")» | |
ok 818 - doc/Language/typesystem.pod6 chunk 35 compiles | |
# class A {}; | |
# class B {}; | |
# subset A-or-B where * ~~ A|B; | |
# role R[A-or-B ::T] {}; | |
# R[A.new].new; | |
ok 819 - doc/Language/typesystem.pod6 chunk 36 compiles | |
# role R[$p = fail("Please provide a parameter to role R")] {}; | |
# my $i = 1 does R; | |
# CATCH { default { say .^name, ': ', .Str} } | |
# # OUTPUT: «X::AdHoc: Could not instantiate role 'R':Please provide a parameter to role R» | |
ok 820 - doc/Language/typesystem.pod6 chunk 37 compiles | |
# role R:ver<4.2.3>:auth<me@here.local> {} | |
# say [R.^ver, R.^auth]; | |
# # OUTPUT: «[v4.2.3 me@here.local]» | |
ok 821 - doc/Language/typesystem.pod6 chunk 38 compiles | |
# enum Names ( name1 => 1, name2 => 2 ); | |
# say name1, ' ', name2; # OUTPUT: «name1 name2» | |
# say name1.value, ' ', name2.value; # OUTPUT: «1 2» | |
ok 822 - doc/Language/typesystem.pod6 chunk 39 compiles | |
# enum Names ( name1 => 1, name2 => 2 ); | |
# sub same(Names $a, Names $b){ | |
# $a eqv $b | |
# } | |
# say same(name1, name1); # OUTPUT: «True» | |
# say same(name1, name2); # OUTPUT: «False» | |
# my $a = name1; | |
# say $a ~~ Names; # OUTPUT: «True» | |
# say $a.WHAT; # OUTPUT: «Names» | |
ok 823 - doc/Language/typesystem.pod6 chunk 40 compiles | |
# enum Mass ( mg => 1/1000, g => 1/1, kg => 1000/1 ); | |
# dd Mass.enums; # OUTPUT: «{:g(1.0), :kg(1000.0), :mg(0.001)}» | |
ok 824 - doc/Language/typesystem.pod6 chunk 41 compiles | |
# enum Numbers <one two three four>; | |
# dd Numbers.enums; # OUTPUT: «{:four(3), :one(0), :three(2), :two(1)}» | |
ok 825 - doc/Language/typesystem.pod6 chunk 42 compiles | |
# enum Numbers «:one(1) two three four»; | |
# dd Numbers.enums; # OUTPUT: «{:four(4), :one(1), :three(3), :two(2)}» | |
ok 826 - doc/Language/typesystem.pod6 chunk 43 compiles | |
# my $e = enum <one two three>; | |
# say two; # OUTPUT: «two()(Map)» | |
# say one.WHAT; # OUTPUT: «()» | |
# say $e.WHAT; # OUTPUT: «(Map)» | |
ok 827 - doc/Language/typesystem.pod6 chunk 44 compiles | |
# enum E(<one two>); dd E::.values; | |
# # OUTPUT: «(E::two, E::one).Seq» | |
ok 828 - doc/Language/typesystem.pod6 chunk 45 compiles | |
# enum E(<a b c>); | |
# say E.HOW ~~ Metamodel::EnumHOW; | |
# # OUTPUT: «True» | |
ok 829 - doc/Language/typesystem.pod6 chunk 46 compiles | |
# method enums() | |
ok 830 - doc/Language/typesystem.pod6 chunk 47 compiles | |
# enum Mass ( mg => 1/1000, g => 1/1, kg => 1000/1 ); | |
# say Mass.enums, g.enums; # OUTPUT: «{g => 1, kg => 1000, mg => 0.001}{g => 1, kg => 1000, mg => 0.001}» | |
ok 831 - doc/Language/typesystem.pod6 chunk 48 compiles | |
# module M:ver<4.2.3>:auth<me@here.local> {} | |
# say [M.^ver, M.^auth]; | |
# # OUTPUT: «[v4.2.3 me@here.local]» | |
ok 832 - doc/Language/typesystem.pod6 chunk 49 compiles | |
# grammar G:ver<4.2.3>:auth<me@here.local> {} | |
# say [G.^ver, G.^auth]; | |
# # OUTPUT: «[v4.2.3 me@here.local]» | |
ok 833 - doc/Language/typesystem.pod6 chunk 50 compiles | |
# subset Positive of Int where * > -1; | |
# my Positive $i = 1; | |
# $i = -42; | |
# CATCH { default { put .^name,': ', .Str } } | |
# # OUTPUT: «X::TypeCheck::Assignment: Type check failed in assignment to $i; expected Positive but got Int (-42) …» | |
ok 834 - doc/Language/typesystem.pod6 chunk 51 compiles | |
# my enum E1 <A B>; | |
# my enum E2 <C D>; | |
# sub g(@a where { .all ~~ subset :: where E1|E2 } ) { | |
# say @a | |
# } | |
# g([A, C]); | |
# # OUTPUT: «[A C]» | |
ok 835 - doc/Language/typesystem.pod6 chunk 52 compiles | |
# say "\c[PENGUIN]"; # OUTPUT: «🐧» | |
# say "\c[BELL]"; # OUTPUT: «🔔» (U+1F514 BELL) | |
ok 836 - doc/Language/unicode.pod6 chunk 1 compiles | |
# say "\c[latin capital letter E]"; # OUTPUT: «E» (U+0045) | |
ok 837 - doc/Language/unicode.pod6 chunk 2 compiles | |
# say "\c[ALERT]"; # Not visible (U+0007 control code (also accessible as \a)) | |
# say "\c[LINE FEED]"; # Not visible (U+000A same as "\n") | |
ok 838 - doc/Language/unicode.pod6 chunk 3 compiles | |
# say "\c[LATIN CAPITAL LETTER GHA]"; # OUTPUT: «Ƣ» | |
# say "Ƣ".uniname; # OUTPUT: «LATIN CAPITAL LETTER OI» | |
# # This one is a spelling mistake that was corrected in a Name Alias: | |
# say "\c[PRESENTATION FORM FOR VERTICAL RIGHT WHITE LENTICULAR BRACKET]".uniname; | |
# # OUTPUT: «PRESENTATION FORM FOR VERTICAL RIGHT WHITE LENTICULAR BRAKCET» | |
ok 839 - doc/Language/unicode.pod6 chunk 4 compiles | |
# say "\c[ZWJ]".uniname; # OUTPUT: «ZERO WIDTH JOINER» | |
# say "\c[NBSP]".uniname; # OUTPUT: «NO-BREAK SPACE» | |
ok 840 - doc/Language/unicode.pod6 chunk 5 compiles | |
# say "\c[LATIN CAPITAL LETTER E WITH VERTICAL LINE BELOW AND ACUTE]"; # OUTPUT: «É̩» | |
# say "\c[LATIN CAPITAL LETTER E WITH VERTICAL LINE BELOW AND ACUTE]".ords; # OUTPUT: «(201 809)» | |
ok 841 - doc/Language/unicode.pod6 chunk 6 compiles | |
# say "\c[woman gesturing OK]"; # OUTPUT: «🙆♀️» | |
# say "\c[family: man woman girl boy]"; # OUTPUT: «👨👩👧👦» | |
ok 842 - doc/Language/unicode.pod6 chunk 7 compiles | |
# say 「What?!」; | |
# say ”Whoa!“; | |
# say „This works too!”; | |
# say „There are just too many ways“; | |
# say “here: “no problem” at all!”; # You can nest them! | |
ok 843 - doc/Language/unicode_entry.pod6 chunk 1 compiles | |
# say (1, 2) »+« (3, 4); # OUTPUT: «(4 6)» - element-wise add | |
# [1, 2, 3] »+=» 42; # add 42 to each element of @array | |
# say «moo»; # OUTPUT: «moo» | |
# my $baa = 123; say «$baa»; # OUTPUT: «(123)» | |
ok 844 - doc/Language/unicode_entry.pod6 chunk 2 compiles | |
# my $var = 19; # U+FF11 U+FF19 | |
# say $var + 2; # OUTPUT: «21» | |
ok 845 - doc/Language/unicode_texas.pod6 chunk 1 compiles | |
# my $var = ⅒ + 2 + Ⅻ; # here ⅒ is No and Rat and Ⅻ is Nl and Int | |
# say $var; # OUTPUT: «14.1» | |
ok 846 - doc/Language/unicode_texas.pod6 chunk 2 compiles | |
# my $square = 9 ** 2; | |
# my @array = 1, 2, 3; # Array variable with three elements | |
# my %hash = London => 'UK', Berlin => 'Germany'; | |
ok 847 - doc/Language/variables.pod6 chunk 1 compiles | |
# class FailHash is Hash { | |
# has Bool $!final = False; | |
# multi method AT-KEY ( ::?CLASS:D: Str:D \key ){ | |
# fail X::OutOfRange.new(:what("Hash key"), :got(key), :range(self.keys)) if $!final && !self.EXISTS-KEY(key); | |
# callsame | |
# } | |
# method finalize() { | |
# $!final = True | |
# } | |
# } | |
# my %h is FailHash = oranges => "round", bananas => "bendy"; | |
# say %h<oranges>; | |
# # OUTPUT: «round» | |
# %h.finalize; | |
# say %h<cherry>; | |
# CATCH { default { put .^name, ': ', .Str } } | |
# # OUTPUT: «X::OutOfRange: Hash key out of range. Is: cherry, should be in (oranges bananas)» | |
ok 848 - doc/Language/variables.pod6 chunk 2 compiles | |
# my $foo = 5; # item assignment | |
# say $foo.perl; # OUTPUT: «5» | |
# my @bar = 7, 9; # list assignment | |
# say @bar.WHAT; # OUTPUT: «(Array)» | |
# say @bar.perl; # OUTPUT: «[7, 9]» | |
# (my $baz) = 11, 13; # list assignment | |
# say $baz.WHAT; # OUTPUT: «(List)» | |
# say $baz.perl; # OUTPUT: «(11, 13)» | |
ok 849 - doc/Language/variables.pod6 chunk 3 compiles | |
# my @array; | |
# @array = my $num = 42, "str"; # item assignment: uses declarator | |
# say @array.perl; # OUTPUT: «[42, "str"]» (an Array) | |
# say $num.perl; # OUTPUT: «42» (a Num) | |
ok 850 - doc/Language/variables.pod6 chunk 4 compiles | |
# my $num; | |
# my @array = $num = 42, "str"; # item assignment: uses expression | |
# say @array.perl; # OUTPUT: «[42, "str"]» (an Array) | |
# say $num.perl; # OUTPUT: «42» (a Num) | |
# my ( @foo, $bar ); | |
# @foo = ($bar) = 42, "str"; # list assignment: uses parentheses | |
# say @foo.perl; # OUTPUT: «[42, "str"]» (an Array) | |
# say $bar.perl; # OUTPUT: «$(42, "str")» (a List)# | |
ok 851 - doc/Language/variables.pod6 chunk 5 compiles | |
# my ( @array, $num ); | |
# @array = $num = 42, "str"; # list assignment | |
# say @array.perl; # OUTPUT: «[42, "str"]» | |
# say $num.perl; # OUTPUT: «[42, "str"]» | |
ok 852 - doc/Language/variables.pod6 chunk 6 compiles | |
# my \degrees = pi / 180; | |
# my \θ = 15 * degrees; | |
ok 853 - doc/Language/variables.pod6 chunk 7 compiles | |
# sub logged(&f, |args) { | |
# say('Calling ' ~ &f.name ~ ' with arguments ' ~ args.perl); | |
# my \result = f(|args); | |
# # ^^^^^^^ not enforcing any context here | |
# say(&f.name ~ ' returned ' ~ result.perl); | |
# return |result; | |
# } | |
ok 854 - doc/Language/variables.pod6 chunk 8 compiles | |
# my $lexical = 1; | |
# my $*dynamic1 = 10; | |
# my $*dynamic2 = 100; | |
# sub say-all() { | |
# say "$lexical, $*dynamic1, $*dynamic2"; | |
# } | |
# # prints 1, 10, 100 | |
# say-all(); | |
# { | |
# my $lexical = 2; | |
# my $*dynamic1 = 11; | |
# $*dynamic2 = 101; | |
# # prints 1, 11, 101 | |
# say-all(); | |
# } | |
# # prints 1, 10, 101 | |
# say-all(); | |
ok 855 - doc/Language/variables.pod6 chunk 9 compiles | |
# sub foo() { | |
# $*FOO // 'foo'; | |
# } | |
# say foo; # OUTPUT: «foo» | |
# my $*FOO = 'bar'; | |
# say foo; # OUTPUT: «bar» | |
ok 856 - doc/Language/variables.pod6 chunk 10 compiles | |
# my class Point { | |
# has $.x; | |
# has $.y; | |
# method Str() { | |
# "($!x, $!y)" | |
# } | |
# } | |
ok 857 - doc/Language/variables.pod6 chunk 11 compiles | |
# say "$?FILE: $?LINE"; # prints "hello.pl: 23" if this is the 23 line of a | |
# # file named "hello.pl". | |
ok 858 - doc/Language/variables.pod6 chunk 12 compiles | |
# my class Point { | |
# has $.x; | |
# has $.y; | |
# method Str() { | |
# "($.x, $.y)" # note that we use the . instead of ! this time | |
# } | |
# } | |
ok 859 - doc/Language/variables.pod6 chunk 13 compiles | |
# class SaySomething { | |
# method a() { say "a"; } | |
# method b() { $.a; } | |
# } | |
# SaySomething.b; # OUTPUT: «a» | |
ok 860 - doc/Language/variables.pod6 chunk 14 compiles | |
# for ^4 { | |
# say "$^b follows $^a"; | |
# } | |
# # OUTPUT: «1 follows 0 | |
# # 3 follows 2» | |
ok 861 - doc/Language/variables.pod6 chunk 15 compiles | |
# say { $:add ?? $^a + $^b !! $^a - $^b }( 4, 5 ) :!add | |
# # OUTPUT: «-1» | |
ok 862 - doc/Language/variables.pod6 chunk 16 compiles | |
# my $amazing-variable = "World"; | |
# say "Hello $amazing-variable!"; # OUTPUT: «Hello World!» | |
ok 863 - doc/Language/variables.pod6 chunk 17 compiles | |
# my $location = "outside"; | |
# sub outer-location { | |
# # Not redefined: | |
# say $location; | |
# } | |
# outer-location; # OUTPUT: «outside» | |
# sub in-building { | |
# my $location = "inside"; | |
# say $location; | |
# } | |
# in-building; # OUTPUT: «inside» | |
# outer-location; # OUTPUT: «outside» | |
ok 864 - doc/Language/variables.pod6 chunk 18 compiles | |
# module M { | |
# our $Var; | |
# # $Var available here | |
# } | |
# # Available as $M::Var here. | |
ok 865 - doc/Language/variables.pod6 chunk 19 compiles | |
# my (@a, $s, %h); | |
ok 866 - doc/Language/variables.pod6 chunk 20 compiles | |
# my (Str $a, Str $b, Int $c) = <a b>; | |
# say [$a, $b, $c].perl; | |
# # OUTPUT: «["a", "b", Int]» | |
ok 867 - doc/Language/variables.pod6 chunk 21 compiles | |
# sub f { 1,2,3 }; | |
# my ($a) = f; | |
# say $a.perl; | |
# # OUTPUT: «1» | |
ok 868 - doc/Language/variables.pod6 chunk 22 compiles | |
# my ($,$a,$,%h) = ('a', 'b', [1,2,3], {:1th}); | |
# say [$a, %h].perl; | |
# # OUTPUT: «["b", {:th(1)}]» | |
ok 869 - doc/Language/variables.pod6 chunk 23 compiles | |
# my %operations = | |
# half => anon sub half($x) { $x / 2 }, | |
# square => anon sub square($x) { $x * $x }, | |
# ; | |
# say %operations<square>.name; # square | |
# say %operations<square>(8); # 64 | |
ok 870 - doc/Language/variables.pod6 chunk 24 compiles | |
# sub a { | |
# state @x; | |
# state $l = 'A'; | |
# @x.push($l++); | |
# }; | |
# say a for 1..6; | |
ok 871 - doc/Language/variables.pod6 chunk 25 compiles | |
# ({ state $i = 1; $i++.say; } xx 3).map: {$_(), $_()}; # says 1 then 2 thrice | |
ok 872 - doc/Language/variables.pod6 chunk 26 compiles | |
# my @a; | |
# sub f() { | |
# state $i; | |
# $i++; | |
# @a.push: "k$i" => $i # <-- .clone goes here | |
# }; | |
# f for 1..3; | |
# dd @a; # «Array $var = $[:k1(3), :k2(3), :k3(3)]» | |
ok 873 - doc/Language/variables.pod6 chunk 27 compiles | |
# sub code(){ state $i = 0; say ++$i; $i }; | |
# await | |
# start { loop { last if code() >= 5 } }, | |
# start { loop { last if code() >= 5 } }; | |
# # OUTPUT: «1234435» | |
# # OUTPUT: «21345» | |
# # many other more or less odd variations can be produced | |
ok 874 - doc/Language/variables.pod6 chunk 28 compiles | |
# say "1-a 2-b 3-c".subst(:g, /\d/, {<one two three>[$++]}); | |
# # OUTPUT: «one-a two-b three-c» | |
ok 875 - doc/Language/variables.pod6 chunk 29 compiles | |
# sub foo() { | |
# given ++$ { | |
# when 1 { | |
# say "one"; | |
# } | |
# when 2 { | |
# say "two"; | |
# } | |
# when 3 { | |
# say "three"; | |
# } | |
# default { | |
# say "many"; | |
# } | |
# } | |
# } | |
# foo() for ^3; | |
# # OUTPUT: «onetwothree» | |
ok 876 - doc/Language/variables.pod6 chunk 30 compiles | |
# sub foo($x) { | |
# say (@).push($x); | |
# } | |
# foo($_) for ^3; | |
# # OUTPUT: «[0] | |
# # [0 1] | |
# # [0 1 2]» | |
ok 877 - doc/Language/variables.pod6 chunk 31 compiles | |
# sub foo($x) { | |
# my $v = @; | |
# $v[$x] = $x; | |
# say $v; | |
# } | |
# foo($_) for ^3; | |
# # OUTPUT: «[0] | |
# # [0 1] | |
# # [0 1 2]» | |
ok 878 - doc/Language/variables.pod6 chunk 32 compiles | |
# sub foo($x) { | |
# say (%).push($x => $x); | |
# } | |
# foo($_) for ^3; | |
# # OUTPUT: «0 => 0 | |
# # 0 => 0, 1 => 1 | |
# # 0 => 0, 1 => 1, 2 => 2» | |
ok 879 - doc/Language/variables.pod6 chunk 33 compiles | |
# sub foo($x) { | |
# my $v = %; | |
# $v{$x} = $x; | |
# say $v; | |
# } | |
# foo($_) for ^3; | |
# # OUTPUT: «0 => 0 | |
# # 0 => 0, 1 => 1 | |
# # 0 => 0, 1 => 1, 2 => 2» | |
ok 880 - doc/Language/variables.pod6 chunk 34 compiles | |
# # don't do this | |
# use MONKEY-TYPING; | |
# augment class Int { | |
# method is-answer { self == 42 } | |
# } | |
# say 42.is-answer; # OUTPUT: «True» | |
ok 881 - doc/Language/variables.pod6 chunk 35 compiles | |
# my $in = 0; # temp will "entangle" the global variable with the call stack | |
# # that keeps the calls at the bottom in order. | |
# sub f(*@c) { | |
# (temp $in)++; | |
# "<f>\n" | |
# ~ @c».indent($in).join("\n") | |
# ~ (+@c ?? "\n" !! "") | |
# ~ '</f>' | |
# }; | |
# sub g(*@c) { | |
# (temp $in)++; | |
# "<g>\n" | |
# ~ @c».indent($in).join("\n") | |
# ~ (+@c ?? "\n" !! "") | |
# ~ "</g>" | |
# }; | |
# print g(g(f(g()), g(), f())); | |
# # OUTPUT: «<g> | |
# # <g> | |
# # <f> | |
# # <g> | |
# # </g> | |
# # </f> | |
# # <g> | |
# # </g> | |
# # <f> | |
# # </f> | |
# # </g> | |
# # </g>» | |
ok 882 - doc/Language/variables.pod6 chunk 36 compiles | |
# my $answer = 42; | |
# { | |
# let $answer = 84; | |
# die if not Bool.pick; | |
# CATCH { | |
# default { say "it's been reset :(" } | |
# } | |
# say "we made it 84 sticks!"; | |
# } | |
# say $answer; | |
ok 883 - doc/Language/variables.pod6 chunk 37 compiles | |
# my Int $x = 42; | |
# $x = 'a string'; | |
# CATCH { default { put .^name, ': ', .Str } } | |
# # OUTPUT: «X::TypeCheck::Assignment: Type check failed in assignment to $x; expected Int but got Str ("a string")» | |
ok 884 - doc/Language/variables.pod6 chunk 38 compiles | |
# my Int $x; | |
# say $x.^name; # OUTPUT: «Int» | |
# say $x.defined; # OUTPUT: «False» | |
ok 885 - doc/Language/variables.pod6 chunk 39 compiles | |
# my Real $product is default(1); | |
# say $product; # OUTPUT: «1» | |
# $product *= 5; | |
# say $product; # OUTPUT: «5» | |
# $product = Nil; | |
# say $product; # OUTPUT: «1» | |
ok 886 - doc/Language/variables.pod6 chunk 40 compiles | |
# for <a b c> { say $_ } # sets $_ to 'a', 'b' and 'c' in turn | |
# say $_ for <a b c>; # same, even though it's not a block | |
# given 'a' { say $_ } # sets $_ to 'a' | |
# say $_ given 'a'; # same, even though it's not a block | |
ok 887 - doc/Language/variables.pod6 chunk 41 compiles | |
# .say; # same as $_.say | |
ok 888 - doc/Language/variables.pod6 chunk 42 compiles | |
# say "Looking for strings with non-alphabetic characters..."; | |
# for <ab:c d$e fgh ij*> { | |
# .say if m/<!alpha>/; | |
# } | |
# # OUTPUT: «Looking for strings with non-alphabetic characters... | |
# # ab:c | |
# # d$e | |
# # ij*» | |
ok 889 - doc/Language/variables.pod6 chunk 43 compiles | |
# 'abc 12' ~~ /\w+/; # sets $/ to a Match object | |
# say $/.Str; # OUTPUT: «abc» | |
ok 890 - doc/Language/variables.pod6 chunk 44 compiles | |
# 'abbbbbcdddddeffg' ~~ / a (b+) c (d+ef+) g /; | |
# say $/[0]; # OUTPUT: «「bbbbb」» | |
# say $/[1]; # OUTPUT: «「dddddeff」» | |
ok 891 - doc/Language/variables.pod6 chunk 45 compiles | |
# say $0; # OUTPUT: «「bbbbb」» | |
# say $1; # OUTPUT: «「dddddeff」» | |
ok 892 - doc/Language/variables.pod6 chunk 46 compiles | |
# say @().join; # OUTPUT: «bbbbbdddddeff» | |
ok 893 - doc/Language/variables.pod6 chunk 47 compiles | |
# 'I.... see?' ~~ / \w+ $<punctuation>=[ <-[\w\s]>+ ] \s* $<final-word> = [ \w+ . ] /; | |
# say $/<punctuation>; # OUTPUT: «「....」» | |
# say $/<final-word>; # OUTPUT: «「see?」» | |
ok 894 - doc/Language/variables.pod6 chunk 48 compiles | |
# say $<punctuation>; # OUTPUT: «「....」» | |
# say $<final-word>; # OUTPUT: «「see?」» | |
ok 895 - doc/Language/variables.pod6 chunk 49 compiles | |
# say %().join; # OUTPUT: «"punctuation ....final-word see?"» | |
ok 896 - doc/Language/variables.pod6 chunk 50 compiles | |
# my $*SCHEDULER = ThreadPoolScheduler.new( max_threads => 64 ); | |
ok 897 - doc/Language/variables.pod6 chunk 51 compiles | |
# my $a = 42; | |
# my %hash = "a" => 1, "b" => 2, "c" => 3; | |
# dd %hash, $a; | |
# # %hash = ("a" => 1, "c" => 3, "b" => 2).hash, $a = 42 | |
ok 898 - doc/Programs/01-debugging.pod6 chunk 1 compiles | |
# dd \((:a(1), :b(2)), :c(3)); | |
# dd [(:a(1), :b(2)), :c(3)]; | |
ok 899 - doc/Programs/01-debugging.pod6 chunk 2 compiles | |
# sub a { dd }; a # sub a | |
ok 900 - doc/Programs/01-debugging.pod6 chunk 3 compiles | |
# class AST { } | |
ok 901 - doc/Type/AST.pod6 chunk 1 compiles | |
# class Any is Mu {} | |
ok 902 - doc/Type/Any.pod6 chunk 1 compiles | |
# multi method ACCEPTS(Any:D: Mu $other) | |
ok 903 - doc/Type/Any.pod6 chunk 2 compiles | |
# method any(--> Junction:D) | |
ok 904 - doc/Type/Any.pod6 chunk 3 compiles | |
# say so 2 == <1 2 3>.any; # OUTPUT: «True» | |
# say so 5 == <1 2 3>.any; # OUTPUT: «False» | |
ok 905 - doc/Type/Any.pod6 chunk 4 compiles | |
# method all(--> Junction:D) | |
ok 906 - doc/Type/Any.pod6 chunk 5 compiles | |
# say so 1 < <2 3 4>.all; # OUTPUT: «True» | |
# say so 3 < <2 3 4>.all; # OUTPUT: «False» | |
ok 907 - doc/Type/Any.pod6 chunk 6 compiles | |
# method one(--> Junction:D) | |
ok 908 - doc/Type/Any.pod6 chunk 7 compiles | |
# say so 1 == (1, 2, 3).one; # OUTPUT: «True» | |
# say so 1 == (1, 2, 1).one; # OUTPUT: «False» | |
ok 909 - doc/Type/Any.pod6 chunk 8 compiles | |
# method none(--> Junction:D) | |
ok 910 - doc/Type/Any.pod6 chunk 9 compiles | |
# say so 1 == (1, 2, 3).none; # OUTPUT: «False» | |
# say so 4 == (1, 2, 3).none; # OUTPUT: «True» | |
ok 911 - doc/Type/Any.pod6 chunk 10 compiles | |
# method list(--> List:D) | |
ok 912 - doc/Type/Any.pod6 chunk 11 compiles | |
# say 42.list.^name; # OUTPUT: «List» | |
# say 42.list.elems; # OUTPUT: «1» | |
ok 913 - doc/Type/Any.pod6 chunk 12 compiles | |
# method push(|values --> Positional:D) | |
ok 914 - doc/Type/Any.pod6 chunk 13 compiles | |
# my %h; | |
# dd %h<a>; # Any (and therefore undefined) | |
# %h<a>.push(1); # .push on Any | |
# dd %h; # «Hash %h = {:a($[1])}» # please note the Array | |
ok 915 - doc/Type/Any.pod6 chunk 14 compiles | |
# multi sub reverse(*@list --> List:D) | |
# multi method reverse(List:D: --> List:D) | |
ok 916 - doc/Type/Any.pod6 chunk 15 compiles | |
# say <hello world!>.reverse; # OUTPUT: «(world! hello)» | |
# say reverse ^10; # OUTPUT: «(9 8 7 6 5 4 3 2 1 0)» | |
ok 917 - doc/Type/Any.pod6 chunk 16 compiles | |
# say <b c a>.sort; # OUTPUT: «(a b c)» | |
# say 'bca'.comb.sort.join; # OUTPUT: «abc» | |
# say 'bca'.comb.sort({$^b cmp $^a}).join; # OUTPUT: «cba» | |
# say '231'.comb.sort(&infix:«<=>»).join; # OUTPUT: «123» | |
ok 918 - doc/Type/Any.pod6 chunk 17 compiles | |
# multi method map(\SELF: █; :$label, :$item) | |
# multi method map(HyperIterable:D: █; :$label) | |
ok 919 - doc/Type/Any.pod6 chunk 18 compiles | |
# method deepmap(&block --> List) is nodal | |
ok 920 - doc/Type/Any.pod6 chunk 19 compiles | |
# dd [[1,2,3],[[4,5],6,7]].deepmap(*+1); | |
# # OUTPUT: «[[2, 3, 4], [[5, 6], 7, 8]]» | |
ok 921 - doc/Type/Any.pod6 chunk 20 compiles | |
# method duckmap(&block) is rw is nodal | |
ok 922 - doc/Type/Any.pod6 chunk 21 compiles | |
# my @a = [1,[2,3],4]; | |
# dd @a.duckmap({ $_ ~~ Int ?? $_++ !! Any }); | |
# # OUTPUT: «(1, (2, 3), 4)» | |
ok 923 - doc/Type/Any.pod6 chunk 22 compiles | |
# method flat(--> Seq:D) is nodal | |
ok 924 - doc/Type/Any.pod6 chunk 23 compiles | |
# say ((1, 2), (3)).elems; # OUTPUT: «2» | |
# say ((1, 2), (3)).flat.elems; # OUTPUT: «3» | |
ok 925 - doc/Type/Any.pod6 chunk 24 compiles | |
# my @a = [[1,2,3],[[4,5],6,7]]; | |
# say gather deepmap *.take, @a; # OUTPUT: «(1 2 3 4 5 6 7)» | |
ok 926 - doc/Type/Any.pod6 chunk 25 compiles | |
# method eager(--> Seq:D) is nodal | |
ok 927 - doc/Type/Any.pod6 chunk 26 compiles | |
# say (1..10).eager; # OUTPUT: «(1 2 3 4 5 6 7 8 9 10)» | |
ok 928 - doc/Type/Any.pod6 chunk 27 compiles | |
# method elems(--> Int:D) is nodal | |
ok 929 - doc/Type/Any.pod6 chunk 28 compiles | |
# say 42.elems; # OUTPUT: «1» | |
# say <a b c>.elems; # OUTPUT: «3» | |
ok 930 - doc/Type/Any.pod6 chunk 29 compiles | |
# method end(--> Any:D) is nodal | |
ok 931 - doc/Type/Any.pod6 chunk 30 compiles | |
# say 6.end; # OUTPUT: «0» | |
# say <a b c>.end; # OUTPUT: «2» | |
ok 932 - doc/Type/Any.pod6 chunk 31 compiles | |
# method pairup(--> Seq:D) is nodal | |
ok 933 - doc/Type/Any.pod6 chunk 32 compiles | |
# say (a => 1, 'b', 'c').pairup.perl; # OUTPUT: «(:a(1), :b("c")).Seq» | |
ok 934 - doc/Type/Any.pod6 chunk 33 compiles | |
# sub exit(Int() $status = 0) | |
ok 935 - doc/Type/Any.pod6 chunk 34 compiles | |
# proto sub item(|) is pure | |
# multi sub item(\x) | |
# multi sub item(|c) | |
# multi sub item(Mu $a) | |
ok 936 - doc/Type/Any.pod6 chunk 35 compiles | |
# say item([1,2,3]).perl; # OUTPUT: «$[1, 2, 3]» | |
# say item({ apple => 10 }).perl; # OUTPUT: «${:apple(10)}» | |
# say item("abc").perl; # OUTPUT: «"abc"» | |
ok 937 - doc/Type/Any.pod6 chunk 36 compiles | |
# say $[1,2,3].perl; # OUTPUT: «$[1, 2, 3]» | |
# say $("abc").perl; # OUTPUT: «"abc"» | |
ok 938 - doc/Type/Any.pod6 chunk 37 compiles | |
# method Array(--> Array:D) is nodal | |
ok 939 - doc/Type/Any.pod6 chunk 38 compiles | |
# method List(--> List:D) is nodal | |
ok 940 - doc/Type/Any.pod6 chunk 39 compiles | |
# method Hash(--> Hash:D) is nodal | |
ok 941 - doc/Type/Any.pod6 chunk 40 compiles | |
# method hash(--> Hash:D) is nodal | |
ok 942 - doc/Type/Any.pod6 chunk 41 compiles | |
# method Slip(--> Slip:D) is nodal | |
ok 943 - doc/Type/Any.pod6 chunk 42 compiles | |
# method Map(--> Map:D) is nodal | |
ok 944 - doc/Type/Any.pod6 chunk 43 compiles | |
# method Bag(--> Bag:D) is nodal | |
ok 945 - doc/Type/Any.pod6 chunk 44 compiles | |
# method BagHash(--> BagHash:D) is nodal | |
ok 946 - doc/Type/Any.pod6 chunk 45 compiles | |
# method Set(--> Set:D) is nodal | |
ok 947 - doc/Type/Any.pod6 chunk 46 compiles | |
# method SetHash(--> SetHash:D) is nodal | |
ok 948 - doc/Type/Any.pod6 chunk 47 compiles | |
# method Mix(--> Mix:D) is nodal | |
ok 949 - doc/Type/Any.pod6 chunk 48 compiles | |
# method MixHash(--> MixHash:D) is nodal | |
ok 950 - doc/Type/Any.pod6 chunk 49 compiles | |
# method Supply(--> Supply:D) is nodal | |
ok 951 - doc/Type/Any.pod6 chunk 50 compiles | |
# multi method min(--> Any:D) | |
# multi method min(&by --> Any:D) | |
ok 952 - doc/Type/Any.pod6 chunk 51 compiles | |
# multi method max(--> Any:D) | |
# multi method min(&by --> Any:D) | |
ok 953 - doc/Type/Any.pod6 chunk 52 compiles | |
# multi method minmax(--> List:D) | |
# multi method minmax(&by --> List:D) | |
ok 954 - doc/Type/Any.pod6 chunk 53 compiles | |
# class Array is List {} | |
ok 955 - doc/Type/Array.pod6 chunk 1 compiles | |
# multi sub pop(Array:D ) | |
# multi method pop(Array:D:) | |
ok 956 - doc/Type/Array.pod6 chunk 2 compiles | |
# my @foo = <a b>; # a b | |
# @foo.pop; # b | |
# pop @foo; # a | |
# pop @foo; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Cannot::Empty: Cannot pop from an empty Array» | |
ok 957 - doc/Type/Array.pod6 chunk 3 compiles | |
# multi sub push(Array:D, **@values --> Array:D) | |
# multi method push(Array:D: **@values --> Array:D) | |
ok 958 - doc/Type/Array.pod6 chunk 4 compiles | |
# my @foo = <a b c>; | |
# @foo.push: 'd'; | |
# say @foo; # OUTPUT: «[a b c d]» | |
ok 959 - doc/Type/Array.pod6 chunk 5 compiles | |
# my @a = <a b c>; | |
# my @b = <d e f>; | |
# @a.push: @b; | |
# say @a.elems; # OUTPUT: «4» | |
# say @a[3].join; # OUTPUT: «def» | |
ok 960 - doc/Type/Array.pod6 chunk 6 compiles | |
# my @a = '1'; | |
# my @b = <a b>; | |
# my @c = <E F>; | |
# @a.push: @b, @c; | |
# say @a.elems; # OUTPUT: «3» | |
ok 961 - doc/Type/Array.pod6 chunk 7 compiles | |
# multi method append(Array:D: \values) | |
# multi method append(Array:D: **@values is raw) | |
ok 962 - doc/Type/Array.pod6 chunk 8 compiles | |
# my @a = <a b c>; | |
# my @b = <d e f>; | |
# @a.append: @b; | |
# say @a.elems; # OUTPUT: «6» | |
# say @a; # OUTPUT: «[a b c d e f]» | |
ok 963 - doc/Type/Array.pod6 chunk 9 compiles | |
# method clone(Array:D: --> Array:D) | |
ok 964 - doc/Type/Array.pod6 chunk 10 compiles | |
# my @a = <a b c>; my @b = @a.clone; | |
# @b[1] = 42; @a.push: 72; | |
# say @b; # OUTPUT: «[a 42 c]» | |
# say @a; # OUTPUT: «[a b c 72]» | |
ok 965 - doc/Type/Array.pod6 chunk 11 compiles | |
# my @a = 1, {rand} … ∞; my @b = @a.clone; | |
# say @b[^3]; # OUTPUT: «(1 0.0216426755282736 0.567660896142156)» | |
# say @a[^3]; # OUTPUT: «(1 0.0216426755282736 0.567660896142156)» | |
ok 966 - doc/Type/Array.pod6 chunk 12 compiles | |
# multi sub shift(Array:D ) | |
# multi method shift(Array:D:) | |
ok 967 - doc/Type/Array.pod6 chunk 13 compiles | |
# my @foo = <a b>; | |
# say @foo.shift; # OUTPUT: «a» | |
# say @foo.shift; # OUTPUT: «b» | |
# say @foo.shift; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Cannot::Empty: Cannot shift from an empty Array» | |
ok 968 - doc/Type/Array.pod6 chunk 14 compiles | |
# multi sub unshift(Array:D, **@values --> Array:D) | |
# multi method unshift(Array:D: **@values --> Array:D) | |
ok 969 - doc/Type/Array.pod6 chunk 15 compiles | |
# my @foo = <a b c>; | |
# @foo.unshift: 1, 3 ... 11; | |
# say @foo; # OUTPUT: «[(1 3 5 7 9 11) a b c]» | |
ok 970 - doc/Type/Array.pod6 chunk 16 compiles | |
# multi method prepend(Array:D: \values) | |
# multi method prepend(Array:D: **@values is raw) | |
ok 971 - doc/Type/Array.pod6 chunk 17 compiles | |
# my @foo = <a b c>; | |
# @foo.prepend: 1, 3 ... 11; | |
# say @foo; # OUTPUT: «[1 3 5 7 9 11 a b c]» | |
ok 972 - doc/Type/Array.pod6 chunk 18 compiles | |
# multi sub splice(@list, $start, $elems?, *@replacement --> Array) | |
# multi method splice(Array:D $start, $elems?, *@replacement --> Array) | |
ok 973 - doc/Type/Array.pod6 chunk 19 compiles | |
# my @foo = <a b c d e f g>; | |
# say @foo.splice(2, 3, <M N O P>); # OUTPUT: «[c d e]» | |
# say @foo; # OUTPUT: «[a b M N O P f g]» | |
ok 974 - doc/Type/Array.pod6 chunk 20 compiles | |
# method shape() { (*,) } | |
ok 975 - doc/Type/Array.pod6 chunk 21 compiles | |
# my @foo[2;3] = ( < 1 2 3 >, < 4 5 6 > ); # Array with fixed dimensions | |
# say @foo.shape; # OUTPUT: «(2 3)» | |
# my @bar = ( < 1 2 3 >, < 4 5 6 > ); # Normal array (of arrays) | |
# say @bar.shape; # OUTPUT: «(*)» | |
ok 976 - doc/Type/Array.pod6 chunk 22 compiles | |
# method default | |
ok 977 - doc/Type/Array.pod6 chunk 23 compiles | |
# my @a1 = 1, "two", 2.718; | |
# say @a1.default; # OUTPUT: «(Any)» | |
# say @a1[4]; # OUTPUT: «(Any)» | |
# my @a2 is default(17) = 1, "two", 3; | |
# say @a2.default; # OUTPUT: «17» | |
# say @a2[4]; # OUTPUT: «17» | |
# @a2[1] = Nil; # (resets element to its default) | |
# say @a2[1]; # OUTPUT: «17» | |
ok 978 - doc/Type/Array.pod6 chunk 24 compiles | |
# method of | |
ok 979 - doc/Type/Array.pod6 chunk 25 compiles | |
# my @a1 = 1, 'two', 3.14159; # (no type constraint specified) | |
# say @a1.of; # OUTPUT: «(Mu)» | |
# my Int @a2 = 1, 2, 3; # (values must be of type Int) | |
# say @a2.of; # OUTPUT: «(Int)» | |
# @a2.push: 'd'; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::TypeCheck::Assignment: Type check failed in assignment to @a2; expected Int but got Str ("d")» | |
ok 980 - doc/Type/Array.pod6 chunk 26 compiles | |
# role Associative { } | |
ok 981 - doc/Type/Associative.pod6 chunk 1 compiles | |
# class Attribute { } | |
ok 982 - doc/Type/Attribute.pod6 chunk 1 compiles | |
# class Useless { | |
# has @!things; | |
# } | |
# my $a = Useless.^attributes(:local)[0]; | |
# say $a.name; # OUTPUT: «@!things» | |
# say $a.package; # OUTPUT: «(Useless)» | |
# say $a.has_accessor; # OUTPUT: «False» | |
# # modifying an attribute from the outside | |
# # this is usually not possible, but since Attribute | |
# # is at the level of the meta class, all is fair game | |
# my $instance = Useless.new; | |
# $a.set_value($instance, [1, 2, 3]); | |
# say $a.get_value($instance); # OUTPUT: «[1 2 3]» | |
ok 983 - doc/Type/Attribute.pod6 chunk 2 compiles | |
# class C { | |
# has $.a is default(42) is rw = 666 | |
# } | |
# my $c = C.new; | |
# say $c; | |
# $c.a = Nil; | |
# say $c; | |
# # OUTPUT: «C.new(a => 666)C.new(a => 42)» | |
ok 984 - doc/Type/Attribute.pod6 chunk 3 compiles | |
# class C { | |
# has $.a is required | |
# } | |
# my $c = C.new; | |
# CATCH{ default { say .^name, ': ', .Str } } | |
# # OUTPUT: «X::Attribute::Required: The attribute '$!a' is required, but you did not provide a value for it.» | |
ok 985 - doc/Type/Attribute.pod6 chunk 4 compiles | |
# multi sub trait_mod:<is>(Attribute:D $r, :$DEPRECATED!) | |
ok 986 - doc/Type/Attribute.pod6 chunk 5 compiles | |
# method name(Attribute:D: --> Str:D) | |
ok 987 - doc/Type/Attribute.pod6 chunk 6 compiles | |
# class Foo { | |
# has @!bar; | |
# } | |
# my $a = Foo.^attributes(:local)[0]; | |
# say $a.name; # OUTPUT: «@!bar» | |
ok 988 - doc/Type/Attribute.pod6 chunk 7 compiles | |
# method package(Attribute:D: --> Mu:U) | |
ok 989 - doc/Type/Attribute.pod6 chunk 8 compiles | |
# class Boo { | |
# has @!baz; | |
# } | |
# my $a = Boo.^attributes(:local)[0]; | |
# say $a.package; # OUTPUT: «(Boo)» | |
ok 990 - doc/Type/Attribute.pod6 chunk 9 compiles | |
# method has_accessor(Attribute:D: --> Bool:D) | |
ok 991 - doc/Type/Attribute.pod6 chunk 10 compiles | |
# class Container { | |
# has $!private; | |
# has $.public; | |
# } | |
# my $private = Container.^attributes(:local)[0]; | |
# my $public = Container.^attributes(:local)[1]; | |
# say $private.has_accessor; # OUTPUT: «False» | |
# say $public.has_accessor; # OUTPUT: «True» | |
ok 992 - doc/Type/Attribute.pod6 chunk 11 compiles | |
# method readonly(Attribute:D: --> Bool:D) | |
ok 993 - doc/Type/Attribute.pod6 chunk 12 compiles | |
# class Library { | |
# has $.address; # Read-only value | |
# has @.new-books is rw; | |
# } | |
# my $addr = Library.^attributes(:local)[0]; | |
# my $new-books = Library.^attributes(:local)[1]; | |
# say $addr.readonly; # OUTPUT: «True» | |
# say $new-books.readonly; # OUTPUT: «False» | |
ok 994 - doc/Type/Attribute.pod6 chunk 13 compiles | |
# method type(Attribute:D: --> Mu) | |
ok 995 - doc/Type/Attribute.pod6 chunk 14 compiles | |
# class TypeHouse { | |
# has Int @.array; | |
# has $!scalar; | |
# has @.mystery; | |
# } | |
# my @types = TypeHouse.^attributes(:local)[0..2]; | |
# for 0..2 { say @types[$_].type } | |
# # OUTPUT: «(Positional[Int]) | |
# # (Mu) | |
# # (Positional)» | |
ok 996 - doc/Type/Attribute.pod6 chunk 15 compiles | |
# method get_value(Attribute:D: Mu $instance) | |
ok 997 - doc/Type/Attribute.pod6 chunk 16 compiles | |
# class Violated { | |
# has $!private-thing = 5; | |
# } | |
# my $private = Violated.^attributes(:local)[0]; | |
# say $private.get_value(Violated.new); # OUTPUT: «5» | |
ok 998 - doc/Type/Attribute.pod6 chunk 17 compiles | |
# method set_value(Attribute:D: Mu $instance, Mu \new_val) | |
ok 999 - doc/Type/Attribute.pod6 chunk 18 compiles | |
# class A { | |
# has $!a = 5; | |
# method speak() { say $!a; } | |
# } | |
# my $attr = A.^attributes(:local)[0]; | |
# my $a = A.new; | |
# $a.speak; # OUTPUT: «5» | |
# $attr.set_value($a, 42); | |
# $a.speak; # OUTPUT: «42» | |
ok 1000 - doc/Type/Attribute.pod6 chunk 19 compiles | |
# multi sub trait_mod:<is> (Attribute $attr, :$required!) | |
ok 1001 - doc/Type/Attribute.pod6 chunk 20 compiles | |
# class Foo { | |
# has $.bar is required; | |
# has $.baz; | |
# }; | |
# Foo.new(bar => 42); # works | |
# Foo.new(baz => 42); | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Attribute::Required: The attribute '$!bar' is required, but you did not provide a value for it.» | |
ok 1002 - doc/Type/Attribute.pod6 chunk 21 compiles | |
# multi sub trait_mod:<is> (Attribute:D $attr, :$rw!) | |
ok 1003 - doc/Type/Attribute.pod6 chunk 22 compiles | |
# class Boo { | |
# has $.bar is rw; | |
# has $.baz; | |
# }; | |
# my $boo = Boo.new; | |
# $boo.bar = 42; # works | |
# $boo.baz = 42; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Assignment::RO: Cannot modify an immutable Any» | |
ok 1004 - doc/Type/Attribute.pod6 chunk 23 compiles | |
# class Backtrace is List {} | |
ok 1005 - doc/Type/Backtrace.pod6 chunk 1 compiles | |
# multi method new(--> Backtrace:D) | |
ok 1006 - doc/Type/Backtrace.pod6 chunk 2 compiles | |
# my $backtrace = Backtrace.new; | |
ok 1007 - doc/Type/Backtrace.pod6 chunk 3 compiles | |
# multi method Str(Backtrace:D:) | |
ok 1008 - doc/Type/Backtrace.pod6 chunk 4 compiles | |
# my $backtrace = Backtrace.new; | |
# say $backtrace.Str; | |
ok 1009 - doc/Type/Backtrace.pod6 chunk 5 compiles | |
# multi method full(Backtrace:D:) | |
ok 1010 - doc/Type/Backtrace.pod6 chunk 6 compiles | |
# my $backtrace = Backtrace.new; | |
# say $backtrace.full; | |
ok 1011 - doc/Type/Backtrace.pod6 chunk 7 compiles | |
# class Backtrace::Frame { } | |
ok 1012 - doc/Type/Backtrace/Frame.pod6 chunk 1 compiles | |
# method file(Backtrace::Frame:D --> Str) | |
ok 1013 - doc/Type/Backtrace/Frame.pod6 chunk 2 compiles | |
# my $bt = Backtrace.new; | |
# my $btf = $bt[0]; | |
# say $btf.file; | |
ok 1014 - doc/Type/Backtrace/Frame.pod6 chunk 3 compiles | |
# method line(Backtrace::Frame:D --> Int) | |
ok 1015 - doc/Type/Backtrace/Frame.pod6 chunk 4 compiles | |
# my $bt = Backtrace.new; | |
# my $btf = $bt[0]; | |
# say $btf.line; | |
ok 1016 - doc/Type/Backtrace/Frame.pod6 chunk 5 compiles | |
# method code(Backtrace::Frame:D) | |
ok 1017 - doc/Type/Backtrace/Frame.pod6 chunk 6 compiles | |
# my $bt = Backtrace.new; | |
# my $btf = $bt[0]; | |
# say $btf.code; | |
ok 1018 - doc/Type/Backtrace/Frame.pod6 chunk 7 compiles | |
# method subname(Backtrace::Frame:D --> Str) | |
ok 1019 - doc/Type/Backtrace/Frame.pod6 chunk 8 compiles | |
# my $bt = Backtrace.new; | |
# my $btf = $bt[0]; | |
# say $btf.subname; | |
ok 1020 - doc/Type/Backtrace/Frame.pod6 chunk 9 compiles | |
# method is-hidden(Backtrace::Frame:D --> Bool:D) | |
ok 1021 - doc/Type/Backtrace/Frame.pod6 chunk 10 compiles | |
# my $bt = Backtrace.new; | |
# my $btf = $bt[0]; | |
# say $btf.is-hidden; | |
ok 1022 - doc/Type/Backtrace/Frame.pod6 chunk 11 compiles | |
# method is-routine(Backtrace::Frame:D --> Bool:D) | |
ok 1023 - doc/Type/Backtrace/Frame.pod6 chunk 12 compiles | |
# my $bt = Backtrace.new; | |
# my $btf = $bt[0]; | |
# say $btf.is-routine; | |
ok 1024 - doc/Type/Backtrace/Frame.pod6 chunk 13 compiles | |
# method is-setting(Backtrace::Frame:D --> Bool:D) | |
ok 1025 - doc/Type/Backtrace/Frame.pod6 chunk 14 compiles | |
# my $bt = Backtrace.new; | |
# my $btf = $bt[0]; | |
# say $btf.is-setting; # OUTPUT: «True» | |
ok 1026 - doc/Type/Backtrace/Frame.pod6 chunk 15 compiles | |
# class Bag does Baggy { } | |
ok 1027 - doc/Type/Bag.pod6 chunk 1 compiles | |
# my $breakfast = bag <spam eggs spam spam bacon spam>; | |
# say $breakfast.elems; # OUTPUT: «3» | |
# say $breakfast.keys.sort; # OUTPUT: «bacon eggs spam» | |
# say $breakfast.total; # OUTPUT: «6» | |
# say $breakfast.kxxv.sort; # OUTPUT: «bacon eggs spam spam spam spam» | |
ok 1028 - doc/Type/Bag.pod6 chunk 2 compiles | |
# my $breakfast = bag <spam eggs spam spam bacon spam>; | |
# say $breakfast<bacon>; # OUTPUT: «1» | |
# say $breakfast<spam>; # OUTPUT: «4» | |
# say $breakfast<sausage>; # OUTPUT: «0» | |
ok 1029 - doc/Type/Bag.pod6 chunk 3 compiles | |
# my $n = bag "a" => 0, "b" => 1, "c" => 2, "c" => 2; | |
# say $n.keys.perl; # OUTPUT: «(:c(2), :b(1), :a(0)).Seq» | |
# say $n.keys.map(&WHAT); # OUTPUT: «((Pair) (Pair) (Pair))» | |
# say $n.values.perl; # OUTPUT: «(2, 1, 1).Seq» | |
ok 1030 - doc/Type/Bag.pod6 chunk 4 compiles | |
# my $n = ("a" => 0, "b" => 1, "c" => 2, "c" => 2).Bag; | |
# say $n.keys.perl; # OUTPUT: «("b", "c").Seq» | |
# say $n.keys.map(&WHAT); # OUTPUT: «((Str) (Str))» | |
# say $n.values.perl; # OUTPUT: «(1, 4).Seq» | |
ok 1031 - doc/Type/Bag.pod6 chunk 5 compiles | |
# say (1..5) (+) 4; # OUTPUT: «bag(1, 2, 3, 4(2), 5)» | |
ok 1032 - doc/Type/Bag.pod6 chunk 6 compiles | |
# my ($a, $b) = bag(2, 2, 4), bag(2, 3, 3, 4); | |
# say $a (<) $b; # OUTPUT: «True» | |
# say $a (<+) $b; # OUTPUT: «False» | |
# say $a (^) $b; # OUTPUT: «set(3)» | |
# say $a (+) $b; # OUTPUT: «bag(2(3), 4(2), 3(2))» | |
# # Unicode versions: | |
# say $a ⊂ $b; # OUTPUT: «True» | |
# say $a ≼ $b; # OUTPUT: «False» | |
# say $a ⊖ $b; # OUTPUT: «set(3)» | |
# say $a ⊎ $b; # OUTPUT: «bag(2(3), 4(2), 3(2))» | |
ok 1033 - doc/Type/Bag.pod6 chunk 7 compiles | |
# sub bag(*@args --> Bag) | |
ok 1034 - doc/Type/Bag.pod6 chunk 8 compiles | |
# class BagHash does Baggy { } | |
ok 1035 - doc/Type/BagHash.pod6 chunk 1 compiles | |
# my $breakfast = <spam eggs spam spam bacon spam>.BagHash; | |
# say $breakfast.elems; # OUTPUT: «3» | |
# say $breakfast.keys.sort; # OUTPUT: «bacon eggs spam» | |
# say $breakfast.total; # OUTPUT: «6» | |
# say $breakfast.kxxv.sort; # OUTPUT: «bacon eggs spam spam spam spam» | |
ok 1036 - doc/Type/BagHash.pod6 chunk 2 compiles | |
# my $breakfast = <spam eggs spam spam bacon spam>.BagHash; | |
# say $breakfast<bacon>; # OUTPUT: «1» | |
# say $breakfast<spam>; # OUTPUT: «4» | |
# say $breakfast<sausage>; # OUTPUT: «0» | |
# $breakfast<sausage> = 2; | |
# $breakfast<bacon>--; | |
# say $breakfast.kxxv.sort; # OUTPUT: «eggs sausage sausage spam spam spam spam» | |
ok 1037 - doc/Type/BagHash.pod6 chunk 3 compiles | |
# my $n = BagHash.new: "a" => 0, "b" => 1, "c" => 2, "c" => 2; | |
# say $n.keys.perl; # OUTPUT: «(:c(2), :b(1), :a(0)).Seq» | |
# say $n.keys.map(&WHAT); # OUTPUT: «((Pair) (Pair) (Pair))» | |
# say $n.values.perl; # OUTPUT: «(2, 1, 1).Seq» | |
ok 1038 - doc/Type/BagHash.pod6 chunk 4 compiles | |
# my $n = ("a" => 0, "b" => 1, "c" => 2, "c" => 2).BagHash; | |
# say $n.keys.perl; # OUTPUT: «("b", "c").Seq» | |
# say $n.keys.map(&WHAT); # OUTPUT: «((Str) (Str))» | |
# say $n.values.perl; # OUTPUT: «(1, 4).Seq» | |
ok 1039 - doc/Type/BagHash.pod6 chunk 5 compiles | |
# my ($a, $b) = BagHash.new(2, 2, 4), BagHash.new(2, 3, 3, 4); | |
# say $a (<) $b; # OUTPUT: «True» | |
# say $a (<+) $b; # OUTPUT: «False» | |
# say $a (^) $b; # OUTPUT: «set(3)» | |
# say $a (+) $b; # OUTPUT: «bag(2(3), 4(2), 3(2))» | |
# # Unicode versions: | |
# say $a ⊂ $b; # OUTPUT: «True» | |
# say $a ≼ $b; # OUTPUT: «False» | |
# say $a ⊖ $b; # OUTPUT: «set(3)» | |
# say $a ⊎ $b; # OUTPUT: «bag(2(3), 4(2), 3(2))» | |
ok 1040 - doc/Type/BagHash.pod6 chunk 6 compiles | |
# role Baggy does QuantHash { } | |
ok 1041 - doc/Type/Baggy.pod6 chunk 1 compiles | |
# method new-from-pairs(*@pairs --> Baggy:D) | |
ok 1042 - doc/Type/Baggy.pod6 chunk 2 compiles | |
# say Mix.new-from-pairs: 'butter' => 0.22, 'sugar' => 0.1, 'sugar' => 0.02; | |
# # OUTPUT: «mix(butter(0.22), sugar(0.12))» | |
ok 1043 - doc/Type/Baggy.pod6 chunk 3 compiles | |
# multi method grab(Baggy:D: --> Any) | |
# multi method grab(Baggy:D: $count --> Array:D) | |
ok 1044 - doc/Type/Baggy.pod6 chunk 4 compiles | |
# my $cars = ('Ford' => 2, 'Rover' => 3).BagHash; | |
# say $cars.grab; # OUTPUT: «Ford» | |
# say $cars.grab(2); # OUTPUT: «[Rover Rover]» | |
# say $cars.grab(*); # OUTPUT: «[Rover Ford]» | |
# my $breakfast = ('eggs' => 2, 'bacon' => 3).Bag; | |
# say $breakfast.grab; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Immutable: Cannot call 'grab' on an immutable 'Bag'» | |
ok 1045 - doc/Type/Baggy.pod6 chunk 5 compiles | |
# multi method grabpairs(Baggy:D: --> Any) | |
# multi method grabpairs(Baggy:D: $count --> List:D) | |
ok 1046 - doc/Type/Baggy.pod6 chunk 6 compiles | |
# my $breakfast = (eggs => 2, bacon => 3).BagHash; | |
# say $breakfast.grabpairs; # OUTPUT: «bacon => 3» | |
# say $breakfast; # OUTPUT: «BagHash.new(eggs(2))» | |
# say $breakfast.grabpairs(1); # OUTPUT: «[eggs => 2]» | |
# say $breakfast.grabpairs(*); # OUTPUT: «[]» | |
# my $diet = ('eggs' => 2, 'bacon' => 3).Bag; | |
# say $diet.grabpairs; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Immutable: Cannot call 'grabpairs' on an immutable 'Bag'» | |
ok 1047 - doc/Type/Baggy.pod6 chunk 7 compiles | |
# multi method pick(Baggy:D: --> Any) | |
# multi method pick(Baggy:D: $count --> Seq:D) | |
ok 1048 - doc/Type/Baggy.pod6 chunk 8 compiles | |
# my $breakfast = bag <eggs bacon bacon bacon>; | |
# say $breakfast.pick; # OUTPUT: «eggs» | |
# say $breakfast.pick(2); # OUTPUT: «(eggs bacon)» | |
# say $breakfast.total; # OUTPUT: «4» | |
# say $breakfast.pick(*); # OUTPUT: «(bacon bacon bacon eggs)» | |
ok 1049 - doc/Type/Baggy.pod6 chunk 9 compiles | |
# multi method pickpairs(Baggy:D: --> Pair:D) | |
# multi method pickpairs(Baggy:D: $count --> List:D) | |
ok 1050 - doc/Type/Baggy.pod6 chunk 10 compiles | |
# my $breakfast = bag <eggs bacon bacon bacon>; | |
# say $breakfast.pickpairs; # OUTPUT: «eggs => 1» | |
# say $breakfast.pickpairs(1); # OUTPUT: «(bacon => 3)» | |
# say $breakfast.pickpairs(*); # OUTPUT: «(eggs => 1 bacon => 3)» | |
ok 1051 - doc/Type/Baggy.pod6 chunk 11 compiles | |
# multi method roll(Baggy:D: --> Any:D) | |
# multi method roll(Baggy:D: $count --> Seq:D) | |
ok 1052 - doc/Type/Baggy.pod6 chunk 12 compiles | |
# my $breakfast = bag <eggs bacon bacon bacon>; | |
# say $breakfast.roll; # OUTPUT: «bacon» | |
# say $breakfast.roll(3); # OUTPUT: «(bacon eggs bacon)» | |
# my $random_dishes := $breakfast.roll(*); | |
# say $random_dishes[^5]; # OUTPUT: «(bacon eggs bacon bacon bacon)» | |
ok 1053 - doc/Type/Baggy.pod6 chunk 13 compiles | |
# method pairs(Baggy:D: --> Seq:D) | |
ok 1054 - doc/Type/Baggy.pod6 chunk 14 compiles | |
# my $breakfast = bag <bacon eggs bacon>; | |
# my $seq = $breakfast.pairs; | |
# say $seq.sort; # OUTPUT: «(bacon => 2 eggs => 1)» | |
ok 1055 - doc/Type/Baggy.pod6 chunk 15 compiles | |
# method antipairs(Baggy:D: --> Seq:D) | |
ok 1056 - doc/Type/Baggy.pod6 chunk 16 compiles | |
# my $breakfast = bag <bacon eggs bacon>; | |
# my $seq = $breakfast.antipairs; | |
# say $seq.sort; # OUTPUT: «(1 => eggs 2 => bacon)» | |
ok 1057 - doc/Type/Baggy.pod6 chunk 17 compiles | |
# method invert(Baggy:D: --> Seq:D) | |
ok 1058 - doc/Type/Baggy.pod6 chunk 18 compiles | |
# my $breakfast = bag <bacon eggs bacon>; | |
# my $seq = $breakfast.invert; | |
# say $seq.sort; # OUTPUT: «(1 => eggs 2 => bacon)» | |
ok 1059 - doc/Type/Baggy.pod6 chunk 19 compiles | |
# multi method classify-list(&mapper, *@list --> Baggy:D) | |
# multi method classify-list(%mapper, *@list --> Baggy:D) | |
# multi method classify-list(@mapper, *@list --> Baggy:D) | |
ok 1060 - doc/Type/Baggy.pod6 chunk 20 compiles | |
# say BagHash.new.classify-list: { $_ %% 2 ?? 'even' !! 'odd' }, ^10; | |
# # OUTPUT: BagHash.new(even(5), odd(5)) | |
# my @mapper = <zero one two three four five>; | |
# say MixHash.new.classify-list: @mapper, 1, 2, 3, 4, 4, 6; | |
# # OUTPUT: MixHash.new((Any), two, three, four(2), one) | |
ok 1061 - doc/Type/Baggy.pod6 chunk 21 compiles | |
# multi method categorize-list(&mapper, *@list --> Baggy:D) | |
# multi method categorize-list(%mapper, *@list --> Baggy:D) | |
# multi method categorize-list(@mapper, *@list --> Baggy:D) | |
ok 1062 - doc/Type/Baggy.pod6 chunk 22 compiles | |
# say BagHash.new.categorize-list: { | |
# gather { | |
# take 'largish' if $_ > 5; | |
# take .is-prime ?? 'prime' !! 'non-prime'; | |
# take $_ %% 2 ?? 'even' !! 'odd'; | |
# } | |
# }, ^10; | |
# # OUTPUT: BagHash.new(largish(4), even(5), non-prime(6), prime(4), odd(5)) | |
# my %mapper = :sugar<sweet white>, :lemon<sour>, :cake('sweet', 'is a lie'); | |
# say MixHash.new.categorize-list: %mapper, <sugar lemon cake>; | |
# # OUTPUT: MixHash.new(is a lie, sour, white, sweet(2)) | |
ok 1063 - doc/Type/Baggy.pod6 chunk 23 compiles | |
# method keys(Baggy:D: --> List:D) | |
ok 1064 - doc/Type/Baggy.pod6 chunk 24 compiles | |
# my $breakfast = bag <eggs spam spam spam>; | |
# say $breakfast.keys.sort; # OUTPUT: «(eggs spam)» | |
# my $n = ("a" => 5, "b" => 2).BagHash; | |
# say $n.keys.sort; # OUTPUT: «(a b)» | |
ok 1065 - doc/Type/Baggy.pod6 chunk 25 compiles | |
# method values(Baggy:D: --> List:D) | |
ok 1066 - doc/Type/Baggy.pod6 chunk 26 compiles | |
# my $breakfast = bag <eggs spam spam spam>; | |
# say $breakfast.values.sort; # OUTPUT: «(1 3)» | |
# my $n = ("a" => 5, "b" => 2, "a" => 1).BagHash; | |
# say $n.values.sort; # OUTPUT: «(2 6)» | |
ok 1067 - doc/Type/Baggy.pod6 chunk 27 compiles | |
# method kv(Baggy:D: --> List:D) | |
ok 1068 - doc/Type/Baggy.pod6 chunk 28 compiles | |
# my $breakfast = bag <eggs spam spam spam>; | |
# say $breakfast.kv; # OUTPUT: «(spam 3 eggs 1)» | |
# my $n = ("a" => 5, "b" => 2, "a" => 1).BagHash; | |
# say $n.kv; # OUTPUT: «(a 6 b 2)» | |
ok 1069 - doc/Type/Baggy.pod6 chunk 29 compiles | |
# method kxxv(Baggy:D: --> List:D) | |
ok 1070 - doc/Type/Baggy.pod6 chunk 30 compiles | |
# my $breakfast = bag <spam eggs spam spam bacon>; | |
# say $breakfast.kxxv.sort; # OUTPUT: «(bacon eggs spam spam spam)» | |
# my $n = ("a" => 0, "b" => 1, "b" => 2).BagHash; | |
# say $n.kxxv; # OUTPUT: «(b b b)» | |
ok 1071 - doc/Type/Baggy.pod6 chunk 31 compiles | |
# method elems(Baggy:D: --> Int:D) | |
ok 1072 - doc/Type/Baggy.pod6 chunk 32 compiles | |
# my $breakfast = bag <eggs spam spam spam>; | |
# say $breakfast.elems; # OUTPUT: «2» | |
# my $n = ("b" => 9.4, "b" => 2).MixHash; | |
# say $n.elems; # OUTPUT: «1» | |
ok 1073 - doc/Type/Baggy.pod6 chunk 33 compiles | |
# method total(Baggy:D:) | |
ok 1074 - doc/Type/Baggy.pod6 chunk 34 compiles | |
# my $breakfast = bag <eggs spam spam bacon>; | |
# say $breakfast.total; # OUTPUT: «4» | |
# my $n = ("a" => 5, "b" => 1, "b" => 2).BagHash; | |
# say $n.total; # OUTPUT: «8» | |
ok 1075 - doc/Type/Baggy.pod6 chunk 35 compiles | |
# method default(Baggy:D: --> Int:D) | |
ok 1076 - doc/Type/Baggy.pod6 chunk 36 compiles | |
# my $breakfast = bag <eggs bacon>; | |
# say $breakfast.default; # OUTPUT: «0» | |
ok 1077 - doc/Type/Baggy.pod6 chunk 37 compiles | |
# method hash(Baggy:D: --> Hash:D) | |
ok 1078 - doc/Type/Baggy.pod6 chunk 38 compiles | |
# my $breakfast = bag <eggs bacon bacon>; | |
# my $h = $breakfast.hash; | |
# say $h.WHAT; # OUTPUT: «(Hash)» | |
# say $h; # OUTPUT: «{bacon => 2, eggs => 1}» | |
ok 1079 - doc/Type/Baggy.pod6 chunk 39 compiles | |
# method Bool(Baggy:D: --> Bool:D) | |
ok 1080 - doc/Type/Baggy.pod6 chunk 40 compiles | |
# my $breakfast = ('eggs' => 1).BagHash; | |
# say $breakfast.Bool; # OUTPUT: «True (since we have one element)» | |
# $breakfast<eggs> = 0; # weight == 0 will lead to element removal | |
# say $breakfast.Bool; # OUTPUT: «False» | |
ok 1081 - doc/Type/Baggy.pod6 chunk 41 compiles | |
# method Set(--> Set:D) | |
ok 1082 - doc/Type/Baggy.pod6 chunk 42 compiles | |
# my $breakfast = (eggs => 2, bacon => 3).BagHash; | |
# say $breakfast.Set; # OUTPUT: «set(bacon, eggs)» | |
ok 1083 - doc/Type/Baggy.pod6 chunk 43 compiles | |
# method SetHash(--> SetHash:D) | |
ok 1084 - doc/Type/Baggy.pod6 chunk 44 compiles | |
# my $breakfast = (eggs => 2, bacon => 3).BagHash; | |
# my $sh = $breakfast.SetHash; | |
# say $sh.WHAT; # OUTPUT: «(SetHash)» | |
# say $sh.elems; # OUTPUT: «2» | |
ok 1085 - doc/Type/Baggy.pod6 chunk 45 compiles | |
# method ACCEPTS($other --> Bool:D) | |
ok 1086 - doc/Type/Baggy.pod6 chunk 46 compiles | |
# my $breakfast = bag <eggs bacon>; | |
# say $breakfast ~~ Baggy; # OUTPUT: «True» | |
# say $breakfast.does(Baggy); # OUTPUT: «True» | |
# my $second-breakfast = (eggs => 1, bacon => 1).Mix; | |
# say $breakfast ~~ $second-breakfast; # OUTPUT: «True» | |
# my $third-breakfast = (eggs => 1, bacon => 2).Bag; | |
# say $second-breakfast ~~ $third-breakfast; # OUTPUT: «False» | |
ok 1087 - doc/Type/Baggy.pod6 chunk 47 compiles | |
# role Blob[::T = uint8] does Positional[T] does Stringy { } | |
ok 1088 - doc/Type/Blob.pod6 chunk 1 compiles | |
# method new(*@codes) | |
ok 1089 - doc/Type/Blob.pod6 chunk 2 compiles | |
# my $blob = Blob.new([1, 2, 3]); | |
ok 1090 - doc/Type/Blob.pod6 chunk 3 compiles | |
# multi method Bool(Blob:D:) | |
ok 1091 - doc/Type/Blob.pod6 chunk 4 compiles | |
# my $blob = Blob.new(); | |
# say $blob.Bool; # OUTPUT: «False» | |
# $blob = Blob.new([1, 2, 3]); | |
# say $blob.Bool; # OUTPUT: «True» | |
ok 1092 - doc/Type/Blob.pod6 chunk 5 compiles | |
# multi method elems(Blob:D: --> Int:D) | |
ok 1093 - doc/Type/Blob.pod6 chunk 6 compiles | |
# my $blob = Blob.new([1, 2, 3]); | |
# say $blob.elems; # OUTPUT: «3» | |
ok 1094 - doc/Type/Blob.pod6 chunk 7 compiles | |
# method bytes(Blob:D: --> Int:D) | |
ok 1095 - doc/Type/Blob.pod6 chunk 8 compiles | |
# say Blob.new([1, 2, 3]).bytes; # OUTPUT: «3» | |
# say blob16.new([1, 2, 3]).bytes; # OUTPUT: «6» | |
# say blob64.new([1, 2, 3]).bytes; # OUTPUT: «24» | |
ok 1096 - doc/Type/Blob.pod6 chunk 9 compiles | |
# multi method decode(Blob:D: Str:D $encoding = 'UTF-8' --> Str:D) | |
ok 1097 - doc/Type/Blob.pod6 chunk 10 compiles | |
# my Blob $blob = "string".encode('utf-8'); | |
# say $blob.decode('utf-8'); # OUTPUT: «string» | |
ok 1098 - doc/Type/Blob.pod6 chunk 11 compiles | |
# multi method subbuf(Int $from, Int $len = self.elems --> Blob:D) | |
# multi method subbuf(Range $range --> Blob:D) | |
ok 1099 - doc/Type/Blob.pod6 chunk 12 compiles | |
# say Blob.new(1..10).subbuf(2, 4); # OUTPUT: «Blob:0x<03 04 05 06>» | |
# say Blob.new(1..10).subbuf(*-2); # OUTPUT: «Blob:0x<09 0a>» | |
# say Blob.new(1..10).subbuf(*-5,2); # OUTPUT: «Blob:0x<06 07>» | |
ok 1100 - doc/Type/Blob.pod6 chunk 13 compiles | |
# say Blob.new(1..10).subbuf(2..5); # OUTPUT: «Blob:0x<03 04 05 06>» | |
ok 1101 - doc/Type/Blob.pod6 chunk 14 compiles | |
# use experimental :pack; | |
ok 1102 - doc/Type/Blob.pod6 chunk 15 compiles | |
# method unpack(Blob:D: $template --> List:D) | |
ok 1103 - doc/Type/Blob.pod6 chunk 16 compiles | |
# use experimental :pack; | |
# say Blob.new(1..10).unpack("C*"); | |
# # OUTPUT: «(1 2 3 4 5 6 7 8 9 10)» | |
ok 1104 - doc/Type/Blob.pod6 chunk 17 compiles | |
# class Block is Code { } | |
ok 1105 - doc/Type/Block.pod6 chunk 1 compiles | |
# my $block = { uc $_; }; | |
# say $block.WHAT; # OUTPUT: «(Block)» | |
# say $block('hello'); # OUTPUT: «HELLO» | |
ok 1106 - doc/Type/Block.pod6 chunk 2 compiles | |
# my $add = -> $a, $b = 2 { $a + $b }; | |
# say $add(40); # OUTPUT: «42» | |
ok 1107 - doc/Type/Block.pod6 chunk 3 compiles | |
# my $swap = <-> $a, $b { ($a, $b) = ($b, $a) }; | |
# my ($a, $b) = (2, 4); | |
# $swap($a, $b); | |
# say $a; # OUTPUT: «4» | |
ok 1108 - doc/Type/Block.pod6 chunk 4 compiles | |
# sub f() { | |
# say <a b c>.map: { return 42 }; | |
# # ^^^^^^ exits &f, not just the block | |
# } | |
ok 1109 - doc/Type/Block.pod6 chunk 5 compiles | |
# say {1}.(); # OUTPUT: «1» | |
ok 1110 - doc/Type/Block.pod6 chunk 6 compiles | |
# say 1; | |
# { | |
# say 2; # executed directly, not a Block object | |
# } | |
# say 3; | |
ok 1111 - doc/Type/Block.pod6 chunk 7 compiles | |
# enum Bool <False True> | |
ok 1112 - doc/Type/Bool.pod6 chunk 1 compiles | |
# method succ(--> Bool:D) | |
ok 1113 - doc/Type/Bool.pod6 chunk 2 compiles | |
# say True.succ; # OUTPUT: «True» | |
# say False.succ; # OUTPUT: «True» | |
ok 1114 - doc/Type/Bool.pod6 chunk 3 compiles | |
# method pred(--> Bool:D) | |
ok 1115 - doc/Type/Bool.pod6 chunk 4 compiles | |
# say True.pred; # OUTPUT: «False» | |
# say False.pred; # OUTPUT: «False» | |
ok 1116 - doc/Type/Bool.pod6 chunk 5 compiles | |
# method enums(--> Hash:D) | |
ok 1117 - doc/Type/Bool.pod6 chunk 6 compiles | |
# say Bool.enums; # OUTPUT: «{False => 0, True => 1}» | |
# say False.enums; # OUTPUT: «{False => 0, True => 1}» | |
ok 1118 - doc/Type/Bool.pod6 chunk 7 compiles | |
# multi method pick(Bool:U --> Bool:D) | |
# multi method pick(Bool:U $count --> Seq:D) | |
ok 1119 - doc/Type/Bool.pod6 chunk 8 compiles | |
# say Bool.pick; # OUTPUT: «True» | |
# say Bool.pick(1); # OUTPUT: «(False)» | |
# say Bool.pick(*); # OUTPUT: «(False True)» | |
ok 1120 - doc/Type/Bool.pod6 chunk 9 compiles | |
# multi method roll(Bool:U --> Bool:D) | |
# multi method roll(Bool:U $count --> Seq:D) | |
ok 1121 - doc/Type/Bool.pod6 chunk 10 compiles | |
# say Bool.roll; # OUTPUT: «True» | |
# say Bool.roll(3); # OUTPUT: «(True False False)» | |
# say Bool.roll(*); # OUTPUT: «(...)» | |
ok 1122 - doc/Type/Bool.pod6 chunk 11 compiles | |
# multi method Numeric(Bool:D --> Int:D) | |
ok 1123 - doc/Type/Bool.pod6 chunk 12 compiles | |
# say False.Numeric; # OUTPUT: «0» | |
# say True.Numeric; # OUTPUT: «1» | |
ok 1124 - doc/Type/Bool.pod6 chunk 13 compiles | |
# multi sub prefix:<?>(Mu --> Bool:D) | |
ok 1125 - doc/Type/Bool.pod6 chunk 14 compiles | |
# multi sub prefix:<so>(Mu --> Bool:D) | |
ok 1126 - doc/Type/Bool.pod6 chunk 15 compiles | |
# role Buf[::T] does Blob[T] { ... } | |
ok 1127 - doc/Type/Buf.pod6 chunk 1 compiles | |
# my $b = Buf.new(1, 2, 3); | |
# $b[1] = 42; | |
ok 1128 - doc/Type/Buf.pod6 chunk 2 compiles | |
# class CallFrame {} | |
ok 1129 - doc/Type/CallFrame.pod6 chunk 1 compiles | |
# my $frame = callframe; | |
# say "The above line of code ran at {$frame.file}:{$frame.line}."; | |
ok 1130 - doc/Type/CallFrame.pod6 chunk 2 compiles | |
# for 1..* -> $level { | |
# given callframe($level) -> $frame { | |
# when CallFrame { | |
# next unless $frame.code ~~ Routine; | |
# say $frame.code.package; | |
# last; | |
# } | |
# default { | |
# say "no calling routine or method found"; | |
# last; | |
# } | |
# } | |
# } | |
ok 1131 - doc/Type/CallFrame.pod6 chunk 3 compiles | |
# method code(CallFrame:D:) | |
ok 1132 - doc/Type/CallFrame.pod6 chunk 4 compiles | |
# method file(CallFrame:D:) | |
ok 1133 - doc/Type/CallFrame.pod6 chunk 5 compiles | |
# my $frame = callframe(0); | |
# say $frame.file eq $frame.annotations<file>; | |
ok 1134 - doc/Type/CallFrame.pod6 chunk 6 compiles | |
# method level(CallFrame:D:) | |
ok 1135 - doc/Type/CallFrame.pod6 chunk 7 compiles | |
# method line(CallFrame:D:) | |
ok 1136 - doc/Type/CallFrame.pod6 chunk 8 compiles | |
# say callframe(1).line; | |
# say callframe(1).annotations<line>; | |
ok 1137 - doc/Type/CallFrame.pod6 chunk 9 compiles | |
# method my(CallFrame:D:) | |
ok 1138 - doc/Type/CallFrame.pod6 chunk 10 compiles | |
# sub some-value { | |
# my $the-answer = 42; | |
# callframe(0); | |
# } | |
# my $frame = some-value(); | |
# say $frame.my<$the-answer>; # 42 | |
ok 1139 - doc/Type/CallFrame.pod6 chunk 11 compiles | |
# sub callframe(Int $level = 0) | |
ok 1140 - doc/Type/CallFrame.pod6 chunk 12 compiles | |
# role Callable { ... } | |
ok 1141 - doc/Type/Callable.pod6 chunk 1 compiles | |
# my &a = {;}; # Empty block needs a semicolon | |
# my &b = -> {}; | |
# my &c = sub () {}; | |
# sub foo() {}; | |
# my &d = &foo; | |
ok 1142 - doc/Type/Callable.pod6 chunk 2 compiles | |
# method CALL-ME(Callable:D $self: |arguments) | |
ok 1143 - doc/Type/Callable.pod6 chunk 3 compiles | |
# class A does Callable { | |
# submethod CALL-ME(|c){ 'called' } | |
# } | |
# my &a = A; | |
# say a(); # OUTPUT: «called» | |
ok 1144 - doc/Type/Callable.pod6 chunk 4 compiles | |
# method assuming(Callable:D $self: |primers) | |
ok 1145 - doc/Type/Callable.pod6 chunk 5 compiles | |
# my sub slow($n){ my $i = 0; $i++ while $i < $n; $i }; | |
# # takes only one parameter and as such wont forward $n | |
# sub bench(&c){ c, now - ENTER now }; | |
# say &slow.assuming(10000000).&bench; # OUTPUT: «(10000000 7.5508834)» | |
ok 1146 - doc/Type/Callable.pod6 chunk 6 compiles | |
# sub f($p){ say 'f'; $p / 2 } | |
# sub g($p){ say 'g'; $p * 2 } | |
# my &composed = &f ∘ &g; | |
# say composed 2; # OUTPUT: «gf2» | |
# # equivalent to: | |
# say 2.&g.&f; | |
# # or to: | |
# say f g 2; | |
ok 1147 - doc/Type/Callable.pod6 chunk 7 compiles | |
# sub f($a, $b, $c) { [~] $c, $b, $a } | |
# sub g($str){ $str.comb } | |
# my &composed = &f ∘ &g; | |
# say composed 'abc'; # OUTPUT: «cba» | |
# # equivalent to: | |
# say f |g 'abc'; | |
ok 1148 - doc/Type/Callable.pod6 chunk 8 compiles | |
# my class Cancellation {} | |
ok 1149 - doc/Type/Cancellation.pod6 chunk 1 compiles | |
# method cancel() | |
ok 1150 - doc/Type/Cancellation.pod6 chunk 2 compiles | |
# say unique 1, -2, 2, 3, as => { abs $_ }; # OUTPUT: «(1 -2 3)» | |
# # ... is the same thing as: | |
# say unique 1, -2, 2, 3, :as({ abs $_ }); # OUTPUT: «(1 -2 3)» | |
# # Be careful not to quote the name of a named parameter: | |
# say unique 1, -2, 2, 3, 'as' => { abs $_ }; | |
# # OUTPUT: «(1 -2 2 3 as => -> ;; $_? is raw { #`(Block|78857320) ... })» | |
ok 1151 - doc/Type/Capture.pod6 chunk 1 compiles | |
# my $c = \(42); # Capture with one positional part | |
# $c = \(1, 2, a => 'b'); # Capture with two positional and one named parts | |
ok 1152 - doc/Type/Capture.pod6 chunk 2 compiles | |
# my $c = \(4, 2, 3); | |
# reverse(|$c).say; # OUTPUT: «3 2 4» | |
# sort(5,|$c).say; # OUTPUT: «2 3 4 5» | |
ok 1153 - doc/Type/Capture.pod6 chunk 3 compiles | |
# f(1, 2, 3, a => 4, b => 5); | |
# sub f($a, |c) { | |
# # c is \(2, 3, a => 4, b => 5) | |
# } | |
ok 1154 - doc/Type/Capture.pod6 chunk 4 compiles | |
# my $b = 1; | |
# my $c = \(4, 2, $b, 3); | |
# sort(|$c).say; # OUTPUT: «1 2 3 4» | |
# $b = 6; | |
# sort(|$c).say; # OUTPUT: «2 3 4 6» | |
ok 1155 - doc/Type/Capture.pod6 chunk 5 compiles | |
# method list(Capture:D: --> Positional) | |
ok 1156 - doc/Type/Capture.pod6 chunk 6 compiles | |
# my Capture $c = \(2, 3, 5, apples => (red => 2)); | |
# say $c.list; # OUTPUT: «(2 3 5)» | |
ok 1157 - doc/Type/Capture.pod6 chunk 7 compiles | |
# method hash(Capture:D: --> Associative) | |
ok 1158 - doc/Type/Capture.pod6 chunk 8 compiles | |
# my Capture $c = \(2, 3, 5, apples => (red => 2)); | |
# say $c.hash; # OUTPUT: «Map.new((:apples(:red(2))))» | |
ok 1159 - doc/Type/Capture.pod6 chunk 9 compiles | |
# method elems(Capture:D: --> Int:D) | |
ok 1160 - doc/Type/Capture.pod6 chunk 10 compiles | |
# my Capture $c = \(2, 3, 5, apples => (red => 2)); | |
# say $c.elems; # OUTPUT: «3» | |
ok 1161 - doc/Type/Capture.pod6 chunk 11 compiles | |
# multi method keys(Capture:D: --> Seq:D) | |
ok 1162 - doc/Type/Capture.pod6 chunk 12 compiles | |
# my $capture = \(2, 3, 5, apples => (red => 2)); | |
# say $capture.keys; # OUTPUT: «(0 1 2 apples)» | |
ok 1163 - doc/Type/Capture.pod6 chunk 13 compiles | |
# multi method values(Capture:D: --> Seq:D) | |
ok 1164 - doc/Type/Capture.pod6 chunk 14 compiles | |
# my $capture = \(2, 3, 5, apples => (red => 2)); | |
# say $capture.values; # OUTPUT: «(2 3 5 red => 2)» | |
ok 1165 - doc/Type/Capture.pod6 chunk 15 compiles | |
# multi method kv(Capture:D: --> Seq:D) | |
ok 1166 - doc/Type/Capture.pod6 chunk 16 compiles | |
# my $capture = \(2, 3, apples => (red => 2)); | |
# say $capture.kv; # OUTPUT: «(0 2 1 3 apples red => 2)» | |
ok 1167 - doc/Type/Capture.pod6 chunk 17 compiles | |
# multi method pairs(Capture:D: --> Seq:D) | |
ok 1168 - doc/Type/Capture.pod6 chunk 18 compiles | |
# my Capture $c = \(2, 3, apples => (red => 2)); | |
# say $c.pairs; # OUTPUT: «(0 => 2 1 => 3 apples => red => 2)» | |
ok 1169 - doc/Type/Capture.pod6 chunk 19 compiles | |
# multi method antipairs(Capture:D: --> Seq:D) | |
ok 1170 - doc/Type/Capture.pod6 chunk 20 compiles | |
# my $capture = \(2, 3, apples => (red => 2)); | |
# say $capture.antipairs; # OUTPUT: «(2 => 0 3 => 1 (red => 2) => apples)» | |
ok 1171 - doc/Type/Capture.pod6 chunk 21 compiles | |
# method Bool(Capture:D: --> Bool:D) | |
ok 1172 - doc/Type/Capture.pod6 chunk 22 compiles | |
# say \(1,2,3, apples => 2).Bool; # OUTPUT: «True» | |
# say \().Bool; # OUTPUT: «False» | |
ok 1173 - doc/Type/Capture.pod6 chunk 23 compiles | |
# method Capture(Capture:D: --> Capture:D) | |
ok 1174 - doc/Type/Capture.pod6 chunk 24 compiles | |
# say \(1,2,3, apples => 2).Capture; # OUTPUT: «\(1, 2, 3, :apples(2))» | |
ok 1175 - doc/Type/Capture.pod6 chunk 25 compiles | |
# method Numeric(Capture:D: --> Int:D) | |
ok 1176 - doc/Type/Capture.pod6 chunk 26 compiles | |
# say \(1,2,3, apples => 2).Numeric; # OUTPUT: «3» | |
ok 1177 - doc/Type/Capture.pod6 chunk 27 compiles | |
# class Channel {} | |
ok 1178 - doc/Type/Channel.pod6 chunk 1 compiles | |
# my $c = Channel.new; | |
# await (^10).map: { | |
# start { | |
# my $r = rand; | |
# sleep $r; | |
# $c.send($r); | |
# } | |
# } | |
# $c.close; | |
# say $c.list; | |
ok 1179 - doc/Type/Channel.pod6 chunk 2 compiles | |
# method send(Channel:D: \item) | |
ok 1180 - doc/Type/Channel.pod6 chunk 3 compiles | |
# my $c = Channel.new; | |
# $c.send(1); | |
# $c.send([2, 3, 4, 5]); | |
# $c.close; | |
# say $c.list; # OUTPUT: «(1 [2 3 4 5])» | |
ok 1181 - doc/Type/Channel.pod6 chunk 4 compiles | |
# method receive(Channel:D:) | |
ok 1182 - doc/Type/Channel.pod6 chunk 5 compiles | |
# my $c = Channel.new; | |
# $c.send(1); | |
# say $c.receive; # OUTPUT: «1» | |
ok 1183 - doc/Type/Channel.pod6 chunk 6 compiles | |
# method poll(Channel:D:) | |
ok 1184 - doc/Type/Channel.pod6 chunk 7 compiles | |
# my $c = Channel.new; | |
# Promise.in(2).then: { $c.close; } | |
# ^10 .map({ $c.send($_); }); | |
# loop { | |
# if $c.poll -> $item { $item.say }; | |
# if $c.closed { last }; | |
# sleep 0.1; | |
# } | |
ok 1185 - doc/Type/Channel.pod6 chunk 8 compiles | |
# method close(Channel:D:) | |
ok 1186 - doc/Type/Channel.pod6 chunk 9 compiles | |
# my $c = Channel.new; | |
# $c.close; | |
# $c.send(1); | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Channel::SendOnClosed: Cannot send a message on a closed channel» | |
ok 1187 - doc/Type/Channel.pod6 chunk 10 compiles | |
# method list(Channel:D: --> List:D) | |
ok 1188 - doc/Type/Channel.pod6 chunk 11 compiles | |
# my $c = Channel.new; $c.send(1); $c.send(2); | |
# $c.close; | |
# say $c.list; # OUTPUT: «(1 2)» | |
ok 1189 - doc/Type/Channel.pod6 chunk 12 compiles | |
# method closed(Channel:D: --> Promise:D) | |
ok 1190 - doc/Type/Channel.pod6 chunk 13 compiles | |
# my $c = Channel.new; | |
# $c.closed.then({ say "It's closed!" }); | |
# $c.close; | |
# sleep 1; | |
ok 1191 - doc/Type/Channel.pod6 chunk 14 compiles | |
# method fail(Channel:D: $error) | |
ok 1192 - doc/Type/Channel.pod6 chunk 15 compiles | |
# my $c = Channel.new; | |
# $c.fail("Bad error happens!"); | |
# $c.receive; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::AdHoc: Bad error happens!» | |
ok 1193 - doc/Type/Channel.pod6 chunk 16 compiles | |
# method Supply(Channel:D:) | |
ok 1194 - doc/Type/Channel.pod6 chunk 17 compiles | |
# my $c = Channel.new; | |
# my Supply $s1 = $c.Supply; | |
# my Supply $s2 = $c.Supply; | |
# $s1.tap(-> $v { say "First $v" }); | |
# $s2.tap(-> $v { say "Second $v" }); | |
# ^10 .map({ $c.send($_) }); | |
# sleep 1; | |
ok 1195 - doc/Type/Channel.pod6 chunk 18 compiles | |
# multi sub await(Channel:D) | |
# multi sub await(*@) | |
ok 1196 - doc/Type/Channel.pod6 chunk 19 compiles | |
# my $c = Channel.new; | |
# Promise.in(1).then({$c.send(1)}); | |
# say await $c; | |
ok 1197 - doc/Type/Channel.pod6 chunk 20 compiles | |
# class Code is Any does Callable {} | |
ok 1198 - doc/Type/Code.pod6 chunk 1 compiles | |
# multi method ACCEPTS(Code:D: Mu $topic) | |
ok 1199 - doc/Type/Code.pod6 chunk 2 compiles | |
# method arity(Code:D: --> Int:D) | |
ok 1200 - doc/Type/Code.pod6 chunk 3 compiles | |
# sub argless() { } | |
# sub args($a, $b?) { } | |
# sub slurpy($a, $b, *@c) { } | |
# say &argless.arity; # OUTPUT: «0» | |
# say &args.arity; # OUTPUT: «1» | |
# say &slurpy.arity; # OUTPUT: «2» | |
ok 1201 - doc/Type/Code.pod6 chunk 4 compiles | |
# method count(Code:D: --> Real:D) | |
ok 1202 - doc/Type/Code.pod6 chunk 5 compiles | |
# sub argless() { } | |
# sub args($a, $b?) { } | |
# sub slurpy($a, $b, *@c) { } | |
# say &argless.count; # OUTPUT: «0» | |
# say &args.count; # OUTPUT: «2» | |
# say &slurpy.count; # OUTPUT: «Inf» | |
ok 1203 - doc/Type/Code.pod6 chunk 6 compiles | |
# method of(Code:D: --> Mu) | |
ok 1204 - doc/Type/Code.pod6 chunk 7 compiles | |
# say -> () --> Int {}.of; # OUTPUT: «(Int)» | |
ok 1205 - doc/Type/Code.pod6 chunk 8 compiles | |
# multi method signature(Code:D: --> Signature:D) | |
ok 1206 - doc/Type/Code.pod6 chunk 9 compiles | |
# sub a(Int $one, Str $two) {}; | |
# say &a.signature; # OUTPUT: «(Int $one, Str $two)» | |
ok 1207 - doc/Type/Code.pod6 chunk 10 compiles | |
# multi method Str(Code:D: --> Str:D) | |
ok 1208 - doc/Type/Code.pod6 chunk 11 compiles | |
# sub marine() { } | |
# say ~&marine; # OUTPUT: «marine» | |
# say &marine.Str; # OUTPUT: «marine» | |
ok 1209 - doc/Type/Code.pod6 chunk 12 compiles | |
# method file(Code:D: --> Str:D) | |
ok 1210 - doc/Type/Code.pod6 chunk 13 compiles | |
# say &infix:<+>.file; | |
ok 1211 - doc/Type/Code.pod6 chunk 14 compiles | |
# method line(Code:D: --> Int:D) | |
ok 1212 - doc/Type/Code.pod6 chunk 15 compiles | |
# say &infix:<+>.line; | |
ok 1213 - doc/Type/Code.pod6 chunk 16 compiles | |
# class Complex is Cool does Numeric {} | |
ok 1214 - doc/Type/Complex.pod6 chunk 1 compiles | |
# say 2i; # same as Complex.new(0, 2); | |
# say 1-2e3i; # same as Complex.new(1, -2e3); | |
ok 1215 - doc/Type/Complex.pod6 chunk 2 compiles | |
# multi method new(Real $re, Real $im --> Complex:D) | |
ok 1216 - doc/Type/Complex.pod6 chunk 3 compiles | |
# my $complex = Complex.new(1, 1); | |
ok 1217 - doc/Type/Complex.pod6 chunk 4 compiles | |
# method re(Complex:D: --> Real:D) | |
ok 1218 - doc/Type/Complex.pod6 chunk 5 compiles | |
# say (3+5i).re; # OUTPUT: «3» | |
ok 1219 - doc/Type/Complex.pod6 chunk 6 compiles | |
# method im(Complex:D: --> Real:D) | |
ok 1220 - doc/Type/Complex.pod6 chunk 7 compiles | |
# say (3+5i).im; # OUTPUT: «5» | |
ok 1221 - doc/Type/Complex.pod6 chunk 8 compiles | |
# method reals(Complex:D: --> Positional:D) | |
ok 1222 - doc/Type/Complex.pod6 chunk 9 compiles | |
# say (3+5i).reals; # OUTPUT: «(3 5)» | |
ok 1223 - doc/Type/Complex.pod6 chunk 10 compiles | |
# method isNaN(Complex:D: --> Bool:D) | |
ok 1224 - doc/Type/Complex.pod6 chunk 11 compiles | |
# say (NaN+5i).isNaN; # OUTPUT: «True» | |
# say (7+5i).isNaN; # OUTPUT: «False» | |
ok 1225 - doc/Type/Complex.pod6 chunk 12 compiles | |
# method polar(Complex:D: --> Positional:D) | |
ok 1226 - doc/Type/Complex.pod6 chunk 13 compiles | |
# say (10+7i).polar; # OUTPUT: «(12.2065556157337 0.610725964389209)» | |
ok 1227 - doc/Type/Complex.pod6 chunk 14 compiles | |
# method floor(Complex:D: --> Complex:D) | |
ok 1228 - doc/Type/Complex.pod6 chunk 15 compiles | |
# say (1.2-3.8i).floor; # OUTPUT: «1-4i» | |
ok 1229 - doc/Type/Complex.pod6 chunk 16 compiles | |
# method ceiling(Complex:D: --> Complex:D) | |
ok 1230 - doc/Type/Complex.pod6 chunk 17 compiles | |
# say (1.2-3.8i).ceiling; # OUTPUT: «2-3i» | |
ok 1231 - doc/Type/Complex.pod6 chunk 18 compiles | |
# multi method round(Complex:D: --> Complex:D) | |
# multi method round(Complex:D: Real() $scale --> Complex:D) | |
ok 1232 - doc/Type/Complex.pod6 chunk 19 compiles | |
# say (1.2-3.8i).round; # OUTPUT: «1-4i» | |
# say (1.256-3.875i).round(0.1); # OUTPUT: «1.3-3.9i» | |
ok 1233 - doc/Type/Complex.pod6 chunk 20 compiles | |
# method truncate(Complex:D: --> Complex:D) | |
ok 1234 - doc/Type/Complex.pod6 chunk 21 compiles | |
# say (1.2-3.8i).truncate; # OUTPUT: «1-3i» | |
ok 1235 - doc/Type/Complex.pod6 chunk 22 compiles | |
# method abs(Complex:D: --> Num:D) | |
# multi sub abs(Complex:D $z --> Num:D) | |
ok 1236 - doc/Type/Complex.pod6 chunk 23 compiles | |
# say (3+4i).abs; # OUTPUT: «5» | |
# # sqrt(3*3 + 4*4) == 5 | |
ok 1237 - doc/Type/Complex.pod6 chunk 24 compiles | |
# method conj(Complex:D: --> Complex:D) | |
ok 1238 - doc/Type/Complex.pod6 chunk 25 compiles | |
# say (1-4i).conj; # OUTPUT: «1+4i» | |
ok 1239 - doc/Type/Complex.pod6 chunk 26 compiles | |
# method gist(Complex:D: --> Str:D) | |
ok 1240 - doc/Type/Complex.pod6 chunk 27 compiles | |
# say (1-4i).gist; # OUTPUT: «1-4i» | |
ok 1241 - doc/Type/Complex.pod6 chunk 28 compiles | |
# method perl(Complex:D: --> Str:D) | |
ok 1242 - doc/Type/Complex.pod6 chunk 29 compiles | |
# say (1-3i).perl; # OUTPUT: «<1-3i>» | |
ok 1243 - doc/Type/Complex.pod6 chunk 30 compiles | |
# class ComplexStr is Complex is Str {} | |
ok 1244 - doc/Type/ComplexStr.pod6 chunk 1 compiles | |
# my $f = <42+0i>; say $f.WHAT; # OUTPUT: «(ComplexStr)» | |
ok 1245 - doc/Type/ComplexStr.pod6 chunk 2 compiles | |
# my $complex-str = < 42+0i >; | |
# my Complex $complex = $complex-str; # OK! | |
# my Str $str = $complex-str; # OK! | |
# say 42+0i ∈ <42+0i 55 1>; # False; ∈ operator cares about object identity | |
ok 1246 - doc/Type/ComplexStr.pod6 chunk 3 compiles | |
# method new(Complex $i, Str $s) | |
ok 1247 - doc/Type/ComplexStr.pod6 chunk 4 compiles | |
# my $f = ComplexStr.new(42+0i, "forty two (but complicated)"); | |
# say +$f; # OUTPUT: «42+0i» | |
# say ~$f; # OUTPUT: «"forty two (but complicated)"» | |
ok 1248 - doc/Type/ComplexStr.pod6 chunk 5 compiles | |
# method Numeric | |
ok 1249 - doc/Type/ComplexStr.pod6 chunk 6 compiles | |
# method Complex | |
ok 1250 - doc/Type/ComplexStr.pod6 chunk 7 compiles | |
# multi sub infix:<cmp>(ComplexStr:D $a, ComplexStr:D $b) | |
ok 1251 - doc/Type/ComplexStr.pod6 chunk 8 compiles | |
# my $f = ComplexStr.new(42+0i, "smaller"); | |
# my $g = ComplexStr.new(43+0i, "larger"); | |
# say $f cmp $g; # OUTPUT: «Less» | |
# say $f.Str cmp $g.Str; # OUTPUT: «More» | |
ok 1252 - doc/Type/ComplexStr.pod6 chunk 9 compiles | |
# class Cool is Any { } | |
ok 1253 - doc/Type/Cool.pod6 chunk 1 compiles | |
# 123.substr(1, 1); # '2', same as 123.Str.substr(1, 1) | |
ok 1254 - doc/Type/Cool.pod6 chunk 2 compiles | |
# sub abs(Numeric() $x) | |
# method abs() | |
ok 1255 - doc/Type/Cool.pod6 chunk 3 compiles | |
# say (-2).abs; # OUTPUT: «2» | |
# say abs "6+8i"; # OUTPUT: «10» | |
ok 1256 - doc/Type/Cool.pod6 chunk 4 compiles | |
# method conj() | |
ok 1257 - doc/Type/Cool.pod6 chunk 5 compiles | |
# say (1+2i).conj; # OUTPUT: «1-2i» | |
ok 1258 - doc/Type/Cool.pod6 chunk 6 compiles | |
# sub sqrt(Numeric(Cool) $x) | |
# method sqrt() | |
ok 1259 - doc/Type/Cool.pod6 chunk 7 compiles | |
# say 4.sqrt; # OUTPUT: «2» | |
# say sqrt(2); # OUTPUT: «1.4142135623731» | |
ok 1260 - doc/Type/Cool.pod6 chunk 8 compiles | |
# method sign() | |
ok 1261 - doc/Type/Cool.pod6 chunk 9 compiles | |
# say 6.sign; # OUTPUT: «1» | |
# say (-6).sign; # OUTPUT: «-1» | |
# say "0".sign; # OUTPUT: «0» | |
ok 1262 - doc/Type/Cool.pod6 chunk 10 compiles | |
# method rand() | |
ok 1263 - doc/Type/Cool.pod6 chunk 11 compiles | |
# say 1e5.rand; # OUTPUT: «33128.495184283» | |
ok 1264 - doc/Type/Cool.pod6 chunk 12 compiles | |
# sub sin(Numeric(Cool)) | |
# method sin() | |
ok 1265 - doc/Type/Cool.pod6 chunk 13 compiles | |
# say sin(0); # OUTPUT: «0» | |
# say sin(pi/4); # OUTPUT: «0.707106781186547» | |
# say sin(pi/2); # OUTPUT: «1» | |
ok 1266 - doc/Type/Cool.pod6 chunk 14 compiles | |
# sub asin(Numeric(Cool)) | |
# method asin() | |
ok 1267 - doc/Type/Cool.pod6 chunk 15 compiles | |
# say 0.1.asin; # OUTPUT: «0.10016742116156» | |
# say asin(0.1); # OUTPUT: «0.10016742116156» | |
ok 1268 - doc/Type/Cool.pod6 chunk 16 compiles | |
# sub cos(Numeric(Cool)) | |
# method cos() | |
ok 1269 - doc/Type/Cool.pod6 chunk 17 compiles | |
# say 0.cos; # OUTPUT: «1» | |
# say pi.cos; # OUTPUT: «-1» | |
# say cos(pi/2); # OUTPUT: «6.12323399573677e-17» | |
ok 1270 - doc/Type/Cool.pod6 chunk 18 compiles | |
# sub acos(Numeric(Cool)) | |
# method acos() | |
ok 1271 - doc/Type/Cool.pod6 chunk 19 compiles | |
# say 1.acos; # OUTPUT: «0» | |
# say acos(-1); # OUTPUT: «3.14159265358979» | |
ok 1272 - doc/Type/Cool.pod6 chunk 20 compiles | |
# sub tan(Numeric(Cool)) | |
# method tan() | |
ok 1273 - doc/Type/Cool.pod6 chunk 21 compiles | |
# say tan(3); # OUTPUT: «-0.142546543074278» | |
# say 3.tan; # OUTPUT: «-0.142546543074278» | |
ok 1274 - doc/Type/Cool.pod6 chunk 22 compiles | |
# sub atan(Numeric(Cool)) | |
# method atan() | |
ok 1275 - doc/Type/Cool.pod6 chunk 23 compiles | |
# say atan(3); # OUTPUT: «1.24904577239825» | |
# say 3.atan; # OUTPUT: «1.24904577239825» | |
ok 1276 - doc/Type/Cool.pod6 chunk 24 compiles | |
# sub atan2(Numeric() $x, Numeric() $y = 1e0) | |
# method atan2($y = 1e0) | |
ok 1277 - doc/Type/Cool.pod6 chunk 25 compiles | |
# say atan2(3); # OUTPUT: «1.24904577239825» | |
# say 3.atan2; # OUTPUT: «1.24904577239825» | |
ok 1278 - doc/Type/Cool.pod6 chunk 26 compiles | |
# sub sec(Numeric(Cool)) | |
# method sec() | |
ok 1279 - doc/Type/Cool.pod6 chunk 27 compiles | |
# say 45.sec; # OUTPUT: «1.90359440740442» | |
# say sec(45); # OUTPUT: «1.90359440740442» | |
ok 1280 - doc/Type/Cool.pod6 chunk 28 compiles | |
# sub asec(Numeric(Cool)) | |
# method asec() | |
ok 1281 - doc/Type/Cool.pod6 chunk 29 compiles | |
# say 1.asec; # OUTPUT: «0» | |
# say sqrt(2).asec; # OUTPUT: «0.785398163397448» | |
ok 1282 - doc/Type/Cool.pod6 chunk 30 compiles | |
# sub cosec(Numeric(Cool)) | |
# method cosec() | |
ok 1283 - doc/Type/Cool.pod6 chunk 31 compiles | |
# say 0.45.cosec; # OUTPUT: «2.29903273150897» | |
# say cosec(0.45); # OUTPUT: «2.29903273150897» | |
ok 1284 - doc/Type/Cool.pod6 chunk 32 compiles | |
# sub acosec(Numeric(Cool)) | |
# method acosec() | |
ok 1285 - doc/Type/Cool.pod6 chunk 33 compiles | |
# say 45.acosec; # OUTPUT: «0.0222240516182672» | |
# say acosec(45) # OUTPUT: «0.0222240516182672» | |
ok 1286 - doc/Type/Cool.pod6 chunk 34 compiles | |
# sub cotan(Numeric(Cool)) | |
# method cotan() | |
ok 1287 - doc/Type/Cool.pod6 chunk 35 compiles | |
# say 45.cotan; # OUTPUT: «0.617369623783555» | |
# say cotan(45); # OUTPUT: «0.617369623783555» | |
ok 1288 - doc/Type/Cool.pod6 chunk 36 compiles | |
# sub acotan(Numeric(Cool)) | |
# method acotan() | |
ok 1289 - doc/Type/Cool.pod6 chunk 37 compiles | |
# say 45.acotan; # OUTPUT: «0.0222185653267191» | |
# say acotan(45) # OUTPUT: «0.0222185653267191» | |
ok 1290 - doc/Type/Cool.pod6 chunk 38 compiles | |
# sub sinh(Numeric(Cool)) | |
# method sinh() | |
ok 1291 - doc/Type/Cool.pod6 chunk 39 compiles | |
# say 1.sinh; # OUTPUT: «1.1752011936438» | |
# say sinh(1); # OUTPUT: «1.1752011936438» | |
ok 1292 - doc/Type/Cool.pod6 chunk 40 compiles | |
# sub asinh(Numeric(Cool)) | |
# method asinh() | |
ok 1293 - doc/Type/Cool.pod6 chunk 41 compiles | |
# say 1.asinh; # OUTPUT: «0.881373587019543» | |
# say asinh(1); # OUTPUT: «0.881373587019543» | |
ok 1294 - doc/Type/Cool.pod6 chunk 42 compiles | |
# sub cosh(Numeric(Cool)) | |
# method cosh() | |
ok 1295 - doc/Type/Cool.pod6 chunk 43 compiles | |
# say cosh(0.5); # OUTPUT: «1.12762596520638» | |
ok 1296 - doc/Type/Cool.pod6 chunk 44 compiles | |
# sub acosh(Numeric(Cool)) | |
# method acosh() | |
ok 1297 - doc/Type/Cool.pod6 chunk 45 compiles | |
# say acosh(45); # OUTPUT: «4.4996861906715» | |
ok 1298 - doc/Type/Cool.pod6 chunk 46 compiles | |
# sub tanh(Numeric(Cool)) | |
# method tanh() | |
ok 1299 - doc/Type/Cool.pod6 chunk 47 compiles | |
# say tanh(0.5); # OUTPUT: «0.46211715726001» | |
# say tanh(atanh(0.5)); # OUTPUT: «0.5» | |
ok 1300 - doc/Type/Cool.pod6 chunk 48 compiles | |
# sub atanh(Numeric(Cool)) | |
# method atanh() | |
ok 1301 - doc/Type/Cool.pod6 chunk 49 compiles | |
# say atanh(0.5); # OUTPUT: «0.549306144334055» | |
ok 1302 - doc/Type/Cool.pod6 chunk 50 compiles | |
# sub sech(Numeric(Cool)) | |
# method sech() | |
ok 1303 - doc/Type/Cool.pod6 chunk 51 compiles | |
# say 0.sech; # OUTPUT: «1» | |
ok 1304 - doc/Type/Cool.pod6 chunk 52 compiles | |
# sub asech(Numeric(Cool)) | |
# method asech() | |
ok 1305 - doc/Type/Cool.pod6 chunk 53 compiles | |
# say 0.8.asech; # OUTPUT: «0.693147180559945» | |
ok 1306 - doc/Type/Cool.pod6 chunk 54 compiles | |
# sub cosech(Numeric(Cool)) | |
# method cosech() | |
ok 1307 - doc/Type/Cool.pod6 chunk 55 compiles | |
# say cosech(pi/2); # OUTPUT: «0.434537208094696» | |
ok 1308 - doc/Type/Cool.pod6 chunk 56 compiles | |
# sub acosech(Numeric(Cool)) | |
# method acosech() | |
ok 1309 - doc/Type/Cool.pod6 chunk 57 compiles | |
# say acosech(4.5); # OUTPUT: «0.220432720979802» | |
ok 1310 - doc/Type/Cool.pod6 chunk 58 compiles | |
# sub cotanh(Numeric(Cool)) | |
# method cotanh() | |
ok 1311 - doc/Type/Cool.pod6 chunk 59 compiles | |
# say cotanh(pi); # OUTPUT: «1.00374187319732» | |
ok 1312 - doc/Type/Cool.pod6 chunk 60 compiles | |
# sub acotanh(Numeric(Cool)) | |
# method acotanh() | |
ok 1313 - doc/Type/Cool.pod6 chunk 61 compiles | |
# say acotanh(2.5); # OUTPUT: «0.423648930193602» | |
ok 1314 - doc/Type/Cool.pod6 chunk 62 compiles | |
# sub cis(Numeric(Cool)) | |
# method cis() | |
ok 1315 - doc/Type/Cool.pod6 chunk 63 compiles | |
# say cis(pi/4); # OUTPUT: «0.707106781186548+0.707106781186547i» | |
ok 1316 - doc/Type/Cool.pod6 chunk 64 compiles | |
# multi sub log(Numeric(Cool) $number, Numeric(Cool) $base?) | |
# multi method log(Cool:D: Cool:D $base?) | |
ok 1317 - doc/Type/Cool.pod6 chunk 65 compiles | |
# say (e*e).log; # OUTPUT: «2» | |
ok 1318 - doc/Type/Cool.pod6 chunk 66 compiles | |
# multi sub log10(Cool(Numeric)) | |
# multi method log10() | |
ok 1319 - doc/Type/Cool.pod6 chunk 67 compiles | |
# say log10(1001); # OUTPUT: «3.00043407747932» | |
ok 1320 - doc/Type/Cool.pod6 chunk 68 compiles | |
# multi sub exp(Cool:D $pow, Cool:D $base?) | |
# multi method exp(Cool:D: Cool:D $base?) | |
ok 1321 - doc/Type/Cool.pod6 chunk 69 compiles | |
# say 0.exp; # OUTPUT: «1» | |
# say 1.exp; # OUTPUT: «2.71828182845905» | |
# say 10.exp; # OUTPUT: «22026.4657948067» | |
ok 1322 - doc/Type/Cool.pod6 chunk 70 compiles | |
# method unpolar(Numeric(Cool)) | |
ok 1323 - doc/Type/Cool.pod6 chunk 71 compiles | |
# say sqrt(2).unpolar(pi/4); # OUTPUT: «1+1i» | |
ok 1324 - doc/Type/Cool.pod6 chunk 72 compiles | |
# multi sub round(Numeric(Cool)) | |
# multi method round(Cool:D: $unit = 1) | |
ok 1325 - doc/Type/Cool.pod6 chunk 73 compiles | |
# say 1.7.round; # OUTPUT: «2» | |
# say 1.07.round(0.1); # OUTPUT: «1.1» | |
# say 21.round(10); # OUTPUT: «20» | |
ok 1326 - doc/Type/Cool.pod6 chunk 74 compiles | |
# say (−.5 ).round; # OUTPUT: «0» | |
# say ( .5 ).round; # OUTPUT: «1» | |
# say (−.55).round(.1); # OUTPUT: «-0.5» | |
# say ( .55).round(.1); # OUTPUT: «0.6» | |
ok 1327 - doc/Type/Cool.pod6 chunk 75 compiles | |
# multi sub floor(Numeric(Cool)) | |
# multi method floor | |
ok 1328 - doc/Type/Cool.pod6 chunk 76 compiles | |
# say "1.99".floor; # OUTPUT: «1» | |
# say "-1.9".floor; # OUTPUT: «-2» | |
# say 0.floor; # OUTPUT: «0» | |
ok 1329 - doc/Type/Cool.pod6 chunk 77 compiles | |
# multi sub ceiling(Numeric(Cool)) | |
# multi method ceiling | |
ok 1330 - doc/Type/Cool.pod6 chunk 78 compiles | |
# say "1".ceiling; # OUTPUT: «1» | |
# say "-0.9".ceiling; # OUTPUT: «0» | |
# say "42.1".ceiling; # OUTPUT: «43» | |
ok 1331 - doc/Type/Cool.pod6 chunk 79 compiles | |
# multi sub truncate(Numeric(Cool)) | |
# multi method truncate() | |
ok 1332 - doc/Type/Cool.pod6 chunk 80 compiles | |
# say 1.2.truncate; # OUTPUT: «1» | |
# say truncate -1.2; # OUTPUT: «-1» | |
ok 1333 - doc/Type/Cool.pod6 chunk 81 compiles | |
# sub ord(Str(Cool)) | |
# method ord() | |
ok 1334 - doc/Type/Cool.pod6 chunk 82 compiles | |
# say 'a'.ord; # OUTPUT: «97» | |
ok 1335 - doc/Type/Cool.pod6 chunk 83 compiles | |
# sub chr(Int(Cool)) | |
# method chr() | |
ok 1336 - doc/Type/Cool.pod6 chunk 84 compiles | |
# say '65'.chr; # OUTPUT: «A» | |
ok 1337 - doc/Type/Cool.pod6 chunk 85 compiles | |
# sub chars(Str(Cool)) | |
# method chars() | |
ok 1338 - doc/Type/Cool.pod6 chunk 86 compiles | |
# say 'møp'.chars; # OUTPUT: «3» | |
ok 1339 - doc/Type/Cool.pod6 chunk 87 compiles | |
# sub codes(Str(Cool)) | |
# method codes() | |
ok 1340 - doc/Type/Cool.pod6 chunk 88 compiles | |
# say 'møp'.codes; # OUTPUT: «3» | |
ok 1341 - doc/Type/Cool.pod6 chunk 89 compiles | |
# sub flip(Str(Cool)) | |
# method flip() | |
ok 1342 - doc/Type/Cool.pod6 chunk 90 compiles | |
# say 421.flip; # OUTPUT: «124» | |
ok 1343 - doc/Type/Cool.pod6 chunk 91 compiles | |
# sub trim(Str(Cool)) | |
# method trim() | |
ok 1344 - doc/Type/Cool.pod6 chunk 92 compiles | |
# my $stripped = ' abc '.trim; | |
# say "<$stripped>"; # OUTPUT: «<abc>» | |
ok 1345 - doc/Type/Cool.pod6 chunk 93 compiles | |
# sub trim-leading(Str(Cool)) | |
# method trim-leading() | |
ok 1346 - doc/Type/Cool.pod6 chunk 94 compiles | |
# my $stripped = ' abc '.trim-leading; | |
# say "<$stripped>"; # OUTPUT: «<abc >» | |
ok 1347 - doc/Type/Cool.pod6 chunk 95 compiles | |
# sub trim-trailing(Str(Cool)) | |
# method trim-trailing() | |
ok 1348 - doc/Type/Cool.pod6 chunk 96 compiles | |
# my $stripped = ' abc '.trim-trailing; | |
# say "<$stripped>"; # OUTPUT: «< abc>» | |
ok 1349 - doc/Type/Cool.pod6 chunk 97 compiles | |
# sub lc(Str(Cool)) | |
# method lc() | |
ok 1350 - doc/Type/Cool.pod6 chunk 98 compiles | |
# say "ABC".lc; # OUTPUT: «abc» | |
ok 1351 - doc/Type/Cool.pod6 chunk 99 compiles | |
# sub uc(Str(Cool)) | |
# method uc() | |
ok 1352 - doc/Type/Cool.pod6 chunk 100 compiles | |
# say "Abc".uc; # OUTPUT: «ABC» | |
ok 1353 - doc/Type/Cool.pod6 chunk 101 compiles | |
# sub fc(Str(Cool)) | |
# method fc() | |
ok 1354 - doc/Type/Cool.pod6 chunk 102 compiles | |
# say "groß".fc; # OUTPUT: «gross» | |
ok 1355 - doc/Type/Cool.pod6 chunk 103 compiles | |
# sub tc(Str(Cool)) | |
# method tc() | |
ok 1356 - doc/Type/Cool.pod6 chunk 104 compiles | |
# say "abC".tc; # OUTPUT: «AbC» | |
ok 1357 - doc/Type/Cool.pod6 chunk 105 compiles | |
# sub tclc(Str(Cool)) | |
# method tclc() | |
ok 1358 - doc/Type/Cool.pod6 chunk 106 compiles | |
# say 'abC'.tclc; # OUTPUT: «Abc» | |
ok 1359 - doc/Type/Cool.pod6 chunk 107 compiles | |
# sub wordcase(Str(Cool) $input, :&filter = &tclc, Mu :$where = True) | |
# method wordcase(:&filter = &tclc, Mu :$where = True) | |
ok 1360 - doc/Type/Cool.pod6 chunk 108 compiles | |
# say "perl 6 programming".wordcase; # OUTPUT: «Perl 6 Programming» | |
ok 1361 - doc/Type/Cool.pod6 chunk 109 compiles | |
# say "have fun working on perl".wordcase(:where({ .chars > 3 })); | |
# # Have fun Working on Perl | |
ok 1362 - doc/Type/Cool.pod6 chunk 110 compiles | |
# say "have fun working on perl".wordcase(:filter(&uc), :where({ .chars > 3 })); | |
# # HAVE fun WORKING on PERL | |
ok 1363 - doc/Type/Cool.pod6 chunk 111 compiles | |
# sub samecase(Cool $string, Cool $pattern) | |
# method samecase(Cool:D: Cool $pattern) | |
ok 1364 - doc/Type/Cool.pod6 chunk 112 compiles | |
# say "perL 6".samecase("A__a__"); # OUTPUT: «Perl 6» | |
# say "pERL 6".samecase("Ab"); # OUTPUT: «Perl 6» | |
ok 1365 - doc/Type/Cool.pod6 chunk 113 compiles | |
# multi sub uniprop(Str(Cool), |c) | |
# multi sub uniprop(Int:D $code, Stringy:D $propname) | |
# multi sub uniprop(Str, $code, Stringy:D $propname) | |
# multi method uniprop(|c) | |
ok 1366 - doc/Type/Cool.pod6 chunk 114 compiles | |
# say 'a'.uniprop; # OUTPUT: «Ll» | |
# say '1'.uniprop; # OUTPUT: «Nd» | |
# say 'a'.uniprop('Alphabetic'); # OUTPUT: «True» | |
# say '1'.uniprop('Alphabetic'); # OUTPUT: «False» | |
ok 1367 - doc/Type/Cool.pod6 chunk 115 compiles | |
# sub uniprops(Str:D $str, Stringy:D $propname = "General_Category") | |
ok 1368 - doc/Type/Cool.pod6 chunk 116 compiles | |
# sub uniname(Str(Cool) --> Str) | |
# method uniname(--> Str) | |
ok 1369 - doc/Type/Cool.pod6 chunk 117 compiles | |
# # Camelia in Unicode | |
# say ‘»ö«’.uniname; | |
# # OUTPUT: «"RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK"» | |
# say "Ḍ̇".uniname; # Note, doesn't show "COMBINING DOT ABOVE" | |
# # OUTPUT: «"LATIN CAPITAL LETTER D WITH DOT BELOW"» | |
# # Find the char with the longest Unicode name. | |
# say (0..0x1FFFF).sort(*.uniname.chars)[*-1].chr.uniname; | |
# # OUTPUT: ««ARABIC LIGATURE UIGHUR KIRGHIZ YEH WITH HAMZA ABOVE WITH ALEF MAKSURA INITIAL FORM»» | |
ok 1370 - doc/Type/Cool.pod6 chunk 118 compiles | |
# sub uninames(Str:D) | |
# method uninames() | |
ok 1371 - doc/Type/Cool.pod6 chunk 119 compiles | |
# say ‘»ö«’.uninames.perl; | |
# # OUTPUT: «("RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK", "LATIN SMALL LETTER O WITH DIAERESIS", "LEFT-POINTING DOUBLE ANGLE QUOTATION MARK").Seq» | |
ok 1372 - doc/Type/Cool.pod6 chunk 120 compiles | |
# say "Ḍ̇'oh".comb>>.uninames.perl; | |
# # OUTPUT: «(("LATIN CAPITAL LETTER D WITH DOT BELOW", "COMBINING DOT ABOVE").Seq, ("APOSTROPHE",).Seq, ("LATIN SMALL LETTER O",).Seq, ("LATIN SMALL LETTER H",).Seq)» | |
ok 1373 - doc/Type/Cool.pod6 chunk 121 compiles | |
# multi sub unimatch(Str:D $str, |c) | |
# multi unimatch(Int:D $code, Stringy:D $pvalname, Stringy:D $propname = $pvalname) | |
ok 1374 - doc/Type/Cool.pod6 chunk 122 compiles | |
# say unimatch 'A', 'Latin'; # OUTPUT: «True» | |
# say unimatch 'A', 'Latin', 'Script'; # OUTPUT: «True» | |
# say unimatch 'A', 'Ll'; # OUTPUT: «True» | |
ok 1375 - doc/Type/Cool.pod6 chunk 123 compiles | |
# sub chop(Str(Cool)) | |
# method chop() | |
ok 1376 - doc/Type/Cool.pod6 chunk 124 compiles | |
# say 'perl'.chop; # OUTPUT: «per» | |
ok 1377 - doc/Type/Cool.pod6 chunk 125 compiles | |
# sub chomp(Str(Cool)) | |
# method chomp() | |
ok 1378 - doc/Type/Cool.pod6 chunk 126 compiles | |
# say 'ab'.chomp.chars; # OUTPUT: «2» | |
# say "a\n".chomp.chars; # OUTPUT: «1» | |
ok 1379 - doc/Type/Cool.pod6 chunk 127 compiles | |
# sub substr(Str(Cool) $str, $from, $chars?) | |
# method substr($from, $chars?) | |
ok 1380 - doc/Type/Cool.pod6 chunk 128 compiles | |
# say 'zenith'.substr(2); # OUTPUT: «nith» | |
# say 'zenith'.substr(0, 3); # OUTPUT: «zen» | |
# # works on non-strings too: | |
# say 20151224.substr(6); # OUTPUT: «24» | |
# # sub form: | |
# say substr "zenith", 0, 3; # OUTPUT: «zen» | |
ok 1381 - doc/Type/Cool.pod6 chunk 129 compiles | |
# say 20151224.substr(*-2); # OUTPUT: «24» | |
ok 1382 - doc/Type/Cool.pod6 chunk 130 compiles | |
# sub ords(Str(Cool) $str) | |
# method ords() | |
ok 1383 - doc/Type/Cool.pod6 chunk 131 compiles | |
# say "Camelia".ords; # OUTPUT: «67 97 109 101 108 105 97» | |
# say ords 10; # OUTPUT: «49 48» | |
ok 1384 - doc/Type/Cool.pod6 chunk 132 compiles | |
# sub chrs(*@codepoints --> Str:D) | |
# method chrs() | |
ok 1385 - doc/Type/Cool.pod6 chunk 133 compiles | |
# say <67 97 109 101 108 105 97>.chrs; # OUTPUT: «Camelia» | |
ok 1386 - doc/Type/Cool.pod6 chunk 134 compiles | |
# multi sub split( Str:D $delimiter, Str(Cool) $input, $limit = Inf, :$k, :$v, :$kv, :$p, :$skip-empty) | |
# multi sub split(Regex:D $delimiter, Str(Cool) $input, $limit = Inf, :$k, :$v, :$kv, :$p, :$skip-empty) | |
# multi sub split(@delimiters, Str(Cool) $input, $limit = Inf, :$k, :$v, :$kv, :$p, :$skip-empty) | |
# multi method split( Str:D $delimiter, $limit = Inf, :$k, :$v, :$kv, :$p, :$skip-empty) | |
# multi method split(Regex:D $delimiter, $limit = Inf, :$k, :$v, :$kv, :$p, :$skip-empty) | |
# multi method split(@delimiters, $limit = Inf, :$k, :$v, :$kv, :$p, :$skip-empty) | |
ok 1387 - doc/Type/Cool.pod6 chunk 135 compiles | |
# say split(';', "a;b;c").perl; # OUTPUT: «("a", "b", "c")» | |
# say split(';', "a;b;c", 2).perl; # OUTPUT: «("a", "b;c").Seq» | |
# say split(';', "a;b;c,d").perl; # OUTPUT: «("a", "b", "c,d")» | |
# say split(/\;/, "a;b;c,d").perl; # OUTPUT: «("a", "b", "c,d")» | |
# say split(/<[;,]>/, "a;b;c,d").perl; # OUTPUT: «("a", "b", "c", "d")» | |
# say split(['a', /b+/, 4], '1a2bb345').perl; # OUTPUT: «("1", "2", "3", "5")» | |
ok 1388 - doc/Type/Cool.pod6 chunk 136 compiles | |
# say 'abc'.split(/b/, :v); # OUTPUT: «(a 「b」 c)» | |
# say 'abc'.split('b', :v); # OUTPUT: «(a b c)» | |
ok 1389 - doc/Type/Cool.pod6 chunk 137 compiles | |
# say 'abc'.split(/b/, :k); # OUTPUT: «(a 0 c)» | |
ok 1390 - doc/Type/Cool.pod6 chunk 138 compiles | |
# say 'abc'.split(/b/, :kv); # OUTPUT: «(a 0 「b」 c)» | |
ok 1391 - doc/Type/Cool.pod6 chunk 139 compiles | |
# say 'abc'.split(/b/, :p); # OUTPUT: «(a 0 => 「b」 c)» | |
# say 'abc'.split('b', :p); # OUTPUT: «(a 0 => b c)» | |
ok 1392 - doc/Type/Cool.pod6 chunk 140 compiles | |
# say ("f,,b,c,d".split: /","/ ).perl; # OUTPUT: «("f", "", "b", "c", "d")» | |
# say ("f,,b,c,d".split: /","/, :skip-empty).perl; # OUTPUT: «("f", "b", "c", "d")» | |
ok 1393 - doc/Type/Cool.pod6 chunk 141 compiles | |
# sub lines(Str(Cool)) | |
# method lines() | |
ok 1394 - doc/Type/Cool.pod6 chunk 142 compiles | |
# say lines("a\nb\n").join('|'); # OUTPUT: «a|b» | |
# say "some\nmore\nlines".lines.elems; # OUTPUT: «3» | |
ok 1395 - doc/Type/Cool.pod6 chunk 143 compiles | |
# method words(Int() $limit) | |
ok 1396 - doc/Type/Cool.pod6 chunk 144 compiles | |
# say 'The quick brown fox'.words.join('|'); # OUTPUT: «The|quick|brown|fox» | |
# say 'The quick brown fox'.words(2).join('|'); # OUTPUT: «The|quick» | |
ok 1397 - doc/Type/Cool.pod6 chunk 145 compiles | |
# say "isn't, can't".words.join('|'); # OUTPUT: «isn't,|can't» | |
ok 1398 - doc/Type/Cool.pod6 chunk 146 compiles | |
# multi sub comb(Regex $matcher, Str(Cool) $input, $limit = * --> Seq) | |
# multi method comb(Regex $matcher, $limit = * --> Seq) | |
ok 1399 - doc/Type/Cool.pod6 chunk 147 compiles | |
# say "6 or 12".comb(/\d+/).join(", "); # OUTPUT: «6, 12» | |
ok 1400 - doc/Type/Cool.pod6 chunk 148 compiles | |
# multi method contains(Cool:D: Str(Cool) $needle, Cool $start? --> Bool:D) | |
ok 1401 - doc/Type/Cool.pod6 chunk 149 compiles | |
# say "Hello, World".contains('hello'); # OUTPUT: «False» | |
# say "Hello, World".contains(','); # OUTPUT: «True» | |
ok 1402 - doc/Type/Cool.pod6 chunk 150 compiles | |
# multi sub index(Str(Cool) $s, Str:D $needle, Int(Cool) $startpos = 0 --> Int) | |
# multi method index(Str(Cool) $needle, Int(Cool) $startpos = 0 --> Int) | |
ok 1403 - doc/Type/Cool.pod6 chunk 151 compiles | |
# multi sub rindex(Str(Cool) $haystack, Str(Cool) $needle, Int(Cool) $startpos = $haystack.chars) | |
# multi method rindex(Str(Cool) $haystack: Str(Cool) $needle, Int(Cool) $startpos = $haystack.chars) | |
ok 1404 - doc/Type/Cool.pod6 chunk 152 compiles | |
# multi method match(Cool:D: $target, *%adverbs) | |
ok 1405 - doc/Type/Cool.pod6 chunk 153 compiles | |
# method fmt($format = '%s' --> Str:D) | |
ok 1406 - doc/Type/Cool.pod6 chunk 154 compiles | |
# say 11.fmt('This Int equals %03d'); # OUTPUT: «This Int equals 011» | |
# say '16'.fmt('Hexadecimal %x'); # OUTPUT: «Hexadecimal 10» | |
ok 1407 - doc/Type/Cool.pod6 chunk 155 compiles | |
# multi sub roots(Numeric(Cool) $x, Int(Cool) $n) | |
# multi method roots(Int(Cool) $n) | |
ok 1408 - doc/Type/Cool.pod6 chunk 156 compiles | |
# my $original = 16; | |
# my @roots = $original.roots(4); | |
# say @roots; | |
# for @roots -> $r { | |
# say abs($r ** 4 - $original); | |
# } | |
ok 1409 - doc/Type/Cool.pod6 chunk 157 compiles | |
# method IO(--> IO::Path:D) | |
ok 1410 - doc/Type/Cool.pod6 chunk 158 compiles | |
# sub EVAL(Cool $code, :$lang = { ... }) | |
ok 1411 - doc/Type/Cool.pod6 chunk 159 compiles | |
# use MONKEY-SEE-NO-EVAL; | |
# use MONKEY; # shortcut that turns on all MONKEY pragmas | |
# use Test; | |
# # any of the above allows: | |
# EVAL "say { 5 + 5 }"; # OUTPUT: «10» | |
ok 1412 - doc/Type/Cool.pod6 chunk 160 compiles | |
# my $answer = 42; | |
# EVAL 'say $answer;'; # OUTPUT: «42» | |
ok 1413 - doc/Type/Cool.pod6 chunk 161 compiles | |
# module M { | |
# EVAL 'our $answer = 42' | |
# } | |
# say $M::answer; # OUTPUT: «42» | |
ok 1414 - doc/Type/Cool.pod6 chunk 162 compiles | |
# sub infix:<mean>(*@a) is assoc<list> { | |
# @a.sum / @a.elems | |
# } | |
# EVAL 'say 2 mean 6 mean 4'; # OUTPUT: «4» | |
ok 1415 - doc/Type/Cool.pod6 chunk 163 compiles | |
# sub infix:<mean>(*@a) is assoc<list> { | |
# @a.sum / @a.elems | |
# } | |
# say EVAL 'say 1; 2 mean 6 mean 4'; # OUTPUT: «14» | |
ok 1416 - doc/Type/Cool.pod6 chunk 164 compiles | |
# sub EVALFILE(Cool $filename, :$lang = { ... }) | |
ok 1417 - doc/Type/Cool.pod6 chunk 165 compiles | |
# class Cursor { } | |
ok 1418 - doc/Type/Cursor.pod6 chunk 1 compiles | |
# method origin(Cursor:D: --> Any) | |
ok 1419 - doc/Type/Cursor.pod6 chunk 2 compiles | |
# method target(Cursor:D: --> Str:D) | |
ok 1420 - doc/Type/Cursor.pod6 chunk 3 compiles | |
# method pod(Cursor:D: --> Int:D) | |
ok 1421 - doc/Type/Cursor.pod6 chunk 4 compiles | |
# class Date { } | |
ok 1422 - doc/Type/Date.pod6 chunk 1 compiles | |
# my $d = Date.new(2015, 12, 24); # Christmas Eve! | |
# say $d; # OUTPUT: «2015-12-24» | |
# say $d.year; # OUTPUT: «2015» | |
# say $d.month; # OUTPUT: «12» | |
# say $d.day; # OUTPUT: «24» | |
# say $d.day-of-week; # OUTPUT: «1», that is Monday | |
# say $d.later(days => 20); # OUTPUT: «2016-01-13» | |
# my $n = Date.new('2015-12-31'); # New Year's Eve | |
# say $n - $d; # OUTPUT: «7», 7 days between New Years/Christmas Eve | |
# say $n + 1; # OUTPUT: «2016-01-01» | |
ok 1423 - doc/Type/Date.pod6 chunk 2 compiles | |
# multi method new($year, $month, $day, :&formatter --> Date:D) | |
# multi method new(:$year!, :$month = 1, :$day = 1 --> Date:D) | |
# multi method new(Str $date --> Date:D) | |
# multi method new(Instant:D $dt --> Date:D) | |
# multi method new(DateTime:D $dt --> Date:D) | |
ok 1424 - doc/Type/Date.pod6 chunk 3 compiles | |
# my $date = Date.new(2042, 1, 1); | |
# $date = Date.new(year => 2042, month => 1, day => 1); | |
# $date = Date.new("2042-01-01"); | |
# $date = Date.new(Instant.from-posix: 1482155532); | |
# $date = Date.new(DateTime.now); | |
ok 1425 - doc/Type/Date.pod6 chunk 4 compiles | |
# method new-from-daycount($daycount,:&formatter --> Date:D) | |
ok 1426 - doc/Type/Date.pod6 chunk 5 compiles | |
# say Date.new-from-daycount(49987); # OUTPUT: «1995-09-27» | |
ok 1427 - doc/Type/Date.pod6 chunk 6 compiles | |
# method clone(:$year, :$month, :$day) | |
ok 1428 - doc/Type/Date.pod6 chunk 7 compiles | |
# say Date.new('2015-11-24').clone(month => 12); # OUTPUT: «2015-12-24» | |
ok 1429 - doc/Type/Date.pod6 chunk 8 compiles | |
# method today(:&formatter --> Date:D) | |
ok 1430 - doc/Type/Date.pod6 chunk 9 compiles | |
# say Date.today; | |
ok 1431 - doc/Type/Date.pod6 chunk 10 compiles | |
# method later(Date:D: *%unit) | |
ok 1432 - doc/Type/Date.pod6 chunk 11 compiles | |
# say Date.new('2015-12-24').later(:2years); # OUTPUT: «2017-12-24» | |
ok 1433 - doc/Type/Date.pod6 chunk 12 compiles | |
# my $d = Date.new('2015-02-27'); | |
# say $d.later(month => 1).later(:2days); # OUTPUT: «2015-03-29» | |
# say $d.later(days => 2).later(:1month); # OUTPUT: «2015-04-01» | |
# say $d.later(days => 2).later(:month); # same, as +True === 1 | |
ok 1434 - doc/Type/Date.pod6 chunk 13 compiles | |
# method earlier(Date:D: *%unit) | |
ok 1435 - doc/Type/Date.pod6 chunk 14 compiles | |
# my $d = Date.new('2015-02-27'); | |
# say $d.earlier(month => 5).earlier(:2days); # OUTPUT: «2014-09-25» | |
ok 1436 - doc/Type/Date.pod6 chunk 15 compiles | |
# method truncated-to(Date:D: Cool $unit) | |
ok 1437 - doc/Type/Date.pod6 chunk 16 compiles | |
# my $c = Date.new('2012-12-24'); | |
# say $c.truncated-to('year'); # OUTPUT: «2012-01-01» | |
# say $c.truncated-to('month'); # OUTPUT: «2012-12-01» | |
# say $c.truncated-to('week'); # OUTPUT: «2012-12-24», because it's Monday already | |
ok 1438 - doc/Type/Date.pod6 chunk 17 compiles | |
# method succ(Date:D: --> Date:D) | |
ok 1439 - doc/Type/Date.pod6 chunk 18 compiles | |
# say Date.new("2016-02-28").succ; # OUTPUT: «2016-02-29» | |
ok 1440 - doc/Type/Date.pod6 chunk 19 compiles | |
# method pred(Date:D: --> Date:D) | |
ok 1441 - doc/Type/Date.pod6 chunk 20 compiles | |
# say Date.new("2016-01-01").pred; # OUTPUT: «2015-12-31» | |
ok 1442 - doc/Type/Date.pod6 chunk 21 compiles | |
# multi method Str(Date:D: --> Str:D) | |
ok 1443 - doc/Type/Date.pod6 chunk 22 compiles | |
# say Date.new('2015-12-24').Str; # OUTPUT: «2015-12-24» | |
# my $fmt = { sprintf "%02d/%02d/%04d", .month, .day, .year }; | |
# say Date.new('2015-12-24', formatter => $fmt).Str; # OUTPUT: «12/24/2015» | |
ok 1444 - doc/Type/Date.pod6 chunk 23 compiles | |
# multi method gist(Date:D: --> Str:D) | |
ok 1445 - doc/Type/Date.pod6 chunk 24 compiles | |
# say Date.new('2015-12-24').gist; # OUTPUT: «2015-12-24» | |
ok 1446 - doc/Type/Date.pod6 chunk 25 compiles | |
# method Date(--> Date) | |
ok 1447 - doc/Type/Date.pod6 chunk 26 compiles | |
# say Date.new('2015-12-24').Date; # OUTPUT: «2015-12-24» | |
# say Date.Date; # OUTPUT: «(Date)» | |
ok 1448 - doc/Type/Date.pod6 chunk 27 compiles | |
# multi method DateTime(Date:U --> DateTime:U) | |
# multi method DateTime(Date:D --> DateTime:D) | |
ok 1449 - doc/Type/Date.pod6 chunk 28 compiles | |
# say Date.new('2015-12-24').DateTime; # OUTPUT: «2015-12-24T00:00:00Z» | |
# say Date.DateTime; # OUTPUT: «(DateTime)» | |
ok 1450 - doc/Type/Date.pod6 chunk 29 compiles | |
# sub sleep($seconds = Inf --> Nil) | |
ok 1451 - doc/Type/Date.pod6 chunk 30 compiles | |
# my $before = now; | |
# sleep (5/2); | |
# my $after = now; | |
# say $after-$before; # OUTPUT: «2.502411561» | |
# $before = now; | |
# sleep 5.2; | |
# $after = now; | |
# say $after-$before; # OUTPUT: «5.20156987» | |
ok 1452 - doc/Type/Date.pod6 chunk 31 compiles | |
# sub sleep-timer(Real $seconds = Inf --> Duration) | |
ok 1453 - doc/Type/Date.pod6 chunk 32 compiles | |
# say sleep-timer 3.14; # OUTPUT: «0» | |
ok 1454 - doc/Type/Date.pod6 chunk 33 compiles | |
# sub sleep-until(Instant $until --> Bool) | |
ok 1455 - doc/Type/Date.pod6 chunk 34 compiles | |
# say sleep-until now+10; # OUTPUT: «True» | |
ok 1456 - doc/Type/Date.pod6 chunk 35 compiles | |
# my $instant = now - 5; | |
# say sleep-until $instant; # OUTPUT: «False» | |
ok 1457 - doc/Type/Date.pod6 chunk 36 compiles | |
# multi sub infix:<-> (Date:D, Int:D --> Date:D) | |
# multi sub infix:<-> (Date:D, Date:D --> Int:D) | |
ok 1458 - doc/Type/Date.pod6 chunk 37 compiles | |
# say Date.new('2016-12-25') - Date.new('2016-12-24'); # OUTPUT: «1» | |
# say Date.new('2015-12-25') - Date.new('2016-11-21'); # OUTPUT: «-332» | |
# say Date.new('2016-11-21') - 332; # OUTPUT: «2015-12-25» | |
ok 1459 - doc/Type/Date.pod6 chunk 38 compiles | |
# multi sub infix:<+> (Date:D, Int:D --> Date:D) | |
# multi sub infix:<+> (Int:D, Date:D --> Date:D) | |
ok 1460 - doc/Type/Date.pod6 chunk 39 compiles | |
# say Date.new('2015-12-25') + 332; # OUTPUT: «2016-11-21» | |
# say 1 + Date.new('2015-12-25'); # OUTPUT: «2015-12-26» | |
ok 1461 - doc/Type/Date.pod6 chunk 40 compiles | |
# class DateTime does Dateish {} | |
ok 1462 - doc/Type/DateTime.pod6 chunk 1 compiles | |
# use v6.c; | |
# my $dt = DateTime.new( | |
# year => 2015, | |
# month => 11, | |
# day => 21, | |
# hour => 16, | |
# minute => 1, | |
# ); | |
# say $dt; # OUTPUT: «2015-11-21T16:01:00Z» | |
# say $dt.later(days => 20); # OUTPUT: «2015-12-11T16:01:00Z» | |
# say $dt.truncated-to('hour'); # OUTPUT: «2015-11-21T16:00:00Z» | |
# say $dt.in-timezone(-8 * 3600); # OUTPUT: «2015-11-21T08:01:00-0800» | |
# my $now = DateTime.now(formatter => { sprintf "%02d:%02d", .hour, .minute }); | |
# say $now; # 12:45 (or something like that) | |
ok 1463 - doc/Type/DateTime.pod6 chunk 2 compiles | |
# my $datetime = DateTime.new(year => 2015, | |
# month => 1, | |
# day => 1, | |
# hour => 1, | |
# minute => 1, | |
# second => 1, | |
# timezone => 1); | |
# $datetime = DateTime.new(date => Date.new('2015-12-24'), | |
# hour => 1, | |
# minute => 1, | |
# second => 1, | |
# timezone => 1); | |
# $datetime = DateTime.new(2015, 1, 1, # First January of 2015 | |
# 1, 1, 1); # Hour, minute, second with default timezone | |
# $datetime = DateTime.new(now); # Instant. | |
# # from a Unix timestamp | |
# say $datetime = DateTime.new(1470853583); # OUTPUT: «2016-08-10T18:26:23Z» | |
# $datetime = DateTime.new("2015-01-01T03:17:30+0500") # Formatted string | |
ok 1464 - doc/Type/DateTime.pod6 chunk 3 compiles | |
# method now(:$timezone=$*TZ, :&formatter --> DateTime:D) | |
ok 1465 - doc/Type/DateTime.pod6 chunk 4 compiles | |
# say DateTime.now; | |
ok 1466 - doc/Type/DateTime.pod6 chunk 5 compiles | |
# method clone(:$year, :$month, :$day, :$hour, :$minute, :$second, :$timezone, :&formatter) | |
ok 1467 - doc/Type/DateTime.pod6 chunk 6 compiles | |
# say DateTime.new('2015-12-24T12:23:00Z').clone(hour => 0); | |
# # OUTPUT: «2015-12-24T00:23:00Z» | |
ok 1468 - doc/Type/DateTime.pod6 chunk 7 compiles | |
# say DateTime.new("2012-02-29T12:34:56Z").clone(year => 2015); | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::OutOfRange: Day out of range. Is: 29, should be in 1..28» | |
ok 1469 - doc/Type/DateTime.pod6 chunk 8 compiles | |
# method hh-mm-ss(DateTime:D: --> Str:D) | |
ok 1470 - doc/Type/DateTime.pod6 chunk 9 compiles | |
# say DateTime.new("2052-02-29T22:34:56Z").hh-mm-ss; | |
# # OUTPUT: «22:34:56» | |
ok 1471 - doc/Type/DateTime.pod6 chunk 10 compiles | |
# method hour(DateTime:D: --> Int:D) | |
ok 1472 - doc/Type/DateTime.pod6 chunk 11 compiles | |
# say DateTime.new('2012-02-29T12:34:56Z').hour; # OUTPUT: «12» | |
ok 1473 - doc/Type/DateTime.pod6 chunk 12 compiles | |
# method minute(DateTime:D: --> Int:D) | |
ok 1474 - doc/Type/DateTime.pod6 chunk 13 compiles | |
# say DateTime.new('2012-02-29T12:34:56Z').minute; # OUTPUT: «34» | |
ok 1475 - doc/Type/DateTime.pod6 chunk 14 compiles | |
# method second(DateTime:D:) | |
ok 1476 - doc/Type/DateTime.pod6 chunk 15 compiles | |
# say DateTime.new('2012-02-29T12:34:56Z').second; # OUTPUT: «56» | |
# say DateTime.new('2012-02-29T12:34:56.789Z').second; # OUTPUT: «56.789» | |
# say DateTime.new('2012-02-29T12:34:56,789Z').second; # comma also ok | |
ok 1477 - doc/Type/DateTime.pod6 chunk 16 compiles | |
# method whole-second(DateTime:D:) | |
ok 1478 - doc/Type/DateTime.pod6 chunk 17 compiles | |
# say DateTime.new('2012-02-29T12:34:56.789Z').whole-second; # OUTPUT: «56» | |
ok 1479 - doc/Type/DateTime.pod6 chunk 18 compiles | |
# method timezone(DateTime:D: --> Int:D) | |
ok 1480 - doc/Type/DateTime.pod6 chunk 19 compiles | |
# say DateTime.new('2015-12-24T12:23:00+0200').timezone; # OUTPUT: «7200» | |
ok 1481 - doc/Type/DateTime.pod6 chunk 20 compiles | |
# method offset(DateTime:D: --> Int:D) | |
ok 1482 - doc/Type/DateTime.pod6 chunk 21 compiles | |
# say DateTime.new('2015-12-24T12:23:00+0200').offset; # OUTPUT: «7200» | |
ok 1483 - doc/Type/DateTime.pod6 chunk 22 compiles | |
# method offset-in-minutes(DateTime:D: --> Real:D) | |
ok 1484 - doc/Type/DateTime.pod6 chunk 23 compiles | |
# say DateTime.new('2015-12-24T12:23:00+0200').offset-in-minutes; # OUTPUT: «120» | |
ok 1485 - doc/Type/DateTime.pod6 chunk 24 compiles | |
# method offset-in-hours(DateTime:D: --> Real:D) | |
ok 1486 - doc/Type/DateTime.pod6 chunk 25 compiles | |
# say DateTime.new('2015-12-24T12:23:00+0200').offset-in-hours; # OUTPUT: «2» | |
ok 1487 - doc/Type/DateTime.pod6 chunk 26 compiles | |
# method Str(DateTime:D: --> Str:D) | |
ok 1488 - doc/Type/DateTime.pod6 chunk 27 compiles | |
# say DateTime.new('2015-12-24T12:23:00+0200').Str; # OUTPUT: «2015-12-24T12:23:00+02:00» | |
ok 1489 - doc/Type/DateTime.pod6 chunk 28 compiles | |
# method Instant(DateTime:D: --> Instant:D) | |
ok 1490 - doc/Type/DateTime.pod6 chunk 29 compiles | |
# say DateTime.new('2015-12-24T12:23:00+0200').Instant; # OUTPUT: «2015-12-24T12:23:00+02:00» | |
ok 1491 - doc/Type/DateTime.pod6 chunk 30 compiles | |
# method posix(DateTime:D: $ignore-timezone = False --> Int:D) | |
ok 1492 - doc/Type/DateTime.pod6 chunk 31 compiles | |
# say DateTime.new('2015-12-24T12:23:00Z').posix; # OUTPUT: «1450959780» | |
ok 1493 - doc/Type/DateTime.pod6 chunk 32 compiles | |
# method later(DateTime:D: *%unit) | |
ok 1494 - doc/Type/DateTime.pod6 chunk 33 compiles | |
# say DateTime.new('2015-12-24T12:23:00Z').later(:2years); # OUTPUT: «2017-12-24T12:23:00Z» | |
ok 1495 - doc/Type/DateTime.pod6 chunk 34 compiles | |
# my $d = DateTime.new(date => Date.new('2015-02-27')); | |
# say $d.later(month => 1).later(:2days); # OUTPUT: «2015-03-29T00:00:00Z» | |
# say $d.later(days => 2).later(:1month); # OUTPUT: «2015-04-01T00:00:00Z» | |
# say $d.later(days => 2).later(:month); # same, as +True === 1 | |
ok 1496 - doc/Type/DateTime.pod6 chunk 35 compiles | |
# method earlier(DateTime:D: *%unit) | |
ok 1497 - doc/Type/DateTime.pod6 chunk 36 compiles | |
# my $d = DateTime.new(date => Date.new('2015-02-27')); | |
# say $d.earlier(month => 1).earlier(:2days); # OUTPUT: «2015-01-25T00:00:00Z» | |
ok 1498 - doc/Type/DateTime.pod6 chunk 37 compiles | |
# method truncated-to(DateTime:D: Cool $unit) | |
ok 1499 - doc/Type/DateTime.pod6 chunk 38 compiles | |
# my $d = DateTime.new("2012-02-29T12:34:56.946314Z"); | |
# say $d.truncated-to('second'); # OUTPUT: «2012-02-29T12:34:56Z» | |
# say $d.truncated-to('minute'); # OUTPUT: «2012-02-29T12:34:00Z» | |
# say $d.truncated-to('hour'); # OUTPUT: «2012-02-29T12:00:00Z» | |
# say $d.truncated-to('day'); # OUTPUT: «2012-02-29T00:00:00Z» | |
# say $d.truncated-to('month'); # OUTPUT: «2012-02-01T00:00:00Z» | |
# say $d.truncated-to('year'); # OUTPUT: «2012-01-01T00:00:00Z» | |
ok 1500 - doc/Type/DateTime.pod6 chunk 39 compiles | |
# multi method Date(DateTime:U --> Date:U) | |
# multi method Date(DateTime:D --> Date:D) | |
ok 1501 - doc/Type/DateTime.pod6 chunk 40 compiles | |
# say DateTime.new("2012-02-29T12:34:56.946314Z").Date; # OUTPUT: «2012-02-29» | |
# say DateTime.Date; # OUTPUT: «(Date)» | |
ok 1502 - doc/Type/DateTime.pod6 chunk 41 compiles | |
# method DateTime(--> DateTime) | |
ok 1503 - doc/Type/DateTime.pod6 chunk 42 compiles | |
# say DateTime.new("2012-02-29T12:34:56.946314Z").DateTime; # 2012-02-29T12:34:56.946314Z | |
# say DateTime.DateTime; # OUTPUT: «(DateTime)» | |
ok 1504 - doc/Type/DateTime.pod6 chunk 43 compiles | |
# method utc(DateTime:D: --> DateTime:D) | |
ok 1505 - doc/Type/DateTime.pod6 chunk 44 compiles | |
# say DateTime.new('2015-12-24T12:23:00+0200').utc; # OUTPUT: «2015-12-24T10:23:00Z» | |
ok 1506 - doc/Type/DateTime.pod6 chunk 45 compiles | |
# method in-timezone(DateTime:D: $timezone = 0 --> DateTime:D) | |
ok 1507 - doc/Type/DateTime.pod6 chunk 46 compiles | |
# say DateTime.new('2015-12-24T12:23:00Z').in-timezone(3600 + 1800); # OUTPUT: «2015-12-24T13:53:00+0130» | |
ok 1508 - doc/Type/DateTime.pod6 chunk 47 compiles | |
# method local(DateTime:D: --> DateTime:D) | |
ok 1509 - doc/Type/DateTime.pod6 chunk 48 compiles | |
# my $*TZ = -3600; | |
# say DateTime.new('2015-12-24T12:23:00+0200').local; # OUTPUT: «2015-12-24T09:23:00-0100» | |
ok 1510 - doc/Type/DateTime.pod6 chunk 49 compiles | |
# multi sub infix:<-> (DateTime:D, Duration:D --> DateTime:D) | |
# multi sub infix:<-> (DateTime:D, DateTime:D --> Duration:D) | |
ok 1511 - doc/Type/DateTime.pod6 chunk 50 compiles | |
# say perl DateTime.new(:2016year) - DateTime.new(:2015year):; # OUTPUT: «Duration.new(31536001.0)» | |
# say DateTime.new(:2016year, :3600timezone) - Duration.new(31536001.0); # OUTPUT: «2015-01-01T00:00:00+01:00» | |
ok 1512 - doc/Type/DateTime.pod6 chunk 51 compiles | |
# multi sub infix:<+> (DateTime:D, Duration:D --> DateTime:D) | |
# multi sub infix:<+> (Duration:D, DateTime:D --> DateTime:D) | |
ok 1513 - doc/Type/DateTime.pod6 chunk 52 compiles | |
# say DateTime.new(:2015year) + Duration.new(31536001.0); # OUTPUT: «2016-01-01T00:00:00Z» | |
# say Duration.new(42) + DateTime.new(:2015year, :3600timezone); # OUTPUT: «2015-01-01T00:00:42+01:00» | |
ok 1514 - doc/Type/DateTime.pod6 chunk 53 compiles | |
# role Dateish { ... } | |
ok 1515 - doc/Type/Dateish.pod6 chunk 1 compiles | |
# method year(Date:D: --> Int:D) | |
ok 1516 - doc/Type/Dateish.pod6 chunk 2 compiles | |
# say Date.new('2015-12-31').year; # OUTPUT: «2015» | |
# say DateTime.new(date => Date.new('2015-12-24'), hour => 1).year; # OUTPUT: «2015» | |
ok 1517 - doc/Type/Dateish.pod6 chunk 3 compiles | |
# method month(Date:D: --> Int:D) | |
ok 1518 - doc/Type/Dateish.pod6 chunk 4 compiles | |
# say Date.new('2015-12-31').month; # OUTPUT: «12» | |
# say DateTime.new(date => Date.new('2015-12-24'), hour => 1).month; # OUTPUT: «12» | |
ok 1519 - doc/Type/Dateish.pod6 chunk 5 compiles | |
# method day(Date:D: --> Int:D) | |
ok 1520 - doc/Type/Dateish.pod6 chunk 6 compiles | |
# say Date.new('2015-12-31').day; # OUTPUT: «31» | |
# say DateTime.new(date => Date.new('2015-12-24'), hour => 1).day; # OUTPUT: «24» | |
ok 1521 - doc/Type/Dateish.pod6 chunk 7 compiles | |
# method formatter(Dateish:D:) | |
ok 1522 - doc/Type/Dateish.pod6 chunk 8 compiles | |
# my $dt = Date.new('2015-12-31'); # (no formatter specified) | |
# say $dt.formatter.WHAT; # OUTPUT: «(Callable)» | |
# my $us-format = sub ($self) { sprintf "%02d/%02d/%04d", .month, .day, .year given $self; }; | |
# $dt = Date.new('2015-12-31', formatter => $us-format); | |
# say $dt.formatter.WHAT; # OUTPUT: «(Sub)» | |
# say $dt; # OUTPUT: «12/31/2015» | |
ok 1523 - doc/Type/Dateish.pod6 chunk 9 compiles | |
# method is-leap-year(--> Bool:D) | |
ok 1524 - doc/Type/Dateish.pod6 chunk 10 compiles | |
# say DateTime.new(:year<2016>).is-leap-year; # OUTPUT: «True» | |
# say Date.new("1900-01-01").is-leap-year; # OUTPUT: «False» | |
ok 1525 - doc/Type/Dateish.pod6 chunk 11 compiles | |
# method day-of-month(Date:D: --> Int:D) | |
ok 1526 - doc/Type/Dateish.pod6 chunk 12 compiles | |
# say Date.new('2015-12-31').day-of-month; # OUTPUT: «31» | |
# say DateTime.new(date => Date.new('2015-12-24'), hour => 1).day-of-month; # OUTPUT: «24» | |
ok 1527 - doc/Type/Dateish.pod6 chunk 13 compiles | |
# method day-of-week(Date:D: --> Int:D) | |
ok 1528 - doc/Type/Dateish.pod6 chunk 14 compiles | |
# say Date.new('2015-12-31').day-of-week; # OUTPUT: «4» | |
# say DateTime.new(date => Date.new('2015-12-24'), hour => 1).day-of-week; # OUTPUT: «4» | |
ok 1529 - doc/Type/Dateish.pod6 chunk 15 compiles | |
# method day-of-year(Date:D: --> Int:D) | |
ok 1530 - doc/Type/Dateish.pod6 chunk 16 compiles | |
# say Date.new('2015-12-31').day-of-year; # OUTPUT: «365» | |
# say DateTime.new(date => Date.new('2015-03-24'), hour => 1).day-of-year; # OUTPUT: «83» | |
ok 1531 - doc/Type/Dateish.pod6 chunk 17 compiles | |
# method days-in-month(Dateish:D: --> Int:D) | |
ok 1532 - doc/Type/Dateish.pod6 chunk 18 compiles | |
# say Date.new("2016-01-02").days-in-month; # OUTPUT: «31» | |
# say DateTime.new(:year<10000>, :month<2>).days-in-month; # OUTPUT: «29» | |
ok 1533 - doc/Type/Dateish.pod6 chunk 19 compiles | |
# method week() | |
ok 1534 - doc/Type/Dateish.pod6 chunk 20 compiles | |
# my ($year, $week) = Date.new("2014-12-31").week; | |
# say $year; # OUTPUT: «2015» | |
# say $week; # OUTPUT: «1» | |
# say Date.new('2015-01-31').week; # OUTPUT: «(2015 5)» | |
ok 1535 - doc/Type/Dateish.pod6 chunk 21 compiles | |
# method week-number(Date:D: --> Int:D) | |
ok 1536 - doc/Type/Dateish.pod6 chunk 22 compiles | |
# say Date.new("2014-12-31").week-number; # 1 (first week of 2015) | |
# say Date.new("2016-01-02").week-number; # 53 (last week of 2015) | |
ok 1537 - doc/Type/Dateish.pod6 chunk 23 compiles | |
# method week-year(Date:D: --> Int:D) | |
ok 1538 - doc/Type/Dateish.pod6 chunk 24 compiles | |
# say Date.new("2015-11-15").week-year; # 2015 | |
# say Date.new("2014-12-31").week-year; # 2015 (date belongs to the first week of 2015) | |
# say Date.new("2016-01-02").week-year; # 2015 (date belongs to the last week of 2015) | |
ok 1539 - doc/Type/Dateish.pod6 chunk 25 compiles | |
# method weekday-of-month(Date:D: --> Int:D) | |
ok 1540 - doc/Type/Dateish.pod6 chunk 26 compiles | |
# say Date.new("2003-06-09").weekday-of-month; # 2 (second Monday of the month) | |
ok 1541 - doc/Type/Dateish.pod6 chunk 27 compiles | |
# method yyyy-mm-dd(Date:D: --> Str:D) | |
ok 1542 - doc/Type/Dateish.pod6 chunk 28 compiles | |
# say Date.new("2015-11-15").yyyy-mm-dd; # OUTPUT: «2015-11-15» | |
# say DateTime.new(1470853583).yyyy-mm-dd; # OUTPUT: «2016-08-10» | |
ok 1543 - doc/Type/Dateish.pod6 chunk 29 compiles | |
# method daycount(Dateish:D: --> Int:D) | |
ok 1544 - doc/Type/Dateish.pod6 chunk 30 compiles | |
# say Date.new('1995-09-27').daycount; # OUTPUT: «49987» | |
ok 1545 - doc/Type/Dateish.pod6 chunk 31 compiles | |
# method IO(Dateish:D: --> IO::Path:D) | |
ok 1546 - doc/Type/Dateish.pod6 chunk 32 compiles | |
# Date.today.IO.say; # OUTPUT: «"2016-10-03".IO» | |
# DateTime.now.IO.say; # OUTPUT: «"2016-10-03T11:14:47.977994-04:00".IO» | |
ok 1547 - doc/Type/Dateish.pod6 chunk 33 compiles | |
# class Duration is Cool does Real { } | |
ok 1548 - doc/Type/Duration.pod6 chunk 1 compiles | |
# class Exception {} | |
ok 1549 - doc/Type/Exception.pod6 chunk 1 compiles | |
# class X::YourApp::SomeError is Exception { | |
# method message() { | |
# "A YourApp-Specific error occurred: out of coffee!"; | |
# } | |
# } | |
ok 1550 - doc/Type/Exception.pod6 chunk 2 compiles | |
# method message(Exception:D: --> Str:D) | |
ok 1551 - doc/Type/Exception.pod6 chunk 3 compiles | |
# try die "Something bad happened"; | |
# if ($!) { | |
# say $!.message; # OUTPUT: «Something bad happened.» | |
# } | |
ok 1552 - doc/Type/Exception.pod6 chunk 4 compiles | |
# method backtrace(Exception:D: --> Backtrace:D) | |
ok 1553 - doc/Type/Exception.pod6 chunk 5 compiles | |
# try die "Something bad happened"; | |
# if ($!) { | |
# say $!.backtrace; | |
# } | |
ok 1554 - doc/Type/Exception.pod6 chunk 6 compiles | |
# method throw(Exception:D:) | |
ok 1555 - doc/Type/Exception.pod6 chunk 7 compiles | |
# my $exception = X::AdHoc.new; # Totally fine | |
# try $exception.throw; # Throws | |
# if ($!) { #`( some handling ) }; # Suppress the exception | |
ok 1556 - doc/Type/Exception.pod6 chunk 8 compiles | |
# method resume(Exception:D:) | |
ok 1557 - doc/Type/Exception.pod6 chunk 9 compiles | |
# # For example, resume control flow for any exception | |
# CATCH { default { .resume } } | |
ok 1558 - doc/Type/Exception.pod6 chunk 10 compiles | |
# method rethrow(Exception:D:) | |
ok 1559 - doc/Type/Exception.pod6 chunk 11 compiles | |
# my $e = X::AdHoc.new(payload => "Bad situation"); | |
# sub f() { die 'Bad' }; | |
# sub g() { try f; CATCH { default { .rethrow } } }; | |
# g; | |
# CATCH { default { say .backtrace.full } }; | |
ok 1560 - doc/Type/Exception.pod6 chunk 12 compiles | |
# multi sub fail(*@text) | |
# multi sub fail(Exception $e) | |
# method fail(Exception:D:) | |
ok 1561 - doc/Type/Exception.pod6 chunk 13 compiles | |
# sub copy-directory-tree ($dir) { | |
# fail "$dir is not a directory" if !$dir.IO.d; | |
# ... | |
# } | |
ok 1562 - doc/Type/Exception.pod6 chunk 14 compiles | |
# multi method gist(Exception:D:) | |
ok 1563 - doc/Type/Exception.pod6 chunk 15 compiles | |
# my $e = X::AdHoc.new(payload => "This exception is pretty bad"); | |
# try $e.throw; | |
# if ($!) { say $!.gist; }; | |
# # OUTPUT: «This exception is pretty bad | |
# # in block <unit> at <unknown file> line 1» | |
ok 1564 - doc/Type/Exception.pod6 chunk 16 compiles | |
# multi sub die(*@message) | |
# multi sub die(Exception:D $e) | |
# method die(Exception:D:) | |
ok 1565 - doc/Type/Exception.pod6 chunk 17 compiles | |
# multi sub warn(*@message) | |
ok 1566 - doc/Type/Exception.pod6 chunk 18 compiles | |
# warn "Warning message"; | |
ok 1567 - doc/Type/Exception.pod6 chunk 19 compiles | |
# class Failure { } | |
ok 1568 - doc/Type/Failure.pod6 chunk 1 compiles | |
# method handled(Failure:D: --> Bool:D) | |
ok 1569 - doc/Type/Failure.pod6 chunk 2 compiles | |
# sub f() { fail }; my $v = f; say $v.handled; # OUTPUT: «False» | |
ok 1570 - doc/Type/Failure.pod6 chunk 3 compiles | |
# method exception(Failure:D: --> Exception) | |
ok 1571 - doc/Type/Failure.pod6 chunk 4 compiles | |
# sub f() { fail }; my $v = f; $v.Exception; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::AdHoc: Failed» | |
ok 1572 - doc/Type/Failure.pod6 chunk 5 compiles | |
# multi method Bool(Failure:D: --> Bool:D) | |
ok 1573 - doc/Type/Failure.pod6 chunk 6 compiles | |
# sub f() { fail }; my $v = f; say $v.handled; $v.Bool; say $v.handled; | |
# # OUTPUT: «False | |
# # True» | |
ok 1574 - doc/Type/Failure.pod6 chunk 7 compiles | |
# multi method defined(Failure:D: --> Bool:D) | |
ok 1575 - doc/Type/Failure.pod6 chunk 8 compiles | |
# sub f() { fail }; my $v = f; say $v.defined; # OUTPUT: «False» | |
ok 1576 - doc/Type/Failure.pod6 chunk 9 compiles | |
# class FatRat is Cool does Rational[Int, Int] {} | |
ok 1577 - doc/Type/FatRat.pod6 chunk 1 compiles | |
# class Grammar is Cursor {} | |
ok 1578 - doc/Type/Grammar.pod6 chunk 1 compiles | |
# grammar Thingy { | |
# token TOP { | |
# <a> <b> | |
# } | |
# token a { a } | |
# token b { b } | |
# } | |
# say Thingy ~~ Grammar; # OUTPUT: «True» | |
# my $match = Thingy.parse('ab'); | |
# say so $match; # OUTPUT: «True» | |
# say ~$match<a>; # OUTPUT: «a» | |
ok 1579 - doc/Type/Grammar.pod6 chunk 2 compiles | |
# method parse($target, :$rule = 'TOP', Capture() :$args = \(), Mu :$actions = Mu, *%opt) | |
ok 1580 - doc/Type/Grammar.pod6 chunk 3 compiles | |
# grammar CSV { | |
# token TOP { [ <line> \n? ]+ } | |
# token line { | |
# ^^ # Beginning of a line | |
# <value>* % \, # Any number of <value>s with commas in between them | |
# $$ # End of a line | |
# } | |
# token value { | |
# [ | |
# | <-[",\n]> # Anything not a double quote, comma or newline | |
# | <quoted-text> # Or some quoted text | |
# ]* # Any number of times | |
# } | |
# token quoted-text { | |
# \" | |
# [ | |
# | <-["\\]> # Anything not a " or \ | |
# | '\"' # Or \", an escaped quotation mark | |
# ]* # Any number of times | |
# \" | |
# } | |
# }.parse( q:to/EOCSV/ ).say; | |
# Year,Make,Model,Length | |
# 1997,Ford,E350,2.34 | |
# 2000,Mercury,Cougar,2.38 | |
# EOCSV | |
ok 1581 - doc/Type/Grammar.pod6 chunk 4 compiles | |
# method subparse($target, :$rule = 'TOP', Capture() :$args = \(), Mu :$actions = Mu, *%opt) | |
ok 1582 - doc/Type/Grammar.pod6 chunk 5 compiles | |
# grammar A { | |
# token as { a+ }; | |
# } | |
# my $match = A.subparse('aaab', :rule<as>); | |
# say ~$match; # OUTPUT: «aaa» | |
# say $match.to; # OUTPUT: «3» | |
ok 1583 - doc/Type/Grammar.pod6 chunk 6 compiles | |
# method parsefile(Str(Cool) $filename, :$enc, *%opts) | |
ok 1584 - doc/Type/Grammar.pod6 chunk 7 compiles | |
# class Hash is Map { } | |
ok 1585 - doc/Type/Hash.pod6 chunk 1 compiles | |
# dd %*ENV{'HOME', 'PATH'}; | |
# # OUTPUT: «("/home/camelia", "/usr/bin:/sbin:/bin")» | |
ok 1586 - doc/Type/Hash.pod6 chunk 2 compiles | |
# my %h = oranges => 'round', bananas => 'bendy'; | |
# dd %h<oranges bananas>; | |
# # OUTPUT: «("round", "bendy")» | |
# my $fruit = 'bananas'; | |
# dd %h«oranges $fruit»; | |
# # OUTPUT: «("round", "bendy")» | |
ok 1587 - doc/Type/Hash.pod6 chunk 3 compiles | |
# my %h; | |
# %h{'new key'} = 'new value'; | |
ok 1588 - doc/Type/Hash.pod6 chunk 4 compiles | |
Potential difficulties: | |
Redeclaration of symbol '%h' | |
at /Users/williamcoleda/sandbox/doc/EVAL_1591:4 | |
------> [32mmy %h[33m⏏[31m = a => 'b', c => 'd', e => 'f';[0m | |
Redeclaration of symbol '%h' | |
at /Users/williamcoleda/sandbox/doc/EVAL_1591:6 | |
------> [32mmy %h[33m⏏[31m = <a b c d e f>;[0m | |
# my %h = 'a', 'b', c => 'd', 'e', 'f'; | |
# # same as | |
# my %h = a => 'b', c => 'd', e => 'f'; | |
# # or | |
# my %h = <a b c d e f>; | |
ok 1589 - doc/Type/Hash.pod6 chunk 5 compiles | |
# my %h = 'a', 'b' => 'c'; | |
# say %h<a>.WHAT; # OUTPUT: «(Pair)» | |
# say %h<a>.key; # OUTPUT: «b» | |
ok 1590 - doc/Type/Hash.pod6 chunk 6 compiles | |
# my %h = a => 1, a => 2; | |
# say %h<a>; # OUTPUT: «2» | |
ok 1591 - doc/Type/Hash.pod6 chunk 7 compiles | |
# my $h = { a => 1, b => 2 }; # *See Note* | |
# say $h.WHAT; # OUTPUT: «Hash» | |
# say $h<a>; # OUTPUT: «1» | |
ok 1592 - doc/Type/Hash.pod6 chunk 8 compiles | |
# my @people = [ | |
# { id => "1A", firstName => "Andy", lastName => "Adams" }, | |
# { id => "2B", firstName => "Beth", lastName => "Burke" }, | |
# # ... | |
# ]; | |
# sub lookup-user (Hash $h) { #`(Do something...) $h } | |
# my @names = map { | |
# my $query = { name => "$_<firstName> $_<lastName>" }; | |
# say $query.WHAT; # OUTPUT: «Block» | |
# say $query<name>; # fails | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::AdHoc: Type Block does not support associative indexing.» | |
# lookup-user($query); # Type check failed in binding $h; expected Hash but got Block | |
# }, @people; | |
ok 1593 - doc/Type/Hash.pod6 chunk 9 compiles | |
# my @people = [ | |
# { id => "1A", firstName => "Andy", lastName => "Adams" }, | |
# { id => "2B", firstName => "Beth", lastName => "Burke" } | |
# ]; | |
# sub lookup-user (Hash $h) { #`(Do something...) $h } | |
# my @names = @people.map: -> $person { | |
# lookup-user( %( name => "$person<firstName> $person<lastName>" ) ); | |
# }; | |
ok 1594 - doc/Type/Hash.pod6 chunk 10 compiles | |
Potential difficulties: | |
Redeclaration of symbol '%h' | |
at /Users/williamcoleda/sandbox/doc/EVAL_1597:3 | |
------> [32mmy %h[33m⏏[31m; %h<a b c> = ^3; %h.perl.say; # OU[0m | |
# my %h; %h<a b c> = 2 xx *; %h.perl.say; # OUTPUT: «{:a(2), :b(2), :c(2)}» | |
# my %h; %h<a b c> = ^3; %h.perl.say; # OUTPUT: «{:a(0), :b(1), :c(2)}» | |
ok 1595 - doc/Type/Hash.pod6 chunk 11 compiles | |
# my $when = :{ (now) => "Instant", (DateTime.now) => "DateTime" }; | |
ok 1596 - doc/Type/Hash.pod6 chunk 12 compiles | |
# :{ -1 => 41, 0 => 42, 1 => 43 }<0>; # Any | |
# :{ -1 => 41, 0 => 42, 1 => 43 }{0}; # 42 | |
ok 1597 - doc/Type/Hash.pod6 chunk 13 compiles | |
# subset Powerful of Int where * > 9000; | |
# my Powerful %h{Str}; | |
# put %h<Goku> = 9001; | |
# try { | |
# %h<Vegeta> = 900; | |
# CATCH { when X::TypeCheck::Binding { .message.put } } | |
# } | |
# # OUTPUT: | |
# # 9001 | |
# # Type check failed in binding assignval; expected Powerful but got Int (900) | |
ok 1598 - doc/Type/Hash.pod6 chunk 14 compiles | |
# my %vowels = 'a' => 1, 'e' => 2, 'i' => 3, 'o' => 4, 'u' => 5; | |
# for %vowels.kv -> $vowel, $index { | |
# "$vowel: $index".say; | |
# } | |
ok 1599 - doc/Type/Hash.pod6 chunk 15 compiles | |
# my %vowels = 'a' => 1, 'e' => 2, 'i' => 3, 'o' => 4, 'u' => 5; | |
# for %vowels.sort(*.key)>>.kv -> ($vowel, $index) { | |
# "$vowel: $index".say; | |
# } | |
ok 1600 - doc/Type/Hash.pod6 chunk 16 compiles | |
# my %vowels = 'a' => 1, 'e' => 2, 'i' => 3, 'o' => 4, 'u' => 5; | |
# for %vowels.sort(*.key)>>.kv.flat -> $vowel, $index { | |
# "$vowel: $index".say; | |
# } | |
ok 1601 - doc/Type/Hash.pod6 chunk 17 compiles | |
# my %intervals{Instant}; | |
# my $first-instant = now; | |
# %intervals{ $first-instant } = "Our first milestone."; | |
# sleep 1; | |
# my $second-instant = now; | |
# %intervals{ $second-instant } = "Logging this Instant for spurious raisins."; | |
# for %intervals.sort -> (:$key, :$value) { | |
# state $last-instant //= $key; | |
# say "We noted '$value' at $key, with an interval of {$key - $last-instant}"; | |
# $last-instant = $key; | |
# } | |
ok 1602 - doc/Type/Hash.pod6 chunk 18 compiles | |
# my %intervals{Instant}; | |
# my $first-instant = now; | |
# %intervals{ $first-instant } = "Our first milestone."; | |
# sleep 1; | |
# my $second-instant = now; | |
# %intervals{ $second-instant } = "Logging this Instant for spurious raisins."; | |
# say ($first-instant, $second-instant) ~~ %intervals.keys; # OUTPUT: «False» | |
# say ($first-instant, $second-instant) ~~ %intervals.keys.sort; # OUTPUT: «True» | |
# say ($first-instant, $second-instant) === %intervals.keys.sort; # OUTPUT: «False» | |
# say $first-instant === %intervals.keys.sort[0]; # OUTPUT: «True» | |
ok 1603 - doc/Type/Hash.pod6 chunk 19 compiles | |
# my %h{Any}; | |
# %h{(now)} = "This is an Instant"; | |
# %h{(DateTime.now)} = "This is a DateTime, which is not an Instant"; | |
# %h{"completely different"} = "Monty Python references are neither DateTimes nor Instants"; | |
ok 1604 - doc/Type/Hash.pod6 chunk 20 compiles | |
# my %h := :{ (now) => "Instant", (DateTime.now) => "DateTime" }; | |
ok 1605 - doc/Type/Hash.pod6 chunk 21 compiles | |
# my %answers = illuminatus => 23, hitchhikers => 42; | |
# # OUTPUT: «hitchhikers => 42, illuminatus => 23» | |
# for %answers.values -> $v { $v += 10 }; # Fails | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::AdHoc: Cannot assign to a readonly variable or a value» | |
ok 1606 - doc/Type/Hash.pod6 chunk 22 compiles | |
# my %answers = illuminatus => 23, hitchhikers => 42; | |
# for %answers.kv -> $k,$v { %answers{$k} = $v + 10 }; | |
ok 1607 - doc/Type/Hash.pod6 chunk 23 compiles | |
# my %answers = illuminatus => 23, hitchhikers => 42; | |
# for %answers.values -> $v is rw { $v += 10 }; | |
ok 1608 - doc/Type/Hash.pod6 chunk 24 compiles | |
# multi method classify-list(&mapper, *@list, :&as --> Hash:D) | |
# multi method classify-list(%mapper, *@list, :&as --> Hash:D) | |
# multi method classify-list(@mapper, *@list, :&as --> Hash:D) | |
ok 1609 - doc/Type/Hash.pod6 chunk 25 compiles | |
# say % .classify-list: { $_ %% 2 ?? 'even' !! 'odd' }, ^10; | |
# # OUTPUT: «{even => [0 2 4 6 8], odd => [1 3 5 7 9]}» | |
# my @mapper = <zero one two three four five>; | |
# my %hash = foo => 'bar'; | |
# say %hash.classify-list: @mapper, 1, 2, 3, 4, 4; | |
# # OUTPUT: «{foo => bar, four => [4 4], one => [1], three => [3], two => [2]}» | |
ok 1610 - doc/Type/Hash.pod6 chunk 26 compiles | |
# say % .classify-list: { | |
# [ | |
# (.is-prime ?? 'prime' !! 'non-prime'), | |
# ($_ %% 2 ?? 'even' !! 'odd' ), | |
# ] | |
# }, ^10; | |
# # OUTPUT: | |
# # { | |
# # non-prime => { | |
# # even => [0 4 6 8], | |
# # odd => [1 9] | |
# # }, | |
# # prime => { | |
# # even => [2], | |
# # odd => [3 5 7] | |
# # } | |
# # } | |
ok 1611 - doc/Type/Hash.pod6 chunk 27 compiles | |
# say % .classify-list: :as{"Value is $_"}, { $_ %% 2 ?? 'even' !! 'odd' }, ^5; | |
# # OUTPUT (slightly altered manually, for clarity): | |
# # { | |
# # even => ['Value is 0', 'Value is 2', 'Value is 4'], | |
# # odd => ['Value is 1', 'Value is 3'] | |
# # } | |
ok 1612 - doc/Type/Hash.pod6 chunk 28 compiles | |
# multi method categorize-list(&mapper, *@list, :&as --> Hash:D) | |
# multi method categorize-list(%mapper, *@list, :&as --> Hash:D) | |
# multi method categorize-list(@mapper, *@list, :&as --> Hash:D) | |
ok 1613 - doc/Type/Hash.pod6 chunk 29 compiles | |
# say % .categorize-list: { | |
# gather { | |
# take 'prime' if .is-prime; | |
# take 'largish' if $_ > 5; | |
# take $_ %% 2 ?? 'even' !! 'odd'; | |
# } | |
# }, ^10; | |
# # OUTPUT: | |
# # { | |
# # prime => [2 3 5 7] | |
# # even => [0 2 4 6 8], | |
# # odd => [1 3 5 7 9], | |
# # largish => [6 7 8 9], | |
# # } | |
ok 1614 - doc/Type/Hash.pod6 chunk 30 compiles | |
# say % .categorize-list: { | |
# [ | |
# $_ > 5 ?? 'largish' !! 'smallish', | |
# .is-prime ?? 'prime' !! 'non-prime', | |
# ], | |
# }, ^10; | |
# # OUTPUT: | |
# # { | |
# # largish => { | |
# # non-prime => [6 8 9], | |
# # prime => [7] | |
# # }, | |
# # smallish => { | |
# # non-prime => [0 1 4], | |
# # prime => [2 3 5] | |
# # } | |
# # } | |
ok 1615 - doc/Type/Hash.pod6 chunk 31 compiles | |
# say % .categorize-list: :as{"Value is $_"}, { $_ %% 2 ?? 'even' !! 'odd' }, ^5; | |
# # OUTPUT (slightly altered manually, for clarity): | |
# # { | |
# # even => ['Value is 0', 'Value is 2', 'Value is 4'], | |
# # odd => ['Value is 1', 'Value is 3'] | |
# # } | |
ok 1616 - doc/Type/Hash.pod6 chunk 32 compiles | |
# multi method push(Hash:D: *@new) | |
ok 1617 - doc/Type/Hash.pod6 chunk 33 compiles | |
# my %h = a => 1; | |
# %h.push: (a => 1); # a => [1,1] | |
# %h.push: (a => 1) xx 3 ; # a => [1,1,1,1,1] | |
# %h.push: (b => 3); # a => [1,1,1,1,1], b => 3 | |
# %h.push('c' => 4); # a => [1,1,1,1,1], b => 3, c => 4 | |
# push %h, 'd' => 5; # a => [1,1,1,1,1], b => 3, c => 4, d => 5 | |
ok 1618 - doc/Type/Hash.pod6 chunk 34 compiles | |
# my %h .= push(e => 6); | |
# push %h, f => 7; | |
# say %h.perl; | |
# # OUTPUT: «{}» | |
ok 1619 - doc/Type/Hash.pod6 chunk 35 compiles | |
# my %wc = 'hash' => 323, 'pair' => 322, 'pipe' => 323; | |
# (my %inv).push: %wc.invert.unique; | |
# say %inv; # OUTPUT: «{322 => pair, 323 => [pipe hash]}» | |
ok 1620 - doc/Type/Hash.pod6 chunk 36 compiles | |
# my %wc = 'hash' => 323, 'pair' => 322, 'pipe' => 323; | |
# my %inv .= push: %wc.invert.unique; | |
ok 1621 - doc/Type/Hash.pod6 chunk 37 compiles | |
# my %ha = :a[42, ]; %ha.push: "a" => <a b c a>; | |
# say %ha; # OUTPUT: «{a => [42 (a b c a)]}» | |
# my %hb = :a[42, ]; %hb.append: "a" => <a b c a>; | |
# say %hb; # OUTPUT: «{a => [42 a b c a]}» | |
ok 1622 - doc/Type/Hash.pod6 chunk 38 compiles | |
# method append(+@values) | |
ok 1623 - doc/Type/Hash.pod6 chunk 39 compiles | |
# my %h = a => 1; | |
# %h.append('b', 2, 'c', 3); | |
# %h.append({d => 4}); | |
# say %h; | |
# # OUTPUT: «{a => 1, b => 2, c => 3, d => 4}» | |
# %h.append('a', 2); | |
# # OUTPUT: «{{a => [1 2], b => 2, c => 3, d => 4}» | |
ok 1624 - doc/Type/Hash.pod6 chunk 40 compiles | |
# my %hb = :a[42, ]; %hb.append: "a" => <a b c a>; | |
# say %hb; # OUTPUT: «{a => [42 a b c a]}» | |
# my %ha = :a[42, ]; %ha.push: "a" => <a b c a>; | |
# say %ha; # OUTPUT: «{a => [42 (a b c a)]}» | |
ok 1625 - doc/Type/Hash.pod6 chunk 41 compiles | |
# method default() | |
ok 1626 - doc/Type/Hash.pod6 chunk 42 compiles | |
# my %h1 = 'apples' => 3, 'oranges' => 7; | |
# say %h1.default; # OUTPUT: «(Any)» | |
# say %h1{'bananas'}; # OUTPUT: «(Any)» | |
# my %h2 is default(1) = 'apples' => 3, 'oranges' => 7; | |
# say %h2.default; # OUTPUT: «1» | |
# say %h2{'apples'} + %h2{'bananas'}; # OUTPUT: «4» | |
ok 1627 - doc/Type/Hash.pod6 chunk 43 compiles | |
# method keyof() | |
ok 1628 - doc/Type/Hash.pod6 chunk 44 compiles | |
# my %h1 = 'apples' => 3, 'oranges' => 7; # (no key type specified) | |
# say %h1.keyof; # OUTPUT: «(Str(Any))» | |
# my %h2{Str} = 'oranges' => 7; # (keys must be of type Str) | |
# say %h2.keyof; # (Str) | |
# %h2{3} = 'apples'; # throws exception | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::TypeCheck::Binding: Type check failed in binding to key; expected Str but got Int (3)» | |
ok 1629 - doc/Type/Hash.pod6 chunk 45 compiles | |
# method of() | |
ok 1630 - doc/Type/Hash.pod6 chunk 46 compiles | |
# my %h1 = 'apples' => 3, 'oranges' => 7; # (no type constraint specified) | |
# say %h1.of; # OUTPUT: «(Mu)» | |
# my Int %h2 = 'oranges' => 7; # (values must be of type Int) | |
# say %h2.of; # OUTPUT: «(Int)» | |
ok 1631 - doc/Type/Hash.pod6 chunk 47 compiles | |
# my %h = a => 1, b => 2; | |
# say %h<a>:exists; # OUTPUT: «True» | |
# say %h<a b>:exists; # OUTPUT: «(True True)» | |
ok 1632 - doc/Type/Hash.pod6 chunk 48 compiles | |
# my %h = a => 1; | |
# dd %h; # Hash %h = {:a(1)} | |
# %h<a>:delete; | |
# dd %h; # Hash %h = {} | |
ok 1633 - doc/Type/Hash.pod6 chunk 49 compiles | |
# my %h = a => 1, b => 2; | |
# say %h<a>:p; # OUTPUT: «a => 1» | |
# say %h<a b>:p; # OUTPUT: «(a => 1 b=> 2)» | |
ok 1634 - doc/Type/Hash.pod6 chunk 50 compiles | |
# my %h = a => 1, b => 2; | |
# say %h<a>:k; # OUTPUT: «a» | |
# say %h<a b>:k; # OUTPUT: «(a b)» | |
ok 1635 - doc/Type/Hash.pod6 chunk 51 compiles | |
# my %h1 = a => 1; | |
# my %h2 = a => 1, b => 2; | |
# say %h1<>:k; # OUTPUT: «(a)» | |
# say %h1<>:v; # OUTPUT: «(1)» | |
# say %h2<>:k; # OUTPUT: «(a b)» | |
# say %h2<>:v; # OUTPUT: «(1 2)» | |
ok 1636 - doc/Type/Hash.pod6 chunk 52 compiles | |
# role IO { } | |
ok 1637 - doc/Type/IO.pod6 chunk 1 compiles | |
# print "Hi there!\n"; # Hi there! | |
ok 1638 - doc/Type/IO.pod6 chunk 2 compiles | |
# print "Hi there!"; | |
# print "How are you?"; | |
# print (0..101).list; | |
ok 1639 - doc/Type/IO.pod6 chunk 3 compiles | |
# put 'Merry 1.0!'; | |
# put (0..101).list; | |
ok 1640 - doc/Type/IO.pod6 chunk 4 compiles | |
# say "Hi there!"; | |
# say "How are you?"; | |
# say (0..101).list; | |
ok 1641 - doc/Type/IO.pod6 chunk 5 compiles | |
# my @array = qw{1 2 3 4}; | |
# say @array; # OUTPUT: «[1 2 3 4]» | |
# say @array.gist; # OUTPUT: «[1 2 3 4]» | |
# my %hash = "a" => 1, "b" => 2, "c" => 3; | |
# say %hash; # OUTPUT: «{a => 1, b => 2, c => 3}» | |
# say %hash.gist; # OUTPUT: «{a => 1, b => 2, c => 3}» | |
ok 1642 - doc/Type/IO.pod6 chunk 6 compiles | |
# if ("path/to/pirate/treasure".IO.e) { | |
# say "Found pirate treasure!"; | |
# } | |
# else { | |
# note "Could not find pirate treasure. Are you sure it exists?"; | |
# } | |
ok 1643 - doc/Type/IO.pod6 chunk 7 compiles | |
# sub prompt($msg) | |
ok 1644 - doc/Type/IO.pod6 chunk 8 compiles | |
# my $fh = open("test"); # the file "test" already exists | |
# $fh.print("new text\n"); # fails | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::AdHoc: Failed to write bytes to filehandle: bad file descriptor» | |
ok 1645 - doc/Type/IO.pod6 chunk 9 compiles | |
# my $fh = open("path-to-file", :w); | |
ok 1646 - doc/Type/IO.pod6 chunk 10 compiles | |
# my $fh = open("test", :w); | |
# $fh.print("stuff\n"); | |
# $fh.print("more stuff\n"); | |
# $fh.seek(0); # return to the start of the file | |
# $fh.get(); # fails | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «Reading from filehandle failed: bad file descriptor» | |
ok 1647 - doc/Type/IO.pod6 chunk 11 compiles | |
# my $fh = open("path-to-file", :rw); | |
ok 1648 - doc/Type/IO.pod6 chunk 12 compiles | |
# my $fh = open("path-to-file", :a); | |
ok 1649 - doc/Type/IO.pod6 chunk 13 compiles | |
# my $fh = open("path-to-file", :bin); | |
ok 1650 - doc/Type/IO.pod6 chunk 14 compiles | |
Potential difficulties: | |
Redeclaration of symbol '$fh' | |
at /Users/williamcoleda/sandbox/doc/EVAL_1653:4 | |
------> [32mmy $fh[33m⏏[31m = open("path-to-file", enc => "utf-8");[0m | |
Redeclaration of symbol '$fh' | |
at /Users/williamcoleda/sandbox/doc/EVAL_1653:6 | |
------> [32mmy $fh[33m⏏[31m = open("path-to-file", enc => "latin1")[0m | |
# # open explicitly as utf8 | |
# my $fh = open("path-to-file", enc => "utf8"); | |
# my $fh = open("path-to-file", enc => "utf-8"); # this form also works | |
# # open with latin1 encoding | |
# my $fh = open("path-to-file", enc => "latin1"); | |
ok 1651 - doc/Type/IO.pod6 chunk 15 compiles | |
# # explicitly use CR-LF as EOL character | |
# my $fh = open("path-to-file", nl-in => "\r\n"); | |
ok 1652 - doc/Type/IO.pod6 chunk 16 compiles | |
# # don't remove newline characters from input | |
# my $fh = open("path-to-file", chomp => False); | |
# say $fh.get(); # returns line including newline char | |
ok 1653 - doc/Type/IO.pod6 chunk 17 compiles | |
# my $fh = open("path-to-file"); | |
# # ... do stuff with the file | |
# $fh.close; | |
ok 1654 - doc/Type/IO.pod6 chunk 18 compiles | |
# my $fh = open("path-to-file"); | |
# # ... do stuff with the file | |
# close $fh; | |
ok 1655 - doc/Type/IO.pod6 chunk 19 compiles | |
# # read entire file as (Unicode) Str | |
# #my $text_contents = slurp "path-to-file"; | |
# # read entire file as Latin1 Str | |
# #my $text_contents = slurp "path-to-file", enc => "latin1"; | |
# # read entire file as Buf | |
# #my $binary_contents = slurp "path-to-file", :bin; | |
ok 1656 - doc/Type/IO.pod6 chunk 20 compiles | |
# # write directly to a file | |
# #spurt "path/to/file", "default text, directly written"; | |
# # write directly with a non-Unicode encoding | |
# #spurt "path/to/latin1_file", "latin1 text: äöüß", enc => "latin1"; | |
# # append to a pre-existing file | |
# #spurt "file_already_exists", "some text"; | |
# #spurt "file_already_exists", "new text", :append; | |
# #slurp "file_already_exists"; # some textnew text | |
# # fail when writing to a pre-existing file | |
# #spurt "file_already_exists", "new text", :createonly; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Cannot::Empty: Cannot pop from an empty Array» | |
ok 1657 - doc/Type/IO.pod6 chunk 21 compiles | |
# sub run(*@args ($, *@) --> Proc) | |
ok 1658 - doc/Type/IO.pod6 chunk 22 compiles | |
# run ‚touch‘, ‚>foo.txt‘; # no shell redirect (as there is no shell) | |
# shell ‚ls \>*‘; # the shell would redirect, hence the backslash | |
# # and the glob is expanded | |
# run Q:w{rm >foo.txt}; # again no redirect but with a list word quote | |
# # OUTPUT: «>foo.txt» | |
ok 1659 - doc/Type/IO.pod6 chunk 23 compiles | |
# sub shell($cmd --> Proc) | |
ok 1660 - doc/Type/IO.pod6 chunk 24 compiles | |
# shell 'ls -lR | gzip -9 > ls-lR.gz'; | |
ok 1661 - doc/Type/IO.pod6 chunk 25 compiles | |
# class IO::ArgFiles is IO::Handle { } | |
ok 1662 - doc/Type/IO/ArgFiles.pod6 chunk 1 compiles | |
# use v6.c; | |
# my $argfiles = IO::ArgFiles.new(args => @*ARGS); | |
# .say for $argfiles.lines; | |
ok 1663 - doc/Type/IO/ArgFiles.pod6 chunk 2 compiles | |
# use v6.c; | |
# my $argfiles = IO::ArgFiles.new(args => @*ARGS); | |
# while ! $argfiles.eof { | |
# say $argfiles.get; | |
# } | |
ok 1664 - doc/Type/IO/ArgFiles.pod6 chunk 3 compiles | |
# use v6.c; | |
# my $argfiles = IO::ArgFiles.new(args => @*ARGS); | |
# say $argfiles.slurp; | |
ok 1665 - doc/Type/IO/ArgFiles.pod6 chunk 4 compiles | |
# use v6.c; | |
# .say for $*ARGFILES.lines; | |
# # or | |
# while ! $*ARGFILES.eof { | |
# say $*ARGFILES.get; | |
# } | |
# # or | |
# say $*ARGFILES.slurp; | |
ok 1666 - doc/Type/IO/ArgFiles.pod6 chunk 5 compiles | |
# class IO::Handle does IO { } | |
ok 1667 - doc/Type/IO/Handle.pod6 chunk 1 compiles | |
# method e(--> Bool) | |
ok 1668 - doc/Type/IO/Handle.pod6 chunk 2 compiles | |
# method d(--> Bool) | |
ok 1669 - doc/Type/IO/Handle.pod6 chunk 3 compiles | |
# method f(--> Bool) | |
ok 1670 - doc/Type/IO/Handle.pod6 chunk 4 compiles | |
# method s(--> Bool) | |
ok 1671 - doc/Type/IO/Handle.pod6 chunk 5 compiles | |
# method l(--> Bool) | |
ok 1672 - doc/Type/IO/Handle.pod6 chunk 6 compiles | |
# method r(--> Bool) | |
ok 1673 - doc/Type/IO/Handle.pod6 chunk 7 compiles | |
# method w(--> Bool) | |
ok 1674 - doc/Type/IO/Handle.pod6 chunk 8 compiles | |
# method rw(--> Bool) | |
ok 1675 - doc/Type/IO/Handle.pod6 chunk 9 compiles | |
# method x(--> Bool) | |
ok 1676 - doc/Type/IO/Handle.pod6 chunk 10 compiles | |
# method rwx(--> Bool) | |
ok 1677 - doc/Type/IO/Handle.pod6 chunk 11 compiles | |
# method z(--> Bool) | |
ok 1678 - doc/Type/IO/Handle.pod6 chunk 12 compiles | |
# method lines($limit = Inf) | |
ok 1679 - doc/Type/IO/Handle.pod6 chunk 13 compiles | |
# method words($count = Inf) | |
ok 1680 - doc/Type/IO/Handle.pod6 chunk 14 compiles | |
# multi method split(IO::Handle:D: :$close = False, :$COMB) | |
# multi method split(IO::Handle:D: $splitter, :$close = False, :$COMB) | |
ok 1681 - doc/Type/IO/Handle.pod6 chunk 15 compiles | |
# multi method comb(IO::Handle:D: :$close = False) | |
# multi method comb(IO::Handle:D: Int:D $size, :$close = False) | |
# multi method comb(IO::Handle:D: $comber, :$close = False) | |
ok 1682 - doc/Type/IO/Handle.pod6 chunk 16 compiles | |
# method print(*@text --> Bool) | |
ok 1683 - doc/Type/IO/Handle.pod6 chunk 17 compiles | |
# method print-nl(IO::Handle:D: --> True) | |
ok 1684 - doc/Type/IO/Handle.pod6 chunk 18 compiles | |
# method printf(IO::Handle:D: Cool $format, *@args) | |
ok 1685 - doc/Type/IO/Handle.pod6 chunk 19 compiles | |
# method say(IO::Handle:D: |) | |
ok 1686 - doc/Type/IO/Handle.pod6 chunk 20 compiles | |
# method read(IO::Handle:D: Int(Cool:D) $bytes --> Blob) | |
ok 1687 - doc/Type/IO/Handle.pod6 chunk 21 compiles | |
# method readchars(IO::Handle:D: Int(Cool:D) $chars --> Str) | |
ok 1688 - doc/Type/IO/Handle.pod6 chunk 22 compiles | |
# method write(IO::Handle:D: Blob:D $buf) | |
ok 1689 - doc/Type/IO/Handle.pod6 chunk 23 compiles | |
# method seek(IO::Handle:D: Int:D $offset, SeekType:D $whence --> True) | |
ok 1690 - doc/Type/IO/Handle.pod6 chunk 24 compiles | |
# method tell(IO::Handle:D: --> Int) | |
ok 1691 - doc/Type/IO/Handle.pod6 chunk 25 compiles | |
# multi method slurp-rest(IO::Handle:D: :$bin! --> Buf) | |
# multi method slurp-rest(IO::Handle:D: :$enc --> Str) | |
ok 1692 - doc/Type/IO/Handle.pod6 chunk 26 compiles | |
# multi method Supply(IO::Handle:D: :$size = 65536, :$bin --> Supply) | |
ok 1693 - doc/Type/IO/Handle.pod6 chunk 27 compiles | |
# method native-descriptor() | |
ok 1694 - doc/Type/IO/Handle.pod6 chunk 28 compiles | |
# method opened(IO::Handle:D: --> Bool) | |
ok 1695 - doc/Type/IO/Handle.pod6 chunk 29 compiles | |
# method t(IO::Handle:D: --> Bool) | |
ok 1696 - doc/Type/IO/Handle.pod6 chunk 30 compiles | |
# multi method new(Str:D $path) | |
# multi method new(:$basename!, :$dirname = '.', :$volume = '') | |
ok 1697 - doc/Type/IO/Path.pod6 chunk 1 compiles | |
# method abspath(IO::Path:D: --> Str) | |
ok 1698 - doc/Type/IO/Path.pod6 chunk 2 compiles | |
# method basename(IO::Path:D:) | |
ok 1699 - doc/Type/IO/Path.pod6 chunk 3 compiles | |
# say IO::Path.new("docs/README.pod").basename; # OUTPUT: «README.pod» | |
ok 1700 - doc/Type/IO/Path.pod6 chunk 4 compiles | |
# method extension(IO::Path:D:) | |
ok 1701 - doc/Type/IO/Path.pod6 chunk 5 compiles | |
# say IO::Path.new("docs/README.pod").extension; # OUTPUT: «pod» | |
ok 1702 - doc/Type/IO/Path.pod6 chunk 6 compiles | |
# method dirname(IO::Path:D:) | |
ok 1703 - doc/Type/IO/Path.pod6 chunk 7 compiles | |
# say IO::Path.new("/home/camelia/myfile.p6").dirname; # OUTPUT: «/home/camelia» | |
# say IO::Path.new("/home/camelia").dirname; # OUTPUT: «/home» | |
# say IO::Path.new("/home").dirname; # OUTPUT: «/» | |
ok 1704 - doc/Type/IO/Path.pod6 chunk 8 compiles | |
# method volume(IO::Path:D:) | |
ok 1705 - doc/Type/IO/Path.pod6 chunk 9 compiles | |
# say IO::Path::Win32.new("C:\\Windows\\registry.ini").volume; # OUTPUT: «C:» | |
ok 1706 - doc/Type/IO/Path.pod6 chunk 10 compiles | |
# method parts(IO::Path:D: --> Hash) | |
ok 1707 - doc/Type/IO/Path.pod6 chunk 11 compiles | |
# say IO::Path.new("/etc/passwd").parts.perl; | |
# # OUTPUT: «{:basename("passwd"), :directory("/etc"), :dirname("/etc"), :volume("")}» | |
ok 1708 - doc/Type/IO/Path.pod6 chunk 12 compiles | |
# method path(IO::Path:D: --> Str) | |
ok 1709 - doc/Type/IO/Path.pod6 chunk 13 compiles | |
# method Str(IO::Path:D:) | |
ok 1710 - doc/Type/IO/Path.pod6 chunk 14 compiles | |
# say IO::Path.new(basename => "foo", dirname => "/bar").Str; # OUTPUT: «/bar/foo» | |
# say IO::Path.new("/bar/foo").Str; # OUTPUT: «/bar/foo» | |
ok 1711 - doc/Type/IO/Path.pod6 chunk 15 compiles | |
# method open(IO::Path:D: *%opts) | |
ok 1712 - doc/Type/IO/Path.pod6 chunk 16 compiles | |
# method watch(IO::Path:D: --> Supply) | |
ok 1713 - doc/Type/IO/Path.pod6 chunk 17 compiles | |
# method is-absolute(IO::Path:D: --> Bool) | |
ok 1714 - doc/Type/IO/Path.pod6 chunk 18 compiles | |
# method is-relative(IO::Path:D: --> Bool) | |
ok 1715 - doc/Type/IO/Path.pod6 chunk 19 compiles | |
# method absolute(IO::Path:D: $base = ~$*CWD --> Str) | |
ok 1716 - doc/Type/IO/Path.pod6 chunk 20 compiles | |
# method relative(IO::Path:D: $base = ~$*CWD --> Str) | |
ok 1717 - doc/Type/IO/Path.pod6 chunk 21 compiles | |
# method parent(IO::Path:D: --> IO::Path) | |
ok 1718 - doc/Type/IO/Path.pod6 chunk 22 compiles | |
# my $io = IO::Path.new( "/etc/passwd" ); | |
# say $io.parent; # OUTPUT: «"/etc".IO» | |
ok 1719 - doc/Type/IO/Path.pod6 chunk 23 compiles | |
# method child(IO::Path:D: $childname --> IO::Path) | |
ok 1720 - doc/Type/IO/Path.pod6 chunk 24 compiles | |
# my $io = IO::Path.new( "/bin" ); | |
# say $io.child('netstat'); # OUTPUT: «"/bin/netstat".IO» | |
ok 1721 - doc/Type/IO/Path.pod6 chunk 25 compiles | |
# method resolve(IO::Path:D: --> IO::Path) | |
ok 1722 - doc/Type/IO/Path.pod6 chunk 26 compiles | |
# # bar is a symlink pointing to "/baz" | |
# my $io = "foo/./bar/..".IO.resolve; # now "/" (the parent of "/baz") | |
ok 1723 - doc/Type/IO/Path.pod6 chunk 27 compiles | |
# sub dir(Cool $path = '.', Mu :$test = none('.', '..')) | |
# method dir(IO::Path:D: Mu :$test = none('.', '..')) | |
ok 1724 - doc/Type/IO/Path.pod6 chunk 28 compiles | |
# # To iterate over the contents of the current directory: | |
# for dir() -> $file { | |
# say $file; | |
# } | |
# # As before, but include even '.' and '..' which are filtered out by | |
# # the default :test matcher: | |
# for dir(test => *) -> $file { | |
# say $file; | |
# } | |
# # To get the names of all .jpg and .jpeg files in ~/Downloads: | |
ok 1725 - doc/Type/IO/Path.pod6 chunk 29 compiles | |
# sub MAIN($dir = '.') { | |
# my @todo = $dir.IO; | |
# while @todo { | |
# for @todo.pop.dir -> $path { | |
# say $path.Str; | |
# @todo.push: $path if $path.d; | |
# } | |
# } | |
# } | |
ok 1726 - doc/Type/IO/Path.pod6 chunk 30 compiles | |
# method e(--> Bool) | |
ok 1727 - doc/Type/IO/Path.pod6 chunk 31 compiles | |
# method d(--> Bool) | |
ok 1728 - doc/Type/IO/Path.pod6 chunk 32 compiles | |
# method f(--> Bool) | |
ok 1729 - doc/Type/IO/Path.pod6 chunk 33 compiles | |
# method s(--> Int) | |
ok 1730 - doc/Type/IO/Path.pod6 chunk 34 compiles | |
# method l(--> Bool) | |
ok 1731 - doc/Type/IO/Path.pod6 chunk 35 compiles | |
# method r(--> Bool) | |
ok 1732 - doc/Type/IO/Path.pod6 chunk 36 compiles | |
# method w(--> Bool) | |
ok 1733 - doc/Type/IO/Path.pod6 chunk 37 compiles | |
# method rw(--> Bool) | |
ok 1734 - doc/Type/IO/Path.pod6 chunk 38 compiles | |
# method x(--> Bool) | |
ok 1735 - doc/Type/IO/Path.pod6 chunk 39 compiles | |
# method rwx(--> Bool) | |
ok 1736 - doc/Type/IO/Path.pod6 chunk 40 compiles | |
# method z(--> Bool) | |
ok 1737 - doc/Type/IO/Path.pod6 chunk 41 compiles | |
# multi method slurp(IO::Path:D: :$bin, :$enc) | |
ok 1738 - doc/Type/IO/Path.pod6 chunk 42 compiles | |
# multi method spurt(IO::Path:D: Blob $contents, :$bin, |c) | |
# multi method spurt(IO::Path:D: Cool $contents, :$bin, |c) | |
ok 1739 - doc/Type/IO/Path.pod6 chunk 43 compiles | |
# sub chdir(Str() $path, :$test = 'r' --> IO::Path) | |
# multi method chdir(IO::Path:U: $path, :$test = 'r' --> IO::Path) | |
# multi method chdir(IO::Path:D: Str() $path is copy, :$test = 'r' --> IO::Path) | |
ok 1740 - doc/Type/IO/Path.pod6 chunk 44 compiles | |
# multi sub mkdir(Int:D $mode, *@dirnames --> List) | |
# multi sub mkdir($path, $mode = 0o777 --> Bool) | |
# method mkdir(IO::Path:D: $mode = 0o777 --> Bool) | |
ok 1741 - doc/Type/IO/Path.pod6 chunk 45 compiles | |
# sub rmdir(IO $dir --> Bool) | |
# method rmdir(IO::Path:D: --> Bool) | |
ok 1742 - doc/Type/IO/Path.pod6 chunk 46 compiles | |
# # When we have a directory first recurse, then remove it | |
# multi sub rm-all(IO::Path $path where :d) { | |
# .&rm-all for $path.dir; | |
# rmdir($path) | |
# } | |
# # Otherwise just remove the thing directly | |
# multi sub rm-all(IO::Path $path) { $path.unlink } | |
ok 1743 - doc/Type/IO/Path.pod6 chunk 47 compiles | |
# sub chmod($mode, *@filenames --> List) | |
# method chmod(IO::Path:D: $mode --> Bool) | |
ok 1744 - doc/Type/IO/Path.pod6 chunk 48 compiles | |
# method rename(IO::Path:D: $to, :$createonly --> Bool) | |
# sub rename($from, $to, :$createonly --> Bool) | |
ok 1745 - doc/Type/IO/Path.pod6 chunk 49 compiles | |
# method copy(IO::Path:D: $to, :$createonly) | |
# sub copy($from, $to, :$createonly) | |
ok 1746 - doc/Type/IO/Path.pod6 chunk 50 compiles | |
# method move(IO::Path:D: $to, :$createonly) | |
# sub move($from, $to, :$createonly) | |
ok 1747 - doc/Type/IO/Path.pod6 chunk 51 compiles | |
# method symlink(IO::Path:D: Str $name --> Bool) | |
# sub symlink(Str $target, Str $name --> Bool) | |
ok 1748 - doc/Type/IO/Path.pod6 chunk 52 compiles | |
# method link(IO::Path:D: Str $name --> Bool) | |
# sub link(Str $target, Str $name --> Bool) | |
ok 1749 - doc/Type/IO/Path.pod6 chunk 53 compiles | |
# method unlink(IO::Path:D: --> Bool) | |
# sub unlink(*@filenames --> List) | |
ok 1750 - doc/Type/IO/Path.pod6 chunk 54 compiles | |
# method IO(IO::Path:D: --> IO::Path) | |
ok 1751 - doc/Type/IO/Path.pod6 chunk 55 compiles | |
# method SPEC(IO::Path:D: --> IO::Spec) | |
ok 1752 - doc/Type/IO/Path.pod6 chunk 56 compiles | |
# my $io = IO::Path.new("/bin/bash"); | |
# say $io.SPEC; # OUTPUT: «(Unix)» | |
# say $io.SPEC.dir-sep; # OUTPUT: «/» | |
ok 1753 - doc/Type/IO/Path.pod6 chunk 57 compiles | |
# if "path/to/directory".IO ~~ :e & :d { | |
# say 'path exists and points to a directory'; | |
# } | |
# my $file = "path/to/file"; | |
# if $file.IO ~~ :e { | |
# say 'file exists'; | |
# } | |
ok 1754 - doc/Type/IO/Path.pod6 chunk 58 compiles | |
# if 'path/to/file'.IO.e { | |
# say 'file exists'; | |
# } | |
ok 1755 - doc/Type/IO/Path.pod6 chunk 59 compiles | |
# my $path = "path/to/file".IO; | |
# given $path { | |
# when :f { say 'path is a file' } | |
# when :d { say 'path is a directory' } | |
# } | |
ok 1756 - doc/Type/IO/Path.pod6 chunk 60 compiles | |
# class IO::Pipe is IO::Handle {} | |
ok 1757 - doc/Type/IO/Pipe.pod6 chunk 1 compiles | |
# method close(IO::Pipe: --> Proc:D) | |
ok 1758 - doc/Type/IO/Pipe.pod6 chunk 2 compiles | |
# method proc(IO::Pipe: --> Proc:D) | |
ok 1759 - doc/Type/IO/Pipe.pod6 chunk 3 compiles | |
# role IO::Socket does IO { ... } | |
ok 1760 - doc/Type/IO/Socket.pod6 chunk 1 compiles | |
# method recv(IO::Socket:D: Cool $elems = Inf, :$bin) | |
ok 1761 - doc/Type/IO/Socket.pod6 chunk 2 compiles | |
# method read(IO::Socket:D: Int(Cool) $bytes) | |
ok 1762 - doc/Type/IO/Socket.pod6 chunk 3 compiles | |
# method print(IO::Socket:D: Str(Cool) $string) | |
ok 1763 - doc/Type/IO/Socket.pod6 chunk 4 compiles | |
# method write(IO::Socket:D: Blob:D $buf) | |
ok 1764 - doc/Type/IO/Socket.pod6 chunk 5 compiles | |
# method put(IO::Socket:D: Str(Cool) $string) | |
ok 1765 - doc/Type/IO/Socket.pod6 chunk 6 compiles | |
# method close(IO::Socket:D) | |
ok 1766 - doc/Type/IO/Socket.pod6 chunk 7 compiles | |
# method native-descriptor() | |
ok 1767 - doc/Type/IO/Socket.pod6 chunk 8 compiles | |
# class IO::Socket::Async {} | |
ok 1768 - doc/Type/IO/Socket/Async.pod6 chunk 1 compiles | |
# method connect(Str $host, Int $port --> Promise) | |
ok 1769 - doc/Type/IO/Socket/Async.pod6 chunk 2 compiles | |
# method listen(Str $host, Int $port --> Supply) | |
ok 1770 - doc/Type/IO/Socket/Async.pod6 chunk 3 compiles | |
# method udp(IO::Socket::Async:U: :$broadcast --> IO::Socket::Async) | |
ok 1771 - doc/Type/IO/Socket/Async.pod6 chunk 4 compiles | |
# method bind-udp(IO::Socket::Async:U: Str() $host, Int() $port, :$broadcast --> IO::Socket::Async) | |
ok 1772 - doc/Type/IO/Socket/Async.pod6 chunk 5 compiles | |
# method print(Str $str --> Promise) | |
ok 1773 - doc/Type/IO/Socket/Async.pod6 chunk 6 compiles | |
# method print-to(IO::Socket::Async:D: Str() $host, Int() $port, Str() $str --> Promise) | |
ok 1774 - doc/Type/IO/Socket/Async.pod6 chunk 7 compiles | |
# method write(Blob $b --> Promise) | |
ok 1775 - doc/Type/IO/Socket/Async.pod6 chunk 8 compiles | |
# method write-to(IO::Socket::Async:D: Str() $host, Int() $port, Blob $b --> Promise) | |
ok 1776 - doc/Type/IO/Socket/Async.pod6 chunk 9 compiles | |
# method Supply(:$bin, :$buf = buf8.new --> Supply) | |
ok 1777 - doc/Type/IO/Socket/Async.pod6 chunk 10 compiles | |
# method close() | |
ok 1778 - doc/Type/IO/Socket/Async.pod6 chunk 11 compiles | |
Use of uninitialized value of type Any in string context. | |
Methods .^name, .perl, .gist, or .say can be used to stringify it to something meaningful. | |
in any !cursor_pass at /Users/williamcoleda/.rakudobrew/moar-a63d82aa5162d2b9c30fdef5867252ac9d3e46cd/install/share/nqp/lib/QRegex.moarvm line 1 | |
# class IO::Socket::INET does IO::Socket {} | |
# No appropriate parametric role variant available for '<anon|140260489989024>::IO::Socket' | |
not ok 1779 - doc/Type/IO/Socket/INET.pod6 chunk 1 compiles | |
# Failed test 'doc/Type/IO/Socket/INET.pod6 chunk 1 compiles' | |
# at xt/examples-compilation.t line 93 | |
# method get() | |
ok 1780 - doc/Type/IO/Socket/INET.pod6 chunk 2 compiles | |
# method lines() | |
ok 1781 - doc/Type/IO/Socket/INET.pod6 chunk 3 compiles | |
# method accept() | |
ok 1782 - doc/Type/IO/Socket/INET.pod6 chunk 4 compiles | |
# class IO::Spec { } | |
ok 1783 - doc/Type/IO/Spec.pod6 chunk 1 compiles | |
# method canonpath(IO::Spec:D: Str $patharg, Str :$parent --> Str) | |
ok 1784 - doc/Type/IO/Spec.pod6 chunk 2 compiles | |
# method dir-sep(IO::Spec:D: --> Str) | |
ok 1785 - doc/Type/IO/Spec.pod6 chunk 3 compiles | |
# method curdir(IO::Spec:D: --> Str) | |
ok 1786 - doc/Type/IO/Spec.pod6 chunk 4 compiles | |
# method updir(IO::Spec:D: --> Str) | |
ok 1787 - doc/Type/IO/Spec.pod6 chunk 5 compiles | |
# method curupdir(IO::Spec:D: --> Junction) | |
ok 1788 - doc/Type/IO/Spec.pod6 chunk 6 compiles | |
# method rootdir(IO::Spec:D: --> Str) | |
ok 1789 - doc/Type/IO/Spec.pod6 chunk 7 compiles | |
# method devnull(IO::Spec:D: --> Str) | |
ok 1790 - doc/Type/IO/Spec.pod6 chunk 8 compiles | |
# method basename(IO::Spec:D: Str $path --> Str) | |
ok 1791 - doc/Type/IO/Spec.pod6 chunk 9 compiles | |
# method extension(IO::Spec:D: Str $path --> Str) | |
ok 1792 - doc/Type/IO/Spec.pod6 chunk 10 compiles | |
# method tmpdir(IO::Spec:D: --> IO::Path) | |
ok 1793 - doc/Type/IO/Spec.pod6 chunk 11 compiles | |
# method is-absolute(IO::Spec:D: Str $file --> Bool) | |
ok 1794 - doc/Type/IO/Spec.pod6 chunk 12 compiles | |
# method path(IO::Spec:D: --> Str) | |
ok 1795 - doc/Type/IO/Spec.pod6 chunk 13 compiles | |
# method splitpath(IO::Spec:D: Str $path, Bool :$nofile = False ) | |
ok 1796 - doc/Type/IO/Spec.pod6 chunk 14 compiles | |
# method split(IO::Spec:D: Cool:D $path is copy ) | |
ok 1797 - doc/Type/IO/Spec.pod6 chunk 15 compiles | |
# method join(IO::Spec:D: $, $dirname, $file) | |
ok 1798 - doc/Type/IO/Spec.pod6 chunk 16 compiles | |
# method catpath(IO::Spec:D: $, $dirname, $file ) | |
ok 1799 - doc/Type/IO/Spec.pod6 chunk 17 compiles | |
# method catdir(IO::Spec:D: *@parts ) | |
ok 1800 - doc/Type/IO/Spec.pod6 chunk 18 compiles | |
# method splitdir(IO::Spec:D: Str $path ) | |
ok 1801 - doc/Type/IO/Spec.pod6 chunk 19 compiles | |
# method catfile(IO::Spec:D: *@parts ) | |
ok 1802 - doc/Type/IO/Spec.pod6 chunk 20 compiles | |
# method abs2rel(IO::Spec:D: Str $path is copy, Str $base is copy = Str ) | |
ok 1803 - doc/Type/IO/Spec.pod6 chunk 21 compiles | |
# method rel2abs(IO::Spec:D: Str $path, Str $base? is copy) | |
ok 1804 - doc/Type/IO/Spec.pod6 chunk 22 compiles | |
# class IO::Spec::QNX is IO::Spec { } | |
ok 1805 - doc/Type/IO/Spec/Cygwin.pod6 chunk 1 compiles | |
# method canonpath(IO::Spec:D: Str $patharg, Str :$parent --> Str) | |
ok 1806 - doc/Type/IO/Spec/Cygwin.pod6 chunk 2 compiles | |
# method dir-sep(IO::Spec:D: --> Str) | |
ok 1807 - doc/Type/IO/Spec/Cygwin.pod6 chunk 3 compiles | |
# method curdir(IO::Spec:D: --> Str) | |
ok 1808 - doc/Type/IO/Spec/Cygwin.pod6 chunk 4 compiles | |
# method updir(IO::Spec:D: --> Str) | |
ok 1809 - doc/Type/IO/Spec/Cygwin.pod6 chunk 5 compiles | |
# method curupdir(IO::Spec:D: --> Junction) | |
ok 1810 - doc/Type/IO/Spec/Cygwin.pod6 chunk 6 compiles | |
# method rootdir(IO::Spec:D: --> Str) | |
ok 1811 - doc/Type/IO/Spec/Cygwin.pod6 chunk 7 compiles | |
# method devnull(IO::Spec:D: --> Str) | |
ok 1812 - doc/Type/IO/Spec/Cygwin.pod6 chunk 8 compiles | |
# method basename(IO::Spec:D: Str $path --> Str) | |
ok 1813 - doc/Type/IO/Spec/Cygwin.pod6 chunk 9 compiles | |
# method extension(IO::Spec:D: Str $path --> Str) | |
ok 1814 - doc/Type/IO/Spec/Cygwin.pod6 chunk 10 compiles | |
# method tmpdir(IO::Spec:D: --> IO::Path) | |
ok 1815 - doc/Type/IO/Spec/Cygwin.pod6 chunk 11 compiles | |
# method is-absolute(IO::Spec:D: Str $file --> Bool) | |
ok 1816 - doc/Type/IO/Spec/Cygwin.pod6 chunk 12 compiles | |
# method path(IO::Spec:D: --> Str) | |
ok 1817 - doc/Type/IO/Spec/Cygwin.pod6 chunk 13 compiles | |
# method splitpath(IO::Spec:D: Str $path, Bool :$nofile = False ) | |
ok 1818 - doc/Type/IO/Spec/Cygwin.pod6 chunk 14 compiles | |
# method split(IO::Spec:D: Cool:D $path is copy ) | |
ok 1819 - doc/Type/IO/Spec/Cygwin.pod6 chunk 15 compiles | |
# method join(IO::Spec:D: $, $dirname, $file) | |
ok 1820 - doc/Type/IO/Spec/Cygwin.pod6 chunk 16 compiles | |
# method catpath(IO::Spec:D: $, $dirname, $file ) | |
ok 1821 - doc/Type/IO/Spec/Cygwin.pod6 chunk 17 compiles | |
# method catdir(IO::Spec:D: *@parts ) | |
ok 1822 - doc/Type/IO/Spec/Cygwin.pod6 chunk 18 compiles | |
# method splitdir(IO::Spec:D: Str $path ) | |
ok 1823 - doc/Type/IO/Spec/Cygwin.pod6 chunk 19 compiles | |
# method catfile(IO::Spec:D: *@parts ) | |
ok 1824 - doc/Type/IO/Spec/Cygwin.pod6 chunk 20 compiles | |
# method abs2rel(IO::Spec:D: Str $path is copy, Str $base is copy = Str ) | |
ok 1825 - doc/Type/IO/Spec/Cygwin.pod6 chunk 21 compiles | |
# method rel2abs(IO::Spec:D $path, Str $base? is copy) | |
ok 1826 - doc/Type/IO/Spec/Cygwin.pod6 chunk 22 compiles | |
# class IO::Spec::QNX is IO::Spec { } | |
ok 1827 - doc/Type/IO/Spec/QNX.pod6 chunk 1 compiles | |
# method canonpath(IO::Spec:D: Str $patharg, Str :$parent --> Str) | |
ok 1828 - doc/Type/IO/Spec/QNX.pod6 chunk 2 compiles | |
# method dir-sep(IO::Spec:D: --> Str) | |
ok 1829 - doc/Type/IO/Spec/QNX.pod6 chunk 3 compiles | |
# method curdir(IO::Spec:D: --> Str) | |
ok 1830 - doc/Type/IO/Spec/QNX.pod6 chunk 4 compiles | |
# method updir(IO::Spec:D: --> Str) | |
ok 1831 - doc/Type/IO/Spec/QNX.pod6 chunk 5 compiles | |
# method curupdir(IO::Spec:D: --> Junction) | |
ok 1832 - doc/Type/IO/Spec/QNX.pod6 chunk 6 compiles | |
# method rootdir(IO::Spec:D: --> Str) | |
ok 1833 - doc/Type/IO/Spec/QNX.pod6 chunk 7 compiles | |
# method devnull(IO::Spec:D: --> Str) | |
ok 1834 - doc/Type/IO/Spec/QNX.pod6 chunk 8 compiles | |
# method basename(IO::Spec:D: Str $path --> Str) | |
ok 1835 - doc/Type/IO/Spec/QNX.pod6 chunk 9 compiles | |
# method extension(IO::Spec:D: Str $path --> Str) | |
ok 1836 - doc/Type/IO/Spec/QNX.pod6 chunk 10 compiles | |
# method tmpdir(IO::Spec:D: --> IO::Path) | |
ok 1837 - doc/Type/IO/Spec/QNX.pod6 chunk 11 compiles | |
# method is-absolute(IO::Spec:D: Str $file --> Bool) | |
ok 1838 - doc/Type/IO/Spec/QNX.pod6 chunk 12 compiles | |
# method path(IO::Spec:D: --> Str) | |
ok 1839 - doc/Type/IO/Spec/QNX.pod6 chunk 13 compiles | |
# method splitpath(IO::Spec:D: Str $path, Bool :$nofile = False ) | |
ok 1840 - doc/Type/IO/Spec/QNX.pod6 chunk 14 compiles | |
# method split(IO::Spec:D: Cool:D $path is copy ) | |
ok 1841 - doc/Type/IO/Spec/QNX.pod6 chunk 15 compiles | |
# method join(IO::Spec:D: $, $dirname, $file) | |
ok 1842 - doc/Type/IO/Spec/QNX.pod6 chunk 16 compiles | |
# method catpath(IO::Spec:D: $, $dirname, $file ) | |
ok 1843 - doc/Type/IO/Spec/QNX.pod6 chunk 17 compiles | |
# method catdir(IO::Spec:D: *@parts ) | |
ok 1844 - doc/Type/IO/Spec/QNX.pod6 chunk 18 compiles | |
# method splitdir(IO::Spec:D: Str $path ) | |
ok 1845 - doc/Type/IO/Spec/QNX.pod6 chunk 19 compiles | |
# method catfile(IO::Spec:D: *@parts ) | |
ok 1846 - doc/Type/IO/Spec/QNX.pod6 chunk 20 compiles | |
# method abs2rel(IO::Spec:D: Str $path is copy, Str $base is copy = Str ) | |
ok 1847 - doc/Type/IO/Spec/QNX.pod6 chunk 21 compiles | |
# method rel2abs(IO::Spec:D: Str $path, Str $base? is copy) | |
ok 1848 - doc/Type/IO/Spec/QNX.pod6 chunk 22 compiles | |
# class IO::Spec::Unix is IO::Spec { } | |
ok 1849 - doc/Type/IO/Spec/Unix.pod6 chunk 1 compiles | |
# method canonpath(IO::Spec:D: Str $patharg, Str :$parent --> Str) | |
ok 1850 - doc/Type/IO/Spec/Unix.pod6 chunk 2 compiles | |
# method dir-sep(IO::Spec:D: --> Str) | |
ok 1851 - doc/Type/IO/Spec/Unix.pod6 chunk 3 compiles | |
# method curdir(IO::Spec:D: --> Str) | |
ok 1852 - doc/Type/IO/Spec/Unix.pod6 chunk 4 compiles | |
# method updir(IO::Spec:D: --> Str) | |
ok 1853 - doc/Type/IO/Spec/Unix.pod6 chunk 5 compiles | |
# method curupdir(IO::Spec:D: --> Junction) | |
ok 1854 - doc/Type/IO/Spec/Unix.pod6 chunk 6 compiles | |
# method rootdir(IO::Spec:D: --> Str) | |
ok 1855 - doc/Type/IO/Spec/Unix.pod6 chunk 7 compiles | |
# method devnull(IO::Spec:D: --> Str) | |
ok 1856 - doc/Type/IO/Spec/Unix.pod6 chunk 8 compiles | |
# method basename(IO::Spec:D: Str $path --> Str) | |
ok 1857 - doc/Type/IO/Spec/Unix.pod6 chunk 9 compiles | |
# method extension(IO::Spec:D: Str $path --> Str) | |
ok 1858 - doc/Type/IO/Spec/Unix.pod6 chunk 10 compiles | |
# method tmpdir(IO::Spec:D: --> IO::Path) | |
ok 1859 - doc/Type/IO/Spec/Unix.pod6 chunk 11 compiles | |
# method is-absolute(IO::Spec:D: Str $file --> Bool) | |
ok 1860 - doc/Type/IO/Spec/Unix.pod6 chunk 12 compiles | |
# method path(IO::Spec:D: --> Str) | |
ok 1861 - doc/Type/IO/Spec/Unix.pod6 chunk 13 compiles | |
# method splitpath(IO::Spec:D: Str $path, Bool :$nofile = False ) | |
ok 1862 - doc/Type/IO/Spec/Unix.pod6 chunk 14 compiles | |
# method split(IO::Spec:D: Cool:D $path is copy ) | |
ok 1863 - doc/Type/IO/Spec/Unix.pod6 chunk 15 compiles | |
# method join(IO::Spec:D: $, $dirname, $file) | |
ok 1864 - doc/Type/IO/Spec/Unix.pod6 chunk 16 compiles | |
# method catpath(IO::Spec:D: $, $dirname, $file ) | |
ok 1865 - doc/Type/IO/Spec/Unix.pod6 chunk 17 compiles | |
# method catdir(IO::Spec:D: *@parts ) | |
ok 1866 - doc/Type/IO/Spec/Unix.pod6 chunk 18 compiles | |
# method splitdir(IO::Spec:D: Str $path ) | |
ok 1867 - doc/Type/IO/Spec/Unix.pod6 chunk 19 compiles | |
# method catfile(IO::Spec:D: *@parts ) | |
ok 1868 - doc/Type/IO/Spec/Unix.pod6 chunk 20 compiles | |
# method abs2rel(IO::Spec:D: Str $path is copy, Str $base is copy = Str ) | |
ok 1869 - doc/Type/IO/Spec/Unix.pod6 chunk 21 compiles | |
# method rel2abs(IO::Spec:D: Str $path, Str $base? is copy) | |
ok 1870 - doc/Type/IO/Spec/Unix.pod6 chunk 22 compiles | |
# class IO::Spec::Win32 is IO::Spec { } | |
ok 1871 - doc/Type/IO/Spec/Win32.pod6 chunk 1 compiles | |
# method canonpath(IO::Spec:D: Str $patharg, Str :$parent --> Str) | |
ok 1872 - doc/Type/IO/Spec/Win32.pod6 chunk 2 compiles | |
# method dir-sep(IO::Spec:D: --> Str) | |
ok 1873 - doc/Type/IO/Spec/Win32.pod6 chunk 3 compiles | |
# method curdir(IO::Spec:D: --> Str) | |
ok 1874 - doc/Type/IO/Spec/Win32.pod6 chunk 4 compiles | |
# method updir(IO::Spec:D: --> Str) | |
ok 1875 - doc/Type/IO/Spec/Win32.pod6 chunk 5 compiles | |
# method curupdir(IO::Spec:D: --> Junction) | |
ok 1876 - doc/Type/IO/Spec/Win32.pod6 chunk 6 compiles | |
# method rootdir(IO::Spec:D: --> Str) | |
ok 1877 - doc/Type/IO/Spec/Win32.pod6 chunk 7 compiles | |
# method devnull(IO::Spec:D: --> Str) | |
ok 1878 - doc/Type/IO/Spec/Win32.pod6 chunk 8 compiles | |
# method basename(IO::Spec:D: Str $path --> Str) | |
ok 1879 - doc/Type/IO/Spec/Win32.pod6 chunk 9 compiles | |
# method extension(IO::Spec:D: Str $path --> Str) | |
ok 1880 - doc/Type/IO/Spec/Win32.pod6 chunk 10 compiles | |
# method tmpdir(IO::Spec:D: --> IO::Path) | |
ok 1881 - doc/Type/IO/Spec/Win32.pod6 chunk 11 compiles | |
# method is-absolute(IO::Spec:D: Str $file --> Bool) | |
ok 1882 - doc/Type/IO/Spec/Win32.pod6 chunk 12 compiles | |
# method path(IO::Spec:D: --> Str) | |
ok 1883 - doc/Type/IO/Spec/Win32.pod6 chunk 13 compiles | |
# method splitpath(IO::Spec:D: Str $path, Bool :$nofile = False ) | |
ok 1884 - doc/Type/IO/Spec/Win32.pod6 chunk 14 compiles | |
# method split(IO::Spec:D: Cool:D $path is copy ) | |
ok 1885 - doc/Type/IO/Spec/Win32.pod6 chunk 15 compiles | |
# method join(IO::Spec:D: $, $dirname, $file) | |
ok 1886 - doc/Type/IO/Spec/Win32.pod6 chunk 16 compiles | |
# method catpath(IO::Spec:D: $, $dirname, $file ) | |
ok 1887 - doc/Type/IO/Spec/Win32.pod6 chunk 17 compiles | |
# method catdir(IO::Spec:D: *@parts ) | |
ok 1888 - doc/Type/IO/Spec/Win32.pod6 chunk 18 compiles | |
# method splitdir(IO::Spec:D: Str $path ) | |
ok 1889 - doc/Type/IO/Spec/Win32.pod6 chunk 19 compiles | |
# method catfile(IO::Spec:D: *@parts ) | |
ok 1890 - doc/Type/IO/Spec/Win32.pod6 chunk 20 compiles | |
# method abs2rel(IO::Spec:D: Str $path is copy, Str $base is copy = Str ) | |
ok 1891 - doc/Type/IO/Spec/Win32.pod6 chunk 21 compiles | |
# method rel2abs(IO::Spec:D: Str $path, Str $base? is copy) | |
ok 1892 - doc/Type/IO/Spec/Win32.pod6 chunk 22 compiles | |
# method WHICH(IO::Special:D: --> Str) | |
ok 1893 - doc/Type/IO/Special.pod6 chunk 1 compiles | |
# method Str(IO::Special:D:) | |
ok 1894 - doc/Type/IO/Special.pod6 chunk 2 compiles | |
# method IO(IO::Special:D: --> IO::Special) | |
ok 1895 - doc/Type/IO/Special.pod6 chunk 3 compiles | |
# method e(IO::Special:D: --> Bool) | |
ok 1896 - doc/Type/IO/Special.pod6 chunk 4 compiles | |
# method d(IO::Special:D: --> Bool) | |
ok 1897 - doc/Type/IO/Special.pod6 chunk 5 compiles | |
# method f(IO::Special:D: --> Bool) | |
ok 1898 - doc/Type/IO/Special.pod6 chunk 6 compiles | |
# method s(IO::Special:D: --> Int) | |
ok 1899 - doc/Type/IO/Special.pod6 chunk 7 compiles | |
# method l(IO::Special:D: --> Bool) | |
ok 1900 - doc/Type/IO/Special.pod6 chunk 8 compiles | |
# method r(IO::Special:D: --> Bool) | |
ok 1901 - doc/Type/IO/Special.pod6 chunk 9 compiles | |
# method w(IO::Special:D: --> Bool) | |
ok 1902 - doc/Type/IO/Special.pod6 chunk 10 compiles | |
# method x(IO::Special:D: --> Bool) | |
ok 1903 - doc/Type/IO/Special.pod6 chunk 11 compiles | |
# method modified(IO::Special:D: --> Instant) | |
ok 1904 - doc/Type/IO/Special.pod6 chunk 12 compiles | |
# method accessed(IO::Special:D: --> Instant) | |
ok 1905 - doc/Type/IO/Special.pod6 chunk 13 compiles | |
# method changed(IO::Special:D: --> Instant) | |
ok 1906 - doc/Type/IO/Special.pod6 chunk 14 compiles | |
# method mode(IO::Special:D: --> Nil) | |
ok 1907 - doc/Type/IO/Special.pod6 chunk 15 compiles | |
# class Instant is Cool does Real { } | |
ok 1908 - doc/Type/Instant.pod6 chunk 1 compiles | |
# method from-posix($posix, Bool $prefer-leap-second = False) | |
ok 1909 - doc/Type/Instant.pod6 chunk 2 compiles | |
# say DateTime.new(Instant.from-posix(915148800, True)); # OUTPUT: «1998-12-31T23:59:60Z» | |
# say DateTime.new(Instant.from-posix(915148800)); # OUTPUT: «1999-01-01T00:00:00Z» | |
ok 1910 - doc/Type/Instant.pod6 chunk 3 compiles | |
# method to-posix() | |
ok 1911 - doc/Type/Instant.pod6 chunk 4 compiles | |
# say DateTime.new("1999-01-01T00:00:00Z").Instant.to-posix; # OUTPUT: «(915148800 False)» | |
# say DateTime.new('1998-12-31T23:59:60Z').Instant.to-posix; # OUTPUT: «(915148800 True)» | |
ok 1912 - doc/Type/Instant.pod6 chunk 5 compiles | |
# method Date(Instant:D: --> Date:D) | |
ok 1913 - doc/Type/Instant.pod6 chunk 6 compiles | |
# # the results given will vary from system to system | |
# my $i = "/etc/passwd".IO.modified; | |
# say $i; # OUTPUT: «Instant:1451489025.878018» | |
# say $i.Date; # OUTPUT: «2015-12-30» | |
ok 1914 - doc/Type/Instant.pod6 chunk 7 compiles | |
WARNINGS for /Users/williamcoleda/sandbox/doc/EVAL_1917: | |
Useless use of constant integer 123 in sink context (line 2) | |
# 123; # Int in decimal notation | |
# :16<BEEF>; # Int in radix notations | |
ok 1915 - doc/Type/Int.pod6 chunk 1 compiles | |
# say so :2<11111111> == 0b11111111 == :8<377> == 0o377 == 255 == 0d255 == :16<ff> == 0xff; | |
# # OUTPUT: «True» | |
ok 1916 - doc/Type/Int.pod6 chunk 2 compiles | |
WARNINGS for /Users/williamcoleda/sandbox/doc/EVAL_1919: | |
Useless use of constant integer 500000 in sink context (lines 2, 3) | |
# 5_00000; # five Lakhs | |
# 500_000; # five hundred thousand | |
# 0xBEEF_CAFE; # a strange place | |
# :2<1010_1010>; # 0d170 | |
ok 1917 - doc/Type/Int.pod6 chunk 3 compiles | |
# :16("9F"); # 159 | |
# :100[99, 2, 3]; # 990203 | |
ok 1918 - doc/Type/Int.pod6 chunk 4 compiles | |
# my $two = "2"; | |
# my $ninety-nine = "99"; | |
# :16($ninety-nine); # 153 | |
# :100[99, $two, 3]; # 990203 | |
ok 1919 - doc/Type/Int.pod6 chunk 5 compiles | |
# multi sub chr(Int:D --> Str:D) | |
# multi method chr(Int:D: --> Str:D) | |
ok 1920 - doc/Type/Int.pod6 chunk 6 compiles | |
# 65.chr; # returns "A" | |
# 196.chr; # returns "Ä" | |
ok 1921 - doc/Type/Int.pod6 chunk 7 compiles | |
# multi sub expmod( $x, $y, $mod --> Int:D) | |
# multi sub expmod(Int:D $x, Int $y, Int $mod --> Int:D) | |
# multi method expmod(Int:D: Int $y, Int $mod --> Int:D) | |
ok 1922 - doc/Type/Int.pod6 chunk 8 compiles | |
# say expmod(4, 2, 5); # OUTPUT: «1» | |
# say 7.expmod(2, 5); # OUTPUT: «4» | |
ok 1923 - doc/Type/Int.pod6 chunk 9 compiles | |
# method polymod(Int:D: +@mods) | |
ok 1924 - doc/Type/Int.pod6 chunk 10 compiles | |
# my $seconds = 1 * 60*60*24 # days | |
# + 3 * 60*60 # hours | |
# + 4 * 60 # minutes | |
# + 5; # seconds | |
# say $seconds.polymod(60, 60); # OUTPUT: «(5 4 27)» | |
# say $seconds.polymod(60, 60, 24); # OUTPUT: «(5 4 3 1)» | |
# say 120.polymod: 1, 10, 10², 10³, 10⁴; # OUTPUT: «(0 0 12 0 0 0)» | |
# say 120.polymod: lazy 1, 10, 10², 10³, 10⁴; # OUTPUT: «(0 0 12)» | |
# say 120.polymod: 1, 10, 10² … ∞; # OUTPUT: «(0 0 12)» | |
# say ⅔.polymod(⅓); # OUTPUT: «(0 2)» | |
# say 5.Rat.polymod(.3, .2); # OUTPUT: «(0.2 0 80)» | |
ok 1925 - doc/Type/Int.pod6 chunk 11 compiles | |
# my $seconds = 2 * 60*60*24 # days | |
# + 3 * 60*60 # hours | |
# + 4 * 60 # minutes | |
# + 5; # seconds | |
# my @pieces; | |
# for 60, 60, 24 -> $divisor { | |
# @pieces.push: $seconds mod $divisor; | |
# $seconds div= $divisor | |
# } | |
# @pieces.push: $seconds; | |
# say @pieces; # OUTPUT: «[5 4 3 2]» | |
ok 1926 - doc/Type/Int.pod6 chunk 12 compiles | |
# multi sub is-prime (Int:D $number --> Bool:D) | |
# multi method is-prime (Int:D: --> Bool:D) | |
ok 1927 - doc/Type/Int.pod6 chunk 13 compiles | |
# say 2.is-prime; # OUTPUT: «True» | |
# say is-prime(9); # OUTPUT: «False» | |
ok 1928 - doc/Type/Int.pod6 chunk 14 compiles | |
# multi method lsb(Int:D:) | |
# multi sub lsb(Int:D) | |
ok 1929 - doc/Type/Int.pod6 chunk 15 compiles | |
# say 0b01011.lsb; # OUTPUT: «0» | |
# say 0b01010.lsb; # OUTPUT: «1» | |
# say 0b10100.lsb; # OUTPUT: «2» | |
# say 0b01000.lsb; # OUTPUT: «3» | |
# say 0b10000.lsb; # OUTPUT: «4» | |
ok 1930 - doc/Type/Int.pod6 chunk 16 compiles | |
# multi method msb(Int:D:) | |
# multi sub msb(Int:D) | |
ok 1931 - doc/Type/Int.pod6 chunk 17 compiles | |
# say 0b00001.msb; # OUTPUT: «0» | |
# say 0b00011.msb; # OUTPUT: «1» | |
# say 0b00101.msb; # OUTPUT: «2» | |
# say 0b01010.msb; # OUTPUT: «3» | |
# say 0b10011.msb; # OUTPUT: «4» | |
ok 1932 - doc/Type/Int.pod6 chunk 18 compiles | |
# multi sub unival(Int:D --> Numeric) | |
# multi method unival(Int:D: --> Numeric) | |
ok 1933 - doc/Type/Int.pod6 chunk 19 compiles | |
# say ord("¾").unival; # OUTPUT: «0.75» | |
# say 190.unival; # OUTPUT: «0.75» | |
# say unival(65); # OUTPUT: «NaN» | |
ok 1934 - doc/Type/Int.pod6 chunk 20 compiles | |
# multi sub infix:<div>(Int:D, Int:D --> Int:D) | |
ok 1935 - doc/Type/Int.pod6 chunk 21 compiles | |
# class IntStr is Int is Str { } | |
ok 1936 - doc/Type/IntStr.pod6 chunk 1 compiles | |
# my $f = <42>; say $f.WHAT; # OUTPUT: «(IntStr)» | |
ok 1937 - doc/Type/IntStr.pod6 chunk 2 compiles | |
# my $int-str = <42>; | |
# my Int $int = $int-str; # OK! | |
# my Str $str = $int-str; # OK! | |
# say 42 ∈ <42 55 1>; # False; ∈ operator cares about object identity | |
ok 1938 - doc/Type/IntStr.pod6 chunk 3 compiles | |
# method new(Int $i, Str $s) | |
ok 1939 - doc/Type/IntStr.pod6 chunk 4 compiles | |
# my $f = IntStr.new(42, "forty two"); | |
# say +$f; # OUTPUT: «42» | |
# say ~$f; # OUTPUT: «"forty two"» | |
ok 1940 - doc/Type/IntStr.pod6 chunk 5 compiles | |
# method Numeric | |
ok 1941 - doc/Type/IntStr.pod6 chunk 6 compiles | |
# method Int | |
ok 1942 - doc/Type/IntStr.pod6 chunk 7 compiles | |
# multi sub infix:<cmp>(IntStr:D $a, IntStr:D $b) | |
ok 1943 - doc/Type/IntStr.pod6 chunk 8 compiles | |
# my $f = IntStr.new(42, "smaller"); | |
# my $g = IntStr.new(43, "larger"); | |
# say $f cmp $g; # OUTPUT: «Less» | |
# say $f.Str cmp $g.Str; # OUTPUT: «More» | |
ok 1944 - doc/Type/IntStr.pod6 chunk 9 compiles | |
# role Iterable { } | |
ok 1945 - doc/Type/Iterable.pod6 chunk 1 compiles | |
# role DNA does Iterable { | |
# method iterator(){ self.comb.iterator } | |
# }; | |
# my @a does DNA = 'GAATCC'; | |
# .say for @a; # OUTPUT: «GGATCC» | |
ok 1946 - doc/Type/Iterable.pod6 chunk 2 compiles | |
# method iterator(--> Iterator:D) | |
ok 1947 - doc/Type/Iterable.pod6 chunk 3 compiles | |
# say (1..10).iterator; | |
ok 1948 - doc/Type/Iterable.pod6 chunk 4 compiles | |
# method flat(--> Iterable) | |
ok 1949 - doc/Type/Iterable.pod6 chunk 5 compiles | |
# say (<a b>, 'c').elems; # OUTPUT: «2» | |
# say (<a b>, 'c').flat.elems; # OUTPUT: «3» | |
ok 1950 - doc/Type/Iterable.pod6 chunk 6 compiles | |
# say ($('a', 'b'), 'c').perl; # OUTPUT: «($("a", "b"), "c")» | |
ok 1951 - doc/Type/Iterable.pod6 chunk 7 compiles | |
# method lazy(--> Iterable) | |
ok 1952 - doc/Type/Iterable.pod6 chunk 8 compiles | |
# say (1 ... 1000).is-lazy; # OUTPUT: «False» | |
# say (1 ... 1000).lazy.is-lazy; # OUTPUT: «True» | |
ok 1953 - doc/Type/Iterable.pod6 chunk 9 compiles | |
# method hyper(Int(Cool) :$batch = 64, Int(Cool) :$degree = 4 --> Iterable) | |
ok 1954 - doc/Type/Iterable.pod6 chunk 10 compiles | |
# say ([1..100].hyper.map({ $_ +1 }).list); | |
ok 1955 - doc/Type/Iterable.pod6 chunk 11 compiles | |
# method race(Int(Cool) :$batch = 64, Int(Cool) :$degree = 4 --> Iterable) | |
ok 1956 - doc/Type/Iterable.pod6 chunk 12 compiles | |
# say ([1..100].race.map({ $_ +1 }).list); | |
ok 1957 - doc/Type/Iterable.pod6 chunk 13 compiles | |
# method pull-one(Iterator:D: --> Mu) | |
ok 1958 - doc/Type/Iterator.pod6 chunk 1 compiles | |
# my $i = (1 .. 3).iterator; | |
# say $i.pull-one; # OUTPUT: «1» | |
# say $i.pull-one; # OUTPUT: «2» | |
# say $i.pull-one; # OUTPUT: «3» | |
# dd $i.pull-one; # IterationEnd | |
ok 1959 - doc/Type/Iterator.pod6 chunk 2 compiles | |
# method push-exactly(Iterator:D: $target, int $count --> Mu) | |
ok 1960 - doc/Type/Iterator.pod6 chunk 3 compiles | |
# my @array; | |
# say (1 .. Inf).iterator.push-exactly(@array, 3); # OUTPUT: «3» | |
# say @array; # [1 2 3] | |
ok 1961 - doc/Type/Iterator.pod6 chunk 4 compiles | |
# method push-at-least(Iterator:D: $target, int $count --> Mu) | |
ok 1962 - doc/Type/Iterator.pod6 chunk 5 compiles | |
# my @array; | |
# say (1 .. Inf).iterator.push-at-least(@array, 10); # OUTPUT: «10» | |
# say @array; # [1 2 3 4 5 6 7 8 9 10] | |
ok 1963 - doc/Type/Iterator.pod6 chunk 6 compiles | |
# method push-all(Iterator:D: $target) | |
ok 1964 - doc/Type/Iterator.pod6 chunk 7 compiles | |
# my @array; | |
# say (1 .. 1000).iterator.push-all(@array); # All 1000 values are pushed | |
ok 1965 - doc/Type/Iterator.pod6 chunk 8 compiles | |
# method push-until-lazy(Iterator:D: $target --> Mu) | |
ok 1966 - doc/Type/Iterator.pod6 chunk 9 compiles | |
# method is-lazy(Iterator:D: --> Bool:D) | |
ok 1967 - doc/Type/Iterator.pod6 chunk 10 compiles | |
# say (1 .. 100).is-lazy; # OUTPUT: «False» | |
# say (1 .. Inf).is-lazy; # OUTPUT: «True» | |
ok 1968 - doc/Type/Iterator.pod6 chunk 11 compiles | |
# method sink-all(Iterator:D:) | |
ok 1969 - doc/Type/Iterator.pod6 chunk 12 compiles | |
# say (1 .. 1000).iterator.sink-all; | |
ok 1970 - doc/Type/Iterator.pod6 chunk 13 compiles | |
# method skip-one(Iterator:D: $target --> Mu) | |
ok 1971 - doc/Type/Iterator.pod6 chunk 14 compiles | |
# my $i = <a b>.iterator; | |
# say $i.skip-one; say $i.pull-one; say $i.skip-one | |
# # OUTPUT: «1b0» | |
ok 1972 - doc/Type/Iterator.pod6 chunk 15 compiles | |
# method skip-at-least(Iterator:D: $target, int $to-skip --> Mu) | |
ok 1973 - doc/Type/Iterator.pod6 chunk 16 compiles | |
# my $i = <a b c>.iterator; | |
# say $i.skip-at-least(2); say $i.pull-one; say $i.skip-at-least(20); | |
# # OUTPUT: «1c0» | |
ok 1974 - doc/Type/Iterator.pod6 chunk 17 compiles | |
# method skip-at-least-pull-one(Iterator:D: $target, int $to-skip --> Mu) | |
ok 1975 - doc/Type/Iterator.pod6 chunk 18 compiles | |
# my $i = <a b c>.iterator; | |
# say $i.skip-at-least-pull-one(2); | |
# say $i.skip-at-least-pull-one(20) =:= IterationEnd; | |
# # OUTPUT: «cTrue» | |
ok 1976 - doc/Type/Iterator.pod6 chunk 19 compiles | |
# class Junction is Mu { } | |
ok 1977 - doc/Type/Junction.pod6 chunk 1 compiles | |
# my $j = 1|2; | |
# if 3 == $j + 1 { | |
# say 'yes'; | |
# } | |
ok 1978 - doc/Type/Junction.pod6 chunk 2 compiles | |
# my @list = <1 2 "Great">; | |
# @list.append(True).append(False); | |
# my @bool_or_int = grep Bool|Int, @list; | |
# sub is_prime(Int $x) returns Bool { | |
# # 'so' is for boolean context | |
# so $x %% none(2..$x.sqrt); | |
# } | |
# my @primes_ending_in_1 = grep &is_prime & / 1$ /, 2..100; | |
# say @primes_ending_in_1; # OUTPUT: «[11 31 41 61 71]» | |
# my @exclude = <~ .git>; | |
# for dir(".") { say .Str if .Str.ends-with(none @exclude) } | |
ok 1979 - doc/Type/Junction.pod6 chunk 3 compiles | |
# my @a = (); | |
# say so all(@a) # True, because there are 0 False's | |
ok 1980 - doc/Type/Junction.pod6 chunk 4 compiles | |
# my @a = (); | |
# say so @a && all(@a); # OUTPUT: «False» | |
ok 1981 - doc/Type/Junction.pod6 chunk 5 compiles | |
# my $word = 'yes'; | |
# my @negations = <no none never>; | |
# if $word !eq any @negations { | |
# say '"yes" is not a negation'; | |
# } | |
ok 1982 - doc/Type/Junction.pod6 chunk 6 compiles | |
# my $word = 'yes'; | |
# my @negations = <no none never>; | |
# if $word eq none @negations { | |
# say '"yes" is not a negation'; | |
# } | |
ok 1983 - doc/Type/Junction.pod6 chunk 7 compiles | |
# class Label {} | |
ok 1984 - doc/Type/Label.pod6 chunk 1 compiles | |
# method next(Label:) | |
ok 1985 - doc/Type/Label.pod6 chunk 2 compiles | |
# MY-LABEL: | |
# for 1..10 { | |
# next MY-LABEL if $_ > 5; # does 5 iteration and then 5 empty iteration | |
# say $_; | |
# } | |
ok 1986 - doc/Type/Label.pod6 chunk 3 compiles | |
# method last(Label:) | |
ok 1987 - doc/Type/Label.pod6 chunk 4 compiles | |
# MY-LABEL: | |
# for 1..10 { | |
# last MY-LABEL if $_ > 5; # does only 5 iteration | |
# say $_; | |
# } | |
ok 1988 - doc/Type/Label.pod6 chunk 5 compiles | |
# my @a = 1, 2, 3; | |
# for @a { } # three iterations | |
# my $s = @a; | |
# for $s { } # one iteration | |
# for @a.item { } # one iteration | |
# for $s.list { } # three iterations | |
ok 1989 - doc/Type/List.pod6 chunk 1 compiles | |
# my @a = 1, 2, 3; | |
# my @nested = @a, @a; # two elements | |
# my @flat = flat @a, @a; # six elements, with explicit flat | |
# my @b = 'a', 'b'; | |
# @b.append: @a; # @b now has 5 elements, because @a | |
# # is the sole argument to append | |
# my @c = 'a', 'b'; | |
# @c.append: $@a; # @b now has 3 elements, because of the | |
# # itemization with $ | |
# say @c.elems; | |
ok 1990 - doc/Type/List.pod6 chunk 2 compiles | |
# my %h = a => 1, b => 2; | |
# my @b = %h; say @b.elems; # OUTPUT: «2» | |
# my @c = %h, ; say @c.elems; # OUTPUT: «1» | |
# my @d = $%h; say @d.elems; # OUTPUT: «1» | |
ok 1991 - doc/Type/List.pod6 chunk 3 compiles | |
# sub fe(*@flat) { @flat.elems } | |
# say fe(<a b>, <d e>); # OUTPUT: «4» | |
# say fe(<a b>, <d e>.item); # OUTPUT: «3» | |
ok 1992 - doc/Type/List.pod6 chunk 4 compiles | |
# my @a; | |
# for @a, @a.list, @a.Seq -> \listoid { | |
# say listoid ~~ () | |
# } | |
# # OUTPUT: «TrueTrueTrue» | |
ok 1993 - doc/Type/List.pod6 chunk 5 compiles | |
# my @a; | |
# say [@a.elems, @a.Bool, ?@a]; # OUTPUT: «[0 False False]» | |
# @a.push: 42; | |
# say [@a.elems, @a.Bool, ?@a]; # OUTPUT: «[1 True True]» | |
# say 'empty' unless @a; # OUTPUT: «()» | |
ok 1994 - doc/Type/List.pod6 chunk 6 compiles | |
# sub elems($list --> Int:D) | |
# method elems(List:D: --> Int:D) | |
ok 1995 - doc/Type/List.pod6 chunk 7 compiles | |
# say (1,2,3,4).elems; # OUTPUT: «4» | |
ok 1996 - doc/Type/List.pod6 chunk 8 compiles | |
# sub end($list --> Int:D) | |
# method end(List:D: --> Int:D) | |
ok 1997 - doc/Type/List.pod6 chunk 9 compiles | |
# say (1,2,3,4).end; # OUTPUT: «3» | |
ok 1998 - doc/Type/List.pod6 chunk 10 compiles | |
# sub keys($list --> Seq:D) | |
# method keys(List:D: --> Seq:D) | |
ok 1999 - doc/Type/List.pod6 chunk 11 compiles | |
# say (1,2,3,4).keys; # OUTPUT: «0..3» | |
ok 2000 - doc/Type/List.pod6 chunk 12 compiles | |
# sub values($list --> Seq:D) | |
# method values(List:D: --> Seq:D) | |
ok 2001 - doc/Type/List.pod6 chunk 13 compiles | |
# say (1,2,3,4).WHAT; # OUTPUT: «(List)» | |
# say (1,2,3,4).values.WHAT; # OUTPUT: «(Seq)» | |
ok 2002 - doc/Type/List.pod6 chunk 14 compiles | |
# sub kv($list --> Seq:D) | |
# method kv(List:D: --> Seq:D) | |
ok 2003 - doc/Type/List.pod6 chunk 15 compiles | |
# <a b c>.kv; # (0 a 1 b 2 c) | |
ok 2004 - doc/Type/List.pod6 chunk 16 compiles | |
# sub pairs($list --> Seq:D) | |
# method pairs(List:D: --> Seq:D) | |
ok 2005 - doc/Type/List.pod6 chunk 17 compiles | |
# <a b c>.pairs # (0 => a 1 => b 2 => c) | |
ok 2006 - doc/Type/List.pod6 chunk 18 compiles | |
# method antipairs(List:D: --> Seq:D) | |
ok 2007 - doc/Type/List.pod6 chunk 19 compiles | |
# say <a b c>.antipairs; # OUTPUT: «(a => 0 b => 1 c => 2)» | |
ok 2008 - doc/Type/List.pod6 chunk 20 compiles | |
# sub join($separator, *@list --> Str:D) | |
# method join(List:D: $separator --> Str:D) | |
ok 2009 - doc/Type/List.pod6 chunk 21 compiles | |
# join ', ', <a b c>; # RESULT: «a, b, c» | |
ok 2010 - doc/Type/List.pod6 chunk 22 compiles | |
# say (1, <a b c>).join('|'); # OUTPUT: «1|a b c» | |
ok 2011 - doc/Type/List.pod6 chunk 23 compiles | |
# sub map(&code, *@elems --> Seq:D) | |
# method map(List:D: &code --> Seq:D) | |
ok 2012 - doc/Type/List.pod6 chunk 24 compiles | |
# say ('hello', 1, 22/7, 42, 'world').map: { .WHAT.perl } # OUTPUT: «(Str Int Rat Int Str)» | |
# say map *.Str.chars, 'hello', 1, 22/7, 42, 'world'; # OUTPUT: «(5 1 8 2 5)» | |
ok 2013 - doc/Type/List.pod6 chunk 25 compiles | |
# sub b($a, $b) { "$a before $b" }; | |
# say <a b x y>.map(&b).join(', '); # OUTPUT: «a before b, x before y» | |
ok 2014 - doc/Type/List.pod6 chunk 26 compiles | |
# ((1, 2), <a b>).map({ .join(',')}) | |
ok 2015 - doc/Type/List.pod6 chunk 27 compiles | |
# sub s { | |
# my &loop-block = { | |
# return # return from sub s | |
# }; | |
# say 'hi'; | |
# (1..3).map: &loop-block; | |
# say 'oi‽' # dead code | |
# }; | |
# s | |
# # RESULT: «hi» | |
ok 2016 - doc/Type/List.pod6 chunk 28 compiles | |
# sub flat(**@list is raw) | |
ok 2017 - doc/Type/List.pod6 chunk 29 compiles | |
# say flat 1, (2, (3, 4), $(5, 6)); # OUTPUT: «(1 2 3 4 (5 6))» | |
ok 2018 - doc/Type/List.pod6 chunk 30 compiles | |
# method flatmap(List:D: &code --> Seq:D) | |
ok 2019 - doc/Type/List.pod6 chunk 31 compiles | |
# say ((1, 2), <a b>).flatmap(&uc).join('|'); # OUTPUT: «1 2|A B» | |
ok 2020 - doc/Type/List.pod6 chunk 32 compiles | |
# sub grep(Mu $matcher, *@elems, :$k, :$kv, :$p, :$v --> Seq:D) | |
# method grep(List:D: Mu $matcher, :$k, :$kv, :$p, :$v --> Seq:D) | |
ok 2021 - doc/Type/List.pod6 chunk 33 compiles | |
# say ('hello', 1, 22/7, 42, 'world').grep: Int; # OUTPUT: «(1 42)» | |
# say grep { .Str.chars > 3 }, 'hello', 1, 22/7, 42, 'world'; # OUTPUT: «(hello 3.142857 world)» | |
ok 2022 - doc/Type/List.pod6 chunk 34 compiles | |
# say ('hello', 1, 22/7, 42, 'world').grep: Int, :k; | |
# # OUTPUT: «(1 3)» | |
# say grep { .Str.chars > 3 }, :kv, 'hello', 1, 22/7, 42, 'world'; | |
# # OUTPUT: «(0 hello 2 3.142857 4 world)» | |
# say grep { .Str.chars > 3 }, :p, 'hello', 1, 22/7, 42, 'world'; | |
# # OUTPUT: «(0 => hello 2 => 3.142857 4 => world)» | |
ok 2023 - doc/Type/List.pod6 chunk 35 compiles | |
# sub first(Mu $matcher, *@elems, :$k, :$kv, :$p, :$end) | |
# method first(List:D: Mu $matcher?, :$k, :$kv, :$p, :$end) | |
ok 2024 - doc/Type/List.pod6 chunk 36 compiles | |
# say (1, 22/7, 42, 300).first: * > 5; # OUTPUT: «42» | |
# say (1, 22/7, 42, 300).first: * > 5, :end; # OUTPUT: «300» | |
# say ('hello', 1, 22/7, 42, 'world').first: Complex; # OUTPUT: «Nil» | |
ok 2025 - doc/Type/List.pod6 chunk 37 compiles | |
# say (1, 22/7, 42, 300).first: * > 5, :k; # OUTPUT: «2» | |
# say (1, 22/7, 42, 300).first: * > 5, :p; # OUTPUT: «2 => 42» | |
# say (1, 22/7, 42, 300).first: * > 5, :kv, :end; # OUTPUT: «(3 300)» | |
ok 2026 - doc/Type/List.pod6 chunk 38 compiles | |
# method head(List:D: Int(Cool) $number = 1 --> Seq:D) | |
ok 2027 - doc/Type/List.pod6 chunk 39 compiles | |
# say ^10 .head(5); # OUTPUT: «(0 1 2 3 4)» | |
# say ^Inf .head(5); # OUTPUT: «(0 1 2 3 4)» | |
# say ^10 .head; # OUTPUT: «(0)» | |
# say ^Inf .head; # OUTPUT: «(0)» | |
ok 2028 - doc/Type/List.pod6 chunk 40 compiles | |
# method tail(List:D: Int(Cool) $number = 1 --> Seq:D) | |
ok 2029 - doc/Type/List.pod6 chunk 41 compiles | |
# sub categorize(&mapper, *@values --> Hash:D) | |
# method categorize(List:D: &mapper --> Hash:D) | |
ok 2030 - doc/Type/List.pod6 chunk 42 compiles | |
# sub mapper(Int $i) returns List { | |
# $i %% 2 ?? 'even' !! 'odd', | |
# $i.is-prime ?? 'prime' !! 'not prime' | |
# } | |
# say categorize &mapper, (1, 7, 6, 3, 2); # OUTPUT: «{even => [6 2], not prime => [1 6], | |
# # odd => [1 7 3], prime => [7 3 2]}» | |
ok 2031 - doc/Type/List.pod6 chunk 43 compiles | |
# sub classify(&mapper, *@values --> Hash:D) | |
# method classify(List:D: &mapper --> Hash:D) | |
ok 2032 - doc/Type/List.pod6 chunk 44 compiles | |
# say classify { $_ %% 2 ?? 'even' !! 'odd' }, (1, 7, 6, 3, 2); | |
# # OUTPUT: «{even => [6 2], odd => [1 7 3]}» | |
# say ('hello', 1, 22/7, 42, 'world').classify: { .Str.chars }; | |
# # OUTPUT: «{1 => [1], 2 => [42], 5 => [hello world], 8 => [3.142857]}» | |
ok 2033 - doc/Type/List.pod6 chunk 45 compiles | |
# method Bool(List:D: --> Bool:D) | |
ok 2034 - doc/Type/List.pod6 chunk 46 compiles | |
# say ().Bool; # OUTPUT: «False» | |
# say (1).Bool; # OUTPUT: «True» | |
ok 2035 - doc/Type/List.pod6 chunk 47 compiles | |
# method Str(List:D: --> Str:D) | |
ok 2036 - doc/Type/List.pod6 chunk 48 compiles | |
# say (1,2,3,4,5).Str; # OUTPUT: «1 2 3 4 5» | |
ok 2037 - doc/Type/List.pod6 chunk 49 compiles | |
# method Int(List:D: --> Int:D) | |
ok 2038 - doc/Type/List.pod6 chunk 50 compiles | |
# say (1,2,3,4,5).Int; # OUTPUT: «5» | |
ok 2039 - doc/Type/List.pod6 chunk 51 compiles | |
# method Numeric(List:D: --> Int:D) | |
ok 2040 - doc/Type/List.pod6 chunk 52 compiles | |
# say (1,2,3,4,5).Numeric; # OUTPUT: «5» | |
ok 2041 - doc/Type/List.pod6 chunk 53 compiles | |
# method Capture(--> Capture:D) | |
ok 2042 - doc/Type/List.pod6 chunk 54 compiles | |
# my $list = (7, 5, a => 2, b => 17); | |
# my $capture = $list.Capture; | |
# say $capture.keys; # OUTPUT: «(0 1 a b)» | |
# my-sub(|$capture); # RESULT: «7, 5, 2, 17» | |
# sub my-sub($first, $second, :$a, :$b) { | |
# say "$first, $second, $a, $b" | |
# } | |
ok 2043 - doc/Type/List.pod6 chunk 55 compiles | |
# my $list = (7, 5, a => 2, b => 17); | |
# say so $list.Capture ~~ :($ where * == 7,$,:$a,:$b); # OUTPUT: «True» | |
# $list = (8, 5, a => 2, b => 17); | |
# say so $list.Capture ~~ :($ where * == 7,$,:$a,:$b); # OUTPUT: «False» | |
ok 2044 - doc/Type/List.pod6 chunk 56 compiles | |
# multi sub pick($count, *@list --> Seq:D) | |
# multi method pick(List:D: $count --> Seq:D) | |
# multi method pick(List:D: --> Mu) | |
ok 2045 - doc/Type/List.pod6 chunk 57 compiles | |
# say <a b c d e>.pick; # OUTPUT: «b» | |
# say <a b c d e>.pick: 3; # OUTPUT: «(c a e)» | |
# say <a b c d e>.pick: *; # OUTPUT: «(e d a b c)» | |
ok 2046 - doc/Type/List.pod6 chunk 58 compiles | |
# multi sub roll($count, *@list --> Seq:D) | |
# multi method roll(List:D: $count --> Seq:D) | |
# multi method roll(List:D: --> Mu) | |
ok 2047 - doc/Type/List.pod6 chunk 59 compiles | |
# say <a b c d e>.roll; # 1 random letter | |
# say <a b c d e>.roll: 3; # 3 random letters | |
# say roll 8, <a b c d e>; # 8 random letters | |
# my $random-digits := (^10).roll(*); | |
# say $random-digits[^15]; # 15 random digits | |
ok 2048 - doc/Type/List.pod6 chunk 60 compiles | |
# multi method eager(List:D: --> List:D) | |
# multi sub eager(*@elems --> List:D) | |
ok 2049 - doc/Type/List.pod6 chunk 61 compiles | |
# say (1,2,3,4,5).eager; # OUTPUT: «1 2 3 4 5» | |
ok 2050 - doc/Type/List.pod6 chunk 62 compiles | |
# multi sub reverse(*@list --> List:D) | |
# multi method reverse(List:D: --> List:D) | |
ok 2051 - doc/Type/List.pod6 chunk 63 compiles | |
# say <hello world!>.reverse; # OUTPUT: «(world! hello)» | |
# say reverse ^10; # OUTPUT: «(9 8 7 6 5 4 3 2 1 0)» | |
ok 2052 - doc/Type/List.pod6 chunk 64 compiles | |
# multi sub rotate(@list, Int:D $n = 1 --> List:D) | |
# multi method rotate(List:D: Int:D $n = 1 --> List:D) | |
ok 2053 - doc/Type/List.pod6 chunk 65 compiles | |
# <a b c d e>.rotate(2); # <c d e a b> | |
# <a b c d e>.rotate(-1); # <e a b c d> | |
ok 2054 - doc/Type/List.pod6 chunk 66 compiles | |
# multi sub sort(*@elems --> Seq:D) | |
# multi sub sort(&by, *@elems --> Seq:D) | |
# multi method sort(List:D: --> Seq:D) | |
# multi method sort(List:D: &by --> Seq:D) | |
ok 2055 - doc/Type/List.pod6 chunk 67 compiles | |
# say (3, -4, 7, -1, 2, 0).sort; # OUTPUT: «(-4 -1 0 2 3 7)» | |
# say (3, -4, 7, -1, 2, 0).sort: *.abs; # OUTPUT: «(0 -1 2 3 -4 7)» | |
# say (3, -4, 7, -1, 2, 0).sort: { $^b leg $^a }; # OUTPUT: «(7 3 2 0 -4 -1)» | |
ok 2056 - doc/Type/List.pod6 chunk 68 compiles | |
# multi sub unique(*@values, :&as, :&with --> Seq:D) | |
# multi method unique(List:D: :&as, :&with --> Seq:D) | |
ok 2057 - doc/Type/List.pod6 chunk 69 compiles | |
# say <a a b b b c c>.unique; # OUTPUT: «(a b c)» | |
# say <a b b c c b a>.unique; # OUTPUT: «(a b c)» | |
ok 2058 - doc/Type/List.pod6 chunk 70 compiles | |
# say <a A B b c b C>.unique(:as(&lc)) # OUTPUT: «(a B c)» | |
ok 2059 - doc/Type/List.pod6 chunk 71 compiles | |
# my @list = {a => 42}, {b => 13}, {a => 42}; | |
# say @list.unique(:with(&[eqv])) # OUTPUT: «({a => 42} {b => 13})» | |
ok 2060 - doc/Type/List.pod6 chunk 72 compiles | |
# multi sub repeated(*@values, :&as, :&with --> Seq:D) | |
# multi method repeated(List:D: :&as, :&with --> Seq:D) | |
ok 2061 - doc/Type/List.pod6 chunk 73 compiles | |
# say <a a b b b c c>.repeated; # OUTPUT: «(a b b c)» | |
# say <a b b c c b a>.repeated; # OUTPUT: «(b c b a)» | |
# say <a A B b c b C>.repeated(:as(&lc)); # OUTPUT: «(A b b C)» | |
# my @list = {a => 42}, {b => 13}, {a => 42}; | |
# say @list.repeated(:with(&[eqv])) # OUTPUT: «({a => 42})» | |
ok 2062 - doc/Type/List.pod6 chunk 74 compiles | |
# multi sub squish(*@values, :&as --> Seq:D) | |
# multi method squish(List:D: :&as --> Seq:D) | |
ok 2063 - doc/Type/List.pod6 chunk 75 compiles | |
# say <a a b b b c c>.squish; # OUTPUT: «(a b c)» | |
# say <a b b c c b a>.squish; # OUTPUT: «(a b c b a)» | |
ok 2064 - doc/Type/List.pod6 chunk 76 compiles | |
# multi sub reduce(&with, *@values) | |
# multi method reduce(List:D: &with) | |
ok 2065 - doc/Type/List.pod6 chunk 77 compiles | |
# my @strings = ("One good string!", "And one another good string!"); | |
# say reduce { $^a ~ $^b }, '', |@strings; # like @strings.join | |
# my @numbers = (1,2,3,4,5); | |
# say reduce { $^a > $^b ?? $^a !! $^b }, 0, |@numbers; # like @numbers.max | |
ok 2066 - doc/Type/List.pod6 chunk 78 compiles | |
# # Raise 2 to the 81st power, because 3 to the 4th power is 81 | |
# [2,3,4].reduce(&[**]).lsb.say; # OUTPUT: «81» | |
# (2**(3**4)).lsb.say; # OUTPUT: «81» | |
# (2**3**4).lsb.say; # OUTPUT: «81» | |
# # Subtract 4 from -1, because 2 minus 3 is -1 | |
# [2,3,4].reduce(&[-]).say; # OUTPUT: «-5» | |
# ((2-3)-4).say; # OUTPUT: «-5» | |
# (2-3-4).say; # OUTPUT: «-5» | |
ok 2067 - doc/Type/List.pod6 chunk 79 compiles | |
# # The following all do the same thing... | |
# my @numbers = (1,2,3,4,5); | |
# say reduce { $^a + $^b }, 0, |@numbers; | |
# say reduce * + *, 0, |@numbers; | |
# say reduce &[+], @numbers; # operator does not need explicit identity | |
# say [+] @numbers; # most people write it this way | |
ok 2068 - doc/Type/List.pod6 chunk 80 compiles | |
# say (2,3,4,5).reduce: { last if $^a > 7; $^a + $^b }; # says 9 | |
ok 2069 - doc/Type/List.pod6 chunk 81 compiles | |
# # Generate a random-ish math formula like "(4 + ((3 * x) + 11) / 6))" | |
# my @ops = [Z] (<+ - * />, 1..20)».roll(4); | |
# say ('x', |@ops).reduce: -> $formula, [$op, $number] { | |
# Bool.pick ?? "($formula $op $number)" | |
# !! "($number $op $formula)" | |
# } | |
ok 2070 - doc/Type/List.pod6 chunk 82 compiles | |
# multi sub produce(&with, *@values) | |
# multi method produce(List:D: &with) | |
ok 2071 - doc/Type/List.pod6 chunk 83 compiles | |
# # Raise 2 to the 81st power, because 3 to the 4th power is 81 | |
# [2,3,4].produce(&[**]).say; # OUTPUT: «(4 81 2417851639229258349412352)» | |
# say produce &[**], (2,3,4); # OUTPUT: «(4 81 2417851639229258349412352)» | |
# say [\**] (2,3,4); # OUTPUT: «(4 81 2417851639229258349412352)» | |
# # Subtract 4 from -1, because 2 minus 3 is -1 | |
# [2,3,4].produce(&[-]).say; # OUTPUT: «(2 -1 -5)» | |
# say produce &[-], (2,3,4); # OUTPUT: «(2 -1 -5)» | |
# say [\-] (2,3,4); # OUTPUT: «(2 -1 -5)» | |
ok 2072 - doc/Type/List.pod6 chunk 84 compiles | |
# # The following all do the same thing... | |
# my @numbers = (1,2,3,4,5); | |
# say produce { $^a + $^b }, @numbers; | |
# say produce * + *, @numbers; | |
# say produce &[+], @numbers; # operator does not need explicit identity | |
# say [\+] @numbers; # most people write it this way | |
ok 2073 - doc/Type/List.pod6 chunk 85 compiles | |
# [\,] 1..5; | |
# # ( | |
# # (1) | |
# # (1 2) | |
# # (1 2 3) | |
# # (1 2 3 4) | |
# # (1 2 3 4 5) | |
# # ) | |
ok 2074 - doc/Type/List.pod6 chunk 86 compiles | |
# say (2,3,4,5).produce: { last if $^a > 7; $^a + $^b }; # OUTPUT: «(2 5 9)» | |
ok 2075 - doc/Type/List.pod6 chunk 87 compiles | |
# multi sub combinations($n, $k --> Seq:D) | |
# multi method combinations(List:D: Int:D $of --> Seq:D) | |
# multi method combinations(List:D: Range:D $of = 0..* --> Seq:D) | |
ok 2076 - doc/Type/List.pod6 chunk 88 compiles | |
# say .join('|') for <a b c>.combinations(2); | |
# # OUTPUT: «a|b | |
# # a|c | |
# # b|c» | |
ok 2077 - doc/Type/List.pod6 chunk 89 compiles | |
# say .join('|') for <a b c>.combinations(2..3); | |
# # OUTPUT: «a|b | |
# # a|c | |
# # b|c | |
# # a|b|c» | |
ok 2078 - doc/Type/List.pod6 chunk 90 compiles | |
# .say for combinations(4, 2) | |
# # OUTPUT: «0 1 | |
# # 0 2 | |
# # 0 3 | |
# # 1 2 | |
# # 1 3 | |
# # 2 3» | |
ok 2079 - doc/Type/List.pod6 chunk 91 compiles | |
# multi sub permutations($n --> Seq:D) | |
# multi method permutations(List:D: --> Seq:D) | |
ok 2080 - doc/Type/List.pod6 chunk 92 compiles | |
# say .join('|') for <a b c>.permutations | |
# # OUTPUT: «a|b|c | |
# # a|c|b | |
# # b|a|c | |
# # b|c|a | |
# # c|a|b | |
# # c|b|a» | |
ok 2081 - doc/Type/List.pod6 chunk 93 compiles | |
# .say for permutations 3; | |
# # OUTPUT: «0 1 2 | |
# # 0 2 1 | |
# # 1 0 2 | |
# # 1 2 0 | |
# # 2 0 1 | |
# # 2 1 0» | |
ok 2082 - doc/Type/List.pod6 chunk 94 compiles | |
# method rotor(*@cycle, Bool() :$partial --> Seq:D) | |
ok 2083 - doc/Type/List.pod6 chunk 95 compiles | |
# say ('a'..'h').rotor(3).join('|'); # OUTPUT: «a b c|d e f» | |
# say ('a'..'h').rotor(3, :partial).join('|'); # OUTPUT: «a b c|d e f|g h» | |
ok 2084 - doc/Type/List.pod6 chunk 96 compiles | |
# say ('a'..'h').rotor(2 => 1).join('|'); # OUTPUT: «a b|d e|g h» | |
# say ('a'..'h').rotor(3 => -1).join('|'); # OUTPUT: «a b c|c d e|e f g» | |
ok 2085 - doc/Type/List.pod6 chunk 97 compiles | |
# say ('a'..'h').rotor(2, 3).join('|'); # OUTPUT: «a b|c d e|f g» | |
# say ('a'..'h').rotor(1 => 1, 3).join('|'); # OUTPUT: «a|c d e|f» | |
ok 2086 - doc/Type/List.pod6 chunk 98 compiles | |
# say ('a'..'h').rotor(1 => 1, 3 => -1, :partial).join('|'); | |
# # OUTPUT: «a|c d e|e|g h» | |
ok 2087 - doc/Type/List.pod6 chunk 99 compiles | |
# sub cross(+@e, :&with --> Seq:D) | |
ok 2088 - doc/Type/List.pod6 chunk 100 compiles | |
# say cross(<a b c>, <d e f>).map(*.join).join(",") | |
# # OUTPUT: «ad,ae,af,bd,be,bf,cd,ce,cf» | |
ok 2089 - doc/Type/List.pod6 chunk 101 compiles | |
# say (<a b c> X <d e f>).map(*.join).join(",") | |
# # output is the same as the previous example | |
ok 2090 - doc/Type/List.pod6 chunk 102 compiles | |
# say cross([1, 2, 3], [4, 5, 6], :with(&infix:<*>)).join(","); | |
# # OUTPUT: «4,5,6,8,10,12,12,15,18» | |
ok 2091 - doc/Type/List.pod6 chunk 103 compiles | |
# say ([1, 2, 3] X* [4, 5, 6]).join(",") | |
# # same output as the previous example | |
ok 2092 - doc/Type/List.pod6 chunk 104 compiles | |
# sub zip(+@e, :&with --> Seq:D) | |
ok 2093 - doc/Type/List.pod6 chunk 105 compiles | |
# say zip(<a b c>, <d e f>, <g h i>); | |
# # OUTPUT: «((a d g) (b e h) (c f i))» | |
ok 2094 - doc/Type/List.pod6 chunk 106 compiles | |
# say <a b c> Z <d e f> Z <g h i>; # same output | |
ok 2095 - doc/Type/List.pod6 chunk 107 compiles | |
# for <a b c> Z <d e f> Z <g h i> -> [$x,$y,$z] {say ($x,$y,$z).join(",")} | |
# # OUTPUT: «a,d,g | |
# # b,e,h | |
# # c,f,i» | |
ok 2096 - doc/Type/List.pod6 chunk 108 compiles | |
# say .join(",") for zip <a b c>, <d e f>, <g h i>; # same output | |
ok 2097 - doc/Type/List.pod6 chunk 109 compiles | |
# say <a b c> Z <d e f m n o p> Z <g h i>; | |
# # ((a d g) (b e h) (c f i)) | |
ok 2098 - doc/Type/List.pod6 chunk 110 compiles | |
# .say for zip <1 2 3>, [1, 2, 3], (1, 2, 3), :with(&infix:<*>); | |
# # OUTPUT: «1 | |
# # 8 | |
# # 27» | |
ok 2099 - doc/Type/List.pod6 chunk 111 compiles | |
# .say for <1 2 3> Z* [1, 2, 3] Z* (1, 2, 3); # same output | |
ok 2100 - doc/Type/List.pod6 chunk 112 compiles | |
# method roundrobin(List:D: --> Seq) | |
ok 2101 - doc/Type/List.pod6 chunk 113 compiles | |
# say roundrobin <a b c>, <d e f>, <g h i>; | |
# # OUTPUT: «((a d g) (b e h) (c f i))» | |
# say .join(",") for roundrobin([1, 2], [2, 3], [3, 4]); | |
# # OUTPUT: «1,2,3 | |
# # 2,3,4» | |
ok 2102 - doc/Type/List.pod6 chunk 114 compiles | |
# say roundrobin <a b c>, <d e f m n o p>, <g h i j>; | |
# # OUTPUT: «((a d g) (b e h) (c f i) (m j) (n) (o) (p))» | |
# say .join(",") for roundrobin([1, 2], [2, 3, 57, 77], [3, 4, 102]); | |
# # OUTPUT: «1,2,3 | |
# # 2,3,4 | |
# # 57,102 | |
# # 77» | |
ok 2103 - doc/Type/List.pod6 chunk 115 compiles | |
# sub sum($list --> Numeric:D) | |
# method sum(List:D: --> Numeric:D) | |
ok 2104 - doc/Type/List.pod6 chunk 116 compiles | |
# say (1, 3, pi).sum; # OUTPUT: «7.14159265358979» | |
# say (1, "0xff").sum; # OUTPUT: «256» | |
# say sum(0b1111, 5); # OUTPUT: «20» | |
ok 2105 - doc/Type/List.pod6 chunk 117 compiles | |
# method fmt($format = '%s', $separator = ' ' --> Str:D) | |
ok 2106 - doc/Type/List.pod6 chunk 118 compiles | |
# my @a = 8..11; | |
# say @a.fmt('%03d', ','); # OUTPUT: «008,009,010,011» | |
ok 2107 - doc/Type/List.pod6 chunk 119 compiles | |
# 'abcdefg' ~~ /(c)(d)/; | |
# say $/.list.from; # OUTPUT: «2» | |
# "abc123def" ~~ m:g/\d/; | |
# say $/.list.from; # OUTPUT: «3» | |
ok 2108 - doc/Type/List.pod6 chunk 120 compiles | |
# "abc123def" ~~ m:g/\d/; | |
# say $/.to; # OUTPUT: «6» | |
ok 2109 - doc/Type/List.pod6 chunk 121 compiles | |
# class Lock {} | |
ok 2110 - doc/Type/Lock.pod6 chunk 1 compiles | |
# my $x = 0; | |
# my $l = Lock.new; | |
# await (^10).map: { | |
# start { | |
# $l.protect({ $x++ }); | |
# } | |
# } | |
# say $x; # OUTPUT: «10» | |
ok 2111 - doc/Type/Lock.pod6 chunk 2 compiles | |
# method protect(Lock:D: &code) | |
ok 2112 - doc/Type/Lock.pod6 chunk 3 compiles | |
# my $l = Lock.new; | |
# $l.protect({ #`( some unsafe operations here ) 1 + 1; }); | |
ok 2113 - doc/Type/Lock.pod6 chunk 4 compiles | |
# method lock(Lock:D:) | |
ok 2114 - doc/Type/Lock.pod6 chunk 5 compiles | |
# my $l = Lock.new; | |
# $l.lock; | |
ok 2115 - doc/Type/Lock.pod6 chunk 6 compiles | |
# method unlock(Lock:D:) | |
ok 2116 - doc/Type/Lock.pod6 chunk 7 compiles | |
# my $l = Lock.new; | |
# $l.lock; | |
# $l.unlock; | |
ok 2117 - doc/Type/Lock.pod6 chunk 8 compiles | |
# my $l = Lock.new; | |
# $l.condition; | |
ok 2118 - doc/Type/Lock.pod6 chunk 9 compiles | |
# class Macro is Routine { } | |
ok 2119 - doc/Type/Macro.pod6 chunk 1 compiles | |
# my %e := Map.new('a', 1, 'b', 2); | |
# say %e.keys; # can print "a b\n" or "b a\n"; | |
# say %e.values; # prints "1 2\n" if the previous line | |
# # printed "a b\n", "b a\n" otherwise | |
ok 2120 - doc/Type/Map.pod6 chunk 1 compiles | |
# method new(*@args) | |
ok 2121 - doc/Type/Map.pod6 chunk 2 compiles | |
# my %h = Map.new('a', 1, 'b', 2); | |
# # WRONG: :b(2) interpreted as named argument | |
# say Map.new('a', 1, :b(2) ).keys; # OUTPUT: «(a)» | |
# # RIGHT: :b(2) interpreted as part of Map's contents | |
# say Map.new( ('a', 1, :b(2)) ).keys; # OUTPUT: «(a b)» | |
ok 2122 - doc/Type/Map.pod6 chunk 3 compiles | |
# method elems(Map:D: --> Int:D) | |
ok 2123 - doc/Type/Map.pod6 chunk 4 compiles | |
# my %map = Map.new('a', 1, 'b', 2); | |
# say %map.elems; # OUTPUT: «2» | |
ok 2124 - doc/Type/Map.pod6 chunk 5 compiles | |
# multi method ACCEPTS(Map:D: Positional $topic) | |
# multi method ACCEPTS(Map:D: Cool:D $topic) | |
# multi method ACCEPTS(Map:D: Regex $topic) | |
# multi method ACCEPTS(Map:D: Any $topic) | |
ok 2125 - doc/Type/Map.pod6 chunk 6 compiles | |
# my $map = Map.new('a', 1, 'b', 2); | |
# say $map{'a'}; # OUTPUT: «1» | |
ok 2126 - doc/Type/Map.pod6 chunk 7 compiles | |
# my $map = Map.new('a', 1, 'b', 2); | |
# my $key = 'a'; | |
# if $map{$key}:exists { | |
# say "$map{} has key $key"; | |
# } | |
ok 2127 - doc/Type/Map.pod6 chunk 8 compiles | |
# method keys(Map:D: --> List:D) | |
ok 2128 - doc/Type/Map.pod6 chunk 9 compiles | |
# my $m = Map.new('a' => (2, 3), 'b' => 17); | |
# say $m.keys; # OUTPUT: «(a b)» | |
ok 2129 - doc/Type/Map.pod6 chunk 10 compiles | |
# method values(Map:D: --> List:D) | |
ok 2130 - doc/Type/Map.pod6 chunk 11 compiles | |
# my $m = Map.new('a' => (2, 3), 'b' => 17); | |
# say $m.values; # OUTPUT: «((2 3) 17)» | |
ok 2131 - doc/Type/Map.pod6 chunk 12 compiles | |
# method pairs(Map:D: --> List:D) | |
ok 2132 - doc/Type/Map.pod6 chunk 13 compiles | |
# my $m = Map.new('a' => (2, 3), 'b' => 17); | |
# say $m.pairs; # OUTPUT: «(a => (2 3) b => 17)» | |
ok 2133 - doc/Type/Map.pod6 chunk 14 compiles | |
# method antipairs(Map:D: --> Seq:D) | |
ok 2134 - doc/Type/Map.pod6 chunk 15 compiles | |
# my $m = Map.new('a' => (2, 3), 'b' => 17); | |
# say $m.antipairs; # OUTPUT: «((2 3) => a 17 => b)» | |
ok 2135 - doc/Type/Map.pod6 chunk 16 compiles | |
# method invert(Map:D: --> Seq:D) | |
ok 2136 - doc/Type/Map.pod6 chunk 17 compiles | |
# my $m = Map.new('a' => (2, 3), 'b' => 17); | |
# say $m.invert; # OUTPUT: «(2 => a 3 => a 17 => b)» | |
ok 2137 - doc/Type/Map.pod6 chunk 18 compiles | |
# method kv(Map:D: --> List:D) | |
ok 2138 - doc/Type/Map.pod6 chunk 19 compiles | |
# Map.new('a', 1, 'b', 2).kv # (a 1 b 2) | |
ok 2139 - doc/Type/Map.pod6 chunk 20 compiles | |
# method Int(Map:D: --> Int:D) | |
ok 2140 - doc/Type/Map.pod6 chunk 21 compiles | |
# my $m = Map.new('a' => 2, 'b' => 17); | |
# say $m.Int; # OUTPUT: «2» | |
ok 2141 - doc/Type/Map.pod6 chunk 22 compiles | |
# method Numeric(Map:D: --> Int:D) | |
ok 2142 - doc/Type/Map.pod6 chunk 23 compiles | |
# my $m = Map.new('a' => 2, 'b' => 17); | |
# say $m.Numeric; # OUTPUT: «2» | |
ok 2143 - doc/Type/Map.pod6 chunk 24 compiles | |
# method Bool(Map:D: --> Bool:D) | |
ok 2144 - doc/Type/Map.pod6 chunk 25 compiles | |
# my $m = Map.new('a' => 2, 'b' => 17); | |
# say $m.Bool; # OUTPUT: «True» | |
ok 2145 - doc/Type/Map.pod6 chunk 26 compiles | |
# method Capture(Map:D: --> Capture:D) | |
ok 2146 - doc/Type/Map.pod6 chunk 27 compiles | |
# my $map = Map.new('a' => 2, 'b' => 17); | |
# my $capture = $map.Capture; | |
# my-sub(|$capture); # RESULT: «2, 17» | |
# sub my-sub(:$a, :$b) { | |
# say "$a, $b" | |
# } | |
ok 2147 - doc/Type/Map.pod6 chunk 28 compiles | |
# class Match is Capture is Cool {} | |
ok 2148 - doc/Type/Match.pod6 chunk 1 compiles | |
# method Bool(Capture:D: --> Bool:D) | |
ok 2149 - doc/Type/Match.pod6 chunk 2 compiles | |
# say 'abc' ~~ /^/; # OUTPUT: «「」» | |
# say $/.from, ' ', $/.to, ' ', ?$/; # OUTPUT: «0 0 True» | |
ok 2150 - doc/Type/Match.pod6 chunk 3 compiles | |
# method Str(Match:D: --> Str:D) | |
ok 2151 - doc/Type/Match.pod6 chunk 4 compiles | |
# "abc123def" ~~ /\d+/; | |
# say $/.Str; # OUTPUT: «123» | |
ok 2152 - doc/Type/Match.pod6 chunk 5 compiles | |
# method prematch(Match:D: --> Str:D) | |
ok 2153 - doc/Type/Match.pod6 chunk 6 compiles | |
# 'abcdefg' ~~ /cd/; | |
# say $/.prematch; # OUTPUT: «ab» | |
# # will return a list of three match objects | |
# "abc123def" ~~ m:g/\d/; | |
# say $/.[1].prematch; # OUTPUT: «abc1» | |
ok 2154 - doc/Type/Match.pod6 chunk 7 compiles | |
# method postmatch(Match:D: --> Str:D) | |
ok 2155 - doc/Type/Match.pod6 chunk 8 compiles | |
# 'abcdefg' ~~ /cd/; | |
# say $/.postmatch; # OUTPUT: «efg» | |
# # will return a list of three match objects | |
# "abc123def" ~~ m:g/\d/; | |
# say $/.[1].postmatch; # OUTPUT: «3def» | |
ok 2156 - doc/Type/Match.pod6 chunk 9 compiles | |
# method make(Match:D: Mu $ast) | |
# sub make(Mu $ast) | |
ok 2157 - doc/Type/Match.pod6 chunk 10 compiles | |
# method my-action ($/) { | |
# make "foo: $/"; | |
# } | |
ok 2158 - doc/Type/Match.pod6 chunk 11 compiles | |
# role Metamodel::AttributeContainer {} | |
ok 2159 - doc/Type/Metamodel/AttributeContainer.pod6 chunk 1 compiles | |
# method add_attribute(Metamodel::AttributeContainer: $obj, $name, $attribute) | |
ok 2160 - doc/Type/Metamodel/AttributeContainer.pod6 chunk 2 compiles | |
# method attributes(Metamodel::AttributeContainer: $obj) | |
ok 2161 - doc/Type/Metamodel/AttributeContainer.pod6 chunk 3 compiles | |
# method set_rw(Metamodel::AttributeContainer: $obj) | |
ok 2162 - doc/Type/Metamodel/AttributeContainer.pod6 chunk 4 compiles | |
# class Point is rw { | |
# has $.x; | |
# has $.y; | |
# } | |
ok 2163 - doc/Type/Metamodel/AttributeContainer.pod6 chunk 5 compiles | |
# method rw(Metamodel::AttributeContainer: $obj) | |
ok 2164 - doc/Type/Metamodel/AttributeContainer.pod6 chunk 6 compiles | |
# role Metamodel::C3MRO { } | |
ok 2165 - doc/Type/Metamodel/C3MRO.pod6 chunk 1 compiles | |
# class CommonAncestor { }; # implicitly inherits from Any | |
# class Child1 is CommonAncestor { } | |
# class Child2 is CommonAncestor { } | |
# class GrandChild2 is Child2 { } | |
# class Weird is Child1 is GrandChild2 { }; | |
# say Weird.^mro; # OUTPUT: «(Weird) (Child1) (GrandChild2) (Child2) (CommonAncestor) (Any) (Mu)» | |
ok 2166 - doc/Type/Metamodel/C3MRO.pod6 chunk 2 compiles | |
# method compute_mro($type) | |
ok 2167 - doc/Type/Metamodel/C3MRO.pod6 chunk 3 compiles | |
# method mro($type) | |
ok 2168 - doc/Type/Metamodel/C3MRO.pod6 chunk 4 compiles | |
# say Int.^mro; # OUTPUT: «((Int) (Cool) (Any) (Mu))» | |
ok 2169 - doc/Type/Metamodel/C3MRO.pod6 chunk 5 compiles | |
# method mro_unhidden($type) | |
ok 2170 - doc/Type/Metamodel/C3MRO.pod6 chunk 6 compiles | |
# class Metamodel::ClassHOW | |
# does Metamodel::Naming | |
# does Metamodel::Documenting | |
# does Metamodel::Versioning | |
# does Metamodel::Stashing | |
# does Metamodel::AttributeContainer | |
# does Metamodel::MethodContainer | |
# does Metamodel::PrivateMethodContainer | |
# does Metamodel::MultiMethodContainer | |
# does Metamodel::RoleContainer | |
# does Metamodel::MultipleInheritance | |
# does Metamodel::DefaultParent | |
# does Metamodel::C3MRO | |
# does Metamodel::MROBasedMethodDispatch | |
# does Metamodel::MROBasedTypeChecking | |
# does Metamodel::Trusting | |
# does Metamodel::BUILDPLAN | |
# does Metamodel::Mixins | |
# does Metamodel::ArrayType | |
# does Metamodel::BoolificationProtocol | |
# does Metamodel::REPRComposeProtocol | |
# does Metamodel::InvocationProtocol | |
# does Metamodel::Finalization | |
# { } | |
ok 2171 - doc/Type/Metamodel/ClassHOW.pod6 chunk 1 compiles | |
# say so Int.HOW ~~ Metamodel::ClassHOW; # OUTPUT: «True» | |
# say Int.^methods(:all).pick.name; # OUTPUT: «random Int method name» | |
ok 2172 - doc/Type/Metamodel/ClassHOW.pod6 chunk 2 compiles | |
# method add_fallback(Metamodel::ClassHOW:D: $condition, $calculator) | |
ok 2173 - doc/Type/Metamodel/ClassHOW.pod6 chunk 3 compiles | |
# method can(Metamodel::ClassHOW:D: $obj, $method-name) | |
ok 2174 - doc/Type/Metamodel/ClassHOW.pod6 chunk 4 compiles | |
# class A { method x($a) {} }; | |
# class B is A { method x() {} }; | |
# say B.^can('x').elems; # OUTPUT: «2» | |
# for B.^can('x') { | |
# say .arity; # OUTPUT: «1, 2» | |
# } | |
ok 2175 - doc/Type/Metamodel/ClassHOW.pod6 chunk 5 compiles | |
# method lookup(Metamodel::ClassHOW:D: $obj, $method-name --> Method) | |
ok 2176 - doc/Type/Metamodel/ClassHOW.pod6 chunk 6 compiles | |
# say Str.^lookup('Int').perl; # OUTPUT: «method Int (Str:D $: *%_) { #`(Method|39910024) ... }» | |
ok 2177 - doc/Type/Metamodel/ClassHOW.pod6 chunk 7 compiles | |
# method compose(Metamodel::ClassHOW:D: $obj) | |
ok 2178 - doc/Type/Metamodel/ClassHOW.pod6 chunk 8 compiles | |
# role Metamodel::Finalization { ... } | |
ok 2179 - doc/Type/Metamodel/Finalization.pod6 chunk 1 compiles | |
# method setup_finalization(Metamodel::Finalization:D: $obj) | |
ok 2180 - doc/Type/Metamodel/Finalization.pod6 chunk 2 compiles | |
# method destroyers(Metamodel::Finalization:D: $obj --> List:D) | |
ok 2181 - doc/Type/Metamodel/Finalization.pod6 chunk 3 compiles | |
# role Metamodel::MROBasedMethodDispatch { ... } | |
ok 2182 - doc/Type/Metamodel/MROBasedMethodDispatch.pod6 chunk 1 compiles | |
# method find_method(Metamodel::MROBasedMethodDispatch:D: $obj, $name, $no_fallback) | |
ok 2183 - doc/Type/Metamodel/MROBasedMethodDispatch.pod6 chunk 2 compiles | |
# method find_method(Metamodel::MROBasedMethodDispatch:D: $obj, $type, $name) | |
ok 2184 - doc/Type/Metamodel/MROBasedMethodDispatch.pod6 chunk 3 compiles | |
# class Metamodel::MethodContainer {} | |
ok 2185 - doc/Type/Metamodel/MethodContainer.pod6 chunk 1 compiles | |
# say .name for Int.^methods(:all); | |
# # don't do that, because it changes type Int globally. | |
# # just for demonstration purposes. | |
# Int.^add_method('double', method ($x:) { 2 * $x }); | |
# say 21.double; # OUTPUT: «42» | |
ok 2186 - doc/Type/Metamodel/MethodContainer.pod6 chunk 2 compiles | |
# method add_method(Metamodel::MethodContainer: $obj, $name, $code) | |
ok 2187 - doc/Type/Metamodel/MethodContainer.pod6 chunk 3 compiles | |
# method methods(Metamodel::MethodContainer: $obj, :$all, :$local) | |
ok 2188 - doc/Type/Metamodel/MethodContainer.pod6 chunk 4 compiles | |
# class A { | |
# method x() { }; | |
# } | |
# say A.^methods(); # x | |
# say A.^methods(:all); # x infinite defined ... | |
ok 2189 - doc/Type/Metamodel/MethodContainer.pod6 chunk 5 compiles | |
# method method_table(Metamodel::MethodContainer:D: $obj --> Hash:D) | |
ok 2190 - doc/Type/Metamodel/MethodContainer.pod6 chunk 6 compiles | |
# role Metamodel::MultipleInheritance { ... } | |
ok 2191 - doc/Type/Metamodel/MultipleInheritance.pod6 chunk 1 compiles | |
# method add_parent(Metamodel::MultipleInheritance:D: $Obj, $parent, :$hides) | |
ok 2192 - doc/Type/Metamodel/MultipleInheritance.pod6 chunk 2 compiles | |
# method parents(Metamodel::MultipleInheritance:D: $obj, :$all, :$tree) | |
ok 2193 - doc/Type/Metamodel/MultipleInheritance.pod6 chunk 3 compiles | |
# class D { }; | |
# class C1 is D { }; | |
# class C2 is D { }; | |
# class B is C1 is C2 { }; | |
# class A is B { }; | |
# say A.^parents(:all).perl; | |
# # OUTPUT: «(B, C1, C2, D, Any, Mu)» | |
# say A.^parents(:all, :tree).perl; | |
# # OUTPUT: «[B, ([C1, [D, [Any, [Mu]]]], [C2, [D, [Any, [Mu]]]])]» | |
ok 2194 - doc/Type/Metamodel/MultipleInheritance.pod6 chunk 4 compiles | |
# method hides(Metamodel::MultipleInheritance:D: $obj) | |
ok 2195 - doc/Type/Metamodel/MultipleInheritance.pod6 chunk 5 compiles | |
# method hidden(Metamodel::MultipleInheritance:D: $obj) | |
ok 2196 - doc/Type/Metamodel/MultipleInheritance.pod6 chunk 6 compiles | |
# method set_hidden(Metamodel::MultipleInheritance:D: $obj) | |
ok 2197 - doc/Type/Metamodel/MultipleInheritance.pod6 chunk 7 compiles | |
# role Metamodel::Naming { } | |
ok 2198 - doc/Type/Metamodel/Naming.pod6 chunk 1 compiles | |
# method name($type) | |
ok 2199 - doc/Type/Metamodel/Naming.pod6 chunk 2 compiles | |
# say 42.^name; # OUTPUT: «Int» | |
ok 2200 - doc/Type/Metamodel/Naming.pod6 chunk 3 compiles | |
# method set_name($type, $new_name) | |
ok 2201 - doc/Type/Metamodel/Naming.pod6 chunk 4 compiles | |
# my Mu $type := Metamodel::Primitives.create_type(Int.HOW, 'P6opaque'); | |
# $type.^set_name('why oh why?'); | |
# my %methods = why => sub ($) { say 42 }; | |
# Metamodel::Primitives.install_method_cache($type, %methods, :authoritative); | |
# $type.why; # 42 | |
# $type.list; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Method::NotFound: Method 'list' not found for invocant of class 'why oh why?'» | |
ok 2202 - doc/Type/Metamodel/Primitives.pod6 chunk 1 compiles | |
# method create_type(Mu $how, $repr = 'P6opaque') | |
ok 2203 - doc/Type/Metamodel/Primitives.pod6 chunk 2 compiles | |
# method set_package(Mu $type, $package) | |
ok 2204 - doc/Type/Metamodel/Primitives.pod6 chunk 3 compiles | |
# method install_method_cache( Mu $type, %cache, :$authoritative = True) | |
ok 2205 - doc/Type/Metamodel/Primitives.pod6 chunk 4 compiles | |
# method configure_destroy(Mu $type, $destroy) | |
ok 2206 - doc/Type/Metamodel/Primitives.pod6 chunk 5 compiles | |
# method compose_type(Mu $type, $configuration) | |
ok 2207 - doc/Type/Metamodel/Primitives.pod6 chunk 6 compiles | |
# method rebless(Mu $object, Mu $type) | |
ok 2208 - doc/Type/Metamodel/Primitives.pod6 chunk 7 compiles | |
# method is_type(Mu \obj, Mu \type --> Bool:D) | |
ok 2209 - doc/Type/Metamodel/Primitives.pod6 chunk 8 compiles | |
# role Metamodel::PrivateMethodContainer { ... } | |
ok 2210 - doc/Type/Metamodel/PrivateMethodContainer.pod6 chunk 1 compiles | |
# class A { | |
# # the ! declares a private method | |
# method !double($x) { | |
# say 2 * $x; | |
# } | |
# method call-double($y) { | |
# # call with ! instead of . | |
# self!double($y); | |
# } | |
# } | |
ok 2211 - doc/Type/Metamodel/PrivateMethodContainer.pod6 chunk 2 compiles | |
# method add_private_method(Metamodel::PrivateMethodContainer: $obj, $name, $code) | |
ok 2212 - doc/Type/Metamodel/PrivateMethodContainer.pod6 chunk 3 compiles | |
# method private_method_table(Metamodel::PrivateMethodContainer: $obj) | |
ok 2213 - doc/Type/Metamodel/PrivateMethodContainer.pod6 chunk 4 compiles | |
# role Metamodel::RoleContainer {} | |
ok 2214 - doc/Type/Metamodel/RoleContainer.pod6 chunk 1 compiles | |
# method add_role(Metamodel::RoleContainer:D: $obj, Mu $role) | |
ok 2215 - doc/Type/Metamodel/RoleContainer.pod6 chunk 2 compiles | |
# method roles_to_compose(Metamodel::RoleContainer:D: $obj --> List:D) | |
ok 2216 - doc/Type/Metamodel/RoleContainer.pod6 chunk 3 compiles | |
# class A { | |
# my class B { | |
# trusts A; # that's where Metamodel::Trusting comes in | |
# method !private_method() { | |
# say "Private method in B"; | |
# } | |
# } | |
# method build-and-poke { | |
# # call a private method from B | |
# # disallowed if A doesn't trust B | |
# B.new()!B::private_method(); | |
# } | |
# }; | |
# A.build-and-poke; # Private method in A | |
ok 2217 - doc/Type/Metamodel/Trusting.pod6 chunk 1 compiles | |
# method add_trustee(Metamodel::Trusting:D: $type, Mu $trustee) | |
ok 2218 - doc/Type/Metamodel/Trusting.pod6 chunk 2 compiles | |
# method trusts(Metamodel::Trusting:D: $type --> List) | |
ok 2219 - doc/Type/Metamodel/Trusting.pod6 chunk 3 compiles | |
# class A { trusts Int; }; | |
# say .^name for A.^trusts; # Int | |
ok 2220 - doc/Type/Metamodel/Trusting.pod6 chunk 4 compiles | |
# method is_trusted(Metamodel::Trusting:D: $type, $claimant) | |
ok 2221 - doc/Type/Metamodel/Trusting.pod6 chunk 5 compiles | |
# class Method is Routine { } | |
ok 2222 - doc/Type/Method.pod6 chunk 1 compiles | |
# my $m = method ($invocant: $param) { | |
# say "$invocant: '$param'"; | |
# } | |
# "greeting".$m("hello"); # greeting: 'hello' | |
# <a b c>.&(my method (List:D:){dd self; self}).say; | |
# # OUTPUT: «("a", "b", "c")(a b c)» | |
ok 2223 - doc/Type/Method.pod6 chunk 2 compiles | |
# my method m(Int:D: $b){ | |
# say self.^name | |
# } | |
# my $i = 1; | |
# $i.&m(<a>); | |
# # OUTPUT: «Int» | |
ok 2224 - doc/Type/Method.pod6 chunk 3 compiles | |
# class A { | |
# multi method m(:$a, :$b) { say "2 named" } | |
# } | |
# class B is A { | |
# method m(:$a) { say "1 named"; nextsame } | |
# } | |
# B.m( :1a, :2b ); | |
# # OUTPUT: «1 named2 named» | |
ok 2225 - doc/Type/Method.pod6 chunk 4 compiles | |
# sub lastcall(--> True) | |
ok 2226 - doc/Type/Method.pod6 chunk 5 compiles | |
# class Mix does Mixy { } | |
ok 2227 - doc/Type/Mix.pod6 chunk 1 compiles | |
# my $recipe = (butter => 0.22, sugar => 0.1, | |
# flour => 0.275, sugar => 0.02).Mix; | |
# say $recipe.elems; # OUTPUT: «3» | |
# say $recipe.keys.sort; # OUTPUT: «butter flour sugar» | |
# say $recipe.pairs.sort; # OUTPUT: «"butter" => 0.22 "flour" => 0.275 "sugar" => 0.12» | |
# say $recipe.total; # OUTPUT: «0.615» | |
ok 2228 - doc/Type/Mix.pod6 chunk 2 compiles | |
# my $recipe = (butter => 0.22, sugar => 0.1, | |
# flour => 0.275, sugar => 0.02).Mix; | |
# say $recipe<butter>; # OUTPUT: «0.22» | |
# say $recipe<sugar>; # OUTPUT: «0.12» | |
# say $recipe<chocolate>; # OUTPUT: «0» | |
ok 2229 - doc/Type/Mix.pod6 chunk 3 compiles | |
# my $n = mix "a", "a", "b" => 0, "c" => 3.14; | |
# say $n.keys.map(&WHAT); # OUTPUT: «((Str) (Pair) (Pair))» | |
# say $n.pairs; # OUTPUT: «(a => 2 (c => 3.14) => 1 (b => 0) => 1)» | |
ok 2230 - doc/Type/Mix.pod6 chunk 4 compiles | |
# my $n = ("a", "a", "b" => 0, "c" => 3.14).Mix; | |
# say $n.keys.map(&WHAT); # OUTPUT: «((Str) (Str))» | |
# say $n.pairs; # OUTPUT: «(a => 2 c => 3.14)» | |
ok 2231 - doc/Type/Mix.pod6 chunk 5 compiles | |
# sub mix(*@args --> Mix) | |
ok 2232 - doc/Type/Mix.pod6 chunk 6 compiles | |
# method Bag (--> Bag:D) | |
ok 2233 - doc/Type/Mix.pod6 chunk 7 compiles | |
# method BagHash (--> BagHash:D) | |
ok 2234 - doc/Type/Mix.pod6 chunk 8 compiles | |
# class MixHash does Mixy { } | |
ok 2235 - doc/Type/MixHash.pod6 chunk 1 compiles | |
# my $recipe = (butter => 0.22, sugar => 0.1, | |
# flour => 0.275, sugar => 0.02).MixHash; | |
# say $recipe.elems; # OUTPUT: «3» | |
# say $recipe.keys.sort; # OUTPUT: «butter flour sugar» | |
# say $recipe.pairs.sort; # OUTPUT: «"butter" => 0.22 "flour" => 0.275 "sugar" => 0.12» | |
# say $recipe.total; # OUTPUT: «0.615» | |
ok 2236 - doc/Type/MixHash.pod6 chunk 2 compiles | |
# my $recipe = (butter => 0.22, sugar => 0.1, | |
# flour => 0.275, sugar => 0.02).MixHash; | |
# say $recipe<butter>; # OUTPUT: «0.22» | |
# say $recipe<sugar>; # OUTPUT: «0.12» | |
# say $recipe<chocolate>; # OUTPUT: «0» | |
# $recipe<butter> = 0; | |
# $recipe<chocolate> = 0.30; | |
# say $recipe.pairs; # OUTPUT: «"sugar" => 0.12 "flour" => 0.275 "chocolate" => 0.3» | |
ok 2237 - doc/Type/MixHash.pod6 chunk 3 compiles | |
# my $n = MixHash.new: "a", "a", "b" => 0, "c" => 3.14; | |
# say $n.keys.map(&WHAT); # OUTPUT: «((Str) (Pair) (Pair))» | |
# say $n.pairs; # OUTPUT: «(a => 2 (c => 3.14) => 1 (b => 0) => 1)» | |
ok 2238 - doc/Type/MixHash.pod6 chunk 4 compiles | |
# my $n = ("a", "a", "b" => 0, "c" => 3.14).MixHash; | |
# say $n.keys.map(&WHAT); # OUTPUT: «((Str) (Str))» | |
# say $n.pairs; # OUTPUT: «(a => 2 c => 3.14)» | |
ok 2239 - doc/Type/MixHash.pod6 chunk 5 compiles | |
# method Bag (--> Bag:D) | |
ok 2240 - doc/Type/MixHash.pod6 chunk 6 compiles | |
# method BagHash (--> BagHash:D) | |
ok 2241 - doc/Type/MixHash.pod6 chunk 7 compiles | |
# role Mixy does Baggy { } | |
ok 2242 - doc/Type/Mixy.pod6 chunk 1 compiles | |
# method total(--> Real) | |
ok 2243 - doc/Type/Mixy.pod6 chunk 2 compiles | |
WARNINGS for /Users/williamcoleda/sandbox/doc/EVAL_2246: | |
Useless use of "==" in expression ".total == 6" in sink context (line 2) | |
# mix('a', 'b', 'c', 'a', 'a', 'd').total == 6; # RESULT: «True» | |
# {a => 5.6, b => 2.4}.Mix.total == 8; # RESULT: «True» | |
ok 2244 - doc/Type/Mixy.pod6 chunk 3 compiles | |
# method roll($count = 1) | |
ok 2245 - doc/Type/Mixy.pod6 chunk 4 compiles | |
# class Mu { } | |
ok 2246 - doc/Type/Mu.pod6 chunk 1 compiles | |
# multi sub defined(Mu --> Bool:D) | |
# multi method defined( --> Bool:D) | |
ok 2247 - doc/Type/Mu.pod6 chunk 2 compiles | |
# say Int.defined; # OUTPUT: «False» | |
# say 42.defined; # OUTPUT: «True» | |
ok 2248 - doc/Type/Mu.pod6 chunk 3 compiles | |
# sub fails() { fail 'oh noe' }; | |
# say fails().defined; # OUTPUT: «False» | |
ok 2249 - doc/Type/Mu.pod6 chunk 4 compiles | |
# multi method isa(Mu $type --> Bool:D) | |
# multi method isa(Str:D $type --> Bool:D) | |
ok 2250 - doc/Type/Mu.pod6 chunk 5 compiles | |
# my $i = 17; | |
# say $i.isa("Int"); # OUTPUT: «True» | |
# say $i.isa(Any); # OUTPUT: «True» | |
ok 2251 - doc/Type/Mu.pod6 chunk 6 compiles | |
# my $s = "String"; | |
# say $s ~~ Str; # OUTPUT: «True» | |
ok 2252 - doc/Type/Mu.pod6 chunk 7 compiles | |
# method does(Mu $type --> Bool:D) | |
ok 2253 - doc/Type/Mu.pod6 chunk 8 compiles | |
# my $d = Date.new('2016-06-03'); | |
# say $d.does(Dateish); # True (Date does role Dateish) | |
# say $d.does(Any); # True (Date is a subclass of Any) | |
# say $d.does(DateTime); # False (Date is not a subclass of DateTime) | |
ok 2254 - doc/Type/Mu.pod6 chunk 9 compiles | |
# my $d = Date.new('2016-06-03'); | |
# say $d ~~ Dateish; # OUTPUT: «True» | |
# say $d ~~ Any; # OUTPUT: «True» | |
# say $d ~~ DateTime; # OUTPUT: «False» | |
ok 2255 - doc/Type/Mu.pod6 chunk 10 compiles | |
# multi sub Bool(Mu --> Bool:D) | |
# multi method Bool( --> Bool:D) | |
ok 2256 - doc/Type/Mu.pod6 chunk 11 compiles | |
# say Mu.Bool; # OUTPUT: «False» | |
# say Mu.new.Bool; # OUTPUT: «True» | |
# say [1, 2, 3].Bool; # OUTPUT: «True» | |
# say [].Bool; # OUTPUT: «False» | |
# say { 'hash' => 'full' }.Bool; # OUTPUT: «True» | |
# say {}.Bool; # OUTPUT: «False» | |
# say "".Bool; # OUTPUT: «False» | |
# say 0.Bool; # OUTPUT: «False» | |
# say 1.Bool; # OUTPUT: «True» | |
# say "0".Bool; # OUTPUT: «True» | |
ok 2257 - doc/Type/Mu.pod6 chunk 12 compiles | |
# multi method Str(--> Str) | |
ok 2258 - doc/Type/Mu.pod6 chunk 13 compiles | |
# say Mu.Str; # Use of uninitialized value of type Mu in string context. | |
ok 2259 - doc/Type/Mu.pod6 chunk 14 compiles | |
# multi sub gist(Mu --> Str) | |
# multi method gist( --> Str) | |
ok 2260 - doc/Type/Mu.pod6 chunk 15 compiles | |
# say Mu.gist; # OUTPUT: «(Mu)» | |
# say Mu.new.gist; # OUTPUT: «Mu.new» | |
ok 2261 - doc/Type/Mu.pod6 chunk 16 compiles | |
# multi sub perl(Mu --> Str) | |
# multi method perl( --> Str) | |
ok 2262 - doc/Type/Mu.pod6 chunk 17 compiles | |
# method item(Mu \item:) is raw | |
ok 2263 - doc/Type/Mu.pod6 chunk 18 compiles | |
# say [1,2,3].item.perl; # OUTPUT: «$[1, 2, 3]» | |
# say { apple => 10 }.item.perl; # OUTPUT: «${:apple(10)}» | |
# say "abc".item.perl; # OUTPUT: «"abc"» | |
ok 2264 - doc/Type/Mu.pod6 chunk 19 compiles | |
# method self(--> Mu) | |
ok 2265 - doc/Type/Mu.pod6 chunk 20 compiles | |
# method clone(*%twiddles) | |
ok 2266 - doc/Type/Mu.pod6 chunk 21 compiles | |
# class Point2D { | |
# has ($.x, $.y); | |
# multi method gist(Point2D:D:) { | |
# "Point($.x, $.y)"; | |
# } | |
# } | |
# my $p = Point2D.new(x => 2, y => 3); | |
# say $p; # OUTPUT: «Point(2, 3)» | |
# say $p.clone(y => -5); # OUTPUT: «Point(2, -5)» | |
ok 2267 - doc/Type/Mu.pod6 chunk 22 compiles | |
# multi method new(*%attrinit) | |
ok 2268 - doc/Type/Mu.pod6 chunk 23 compiles | |
# method bless(*%attrinit --> Mu:D) | |
ok 2269 - doc/Type/Mu.pod6 chunk 24 compiles | |
# class Point { | |
# has $.x; | |
# has $.y; | |
# multi method new($x, $y) { | |
# self.bless(:$x, :$y); | |
# } | |
# } | |
# my $p = Point.new(-1, 1); | |
ok 2270 - doc/Type/Mu.pod6 chunk 25 compiles | |
# method CREATE(--> Mu:D) | |
ok 2271 - doc/Type/Mu.pod6 chunk 26 compiles | |
# say Mu.CREATE.defined; # OUTPUT: «True» | |
ok 2272 - doc/Type/Mu.pod6 chunk 27 compiles | |
# multi method print(--> Bool:D) | |
ok 2273 - doc/Type/Mu.pod6 chunk 28 compiles | |
# "abc\n".print; # RESULT: «abc» | |
ok 2274 - doc/Type/Mu.pod6 chunk 29 compiles | |
# multi method put(--> Bool:D) | |
ok 2275 - doc/Type/Mu.pod6 chunk 30 compiles | |
# "abc".put; # RESULT: «abc» | |
ok 2276 - doc/Type/Mu.pod6 chunk 31 compiles | |
# multi method say(--> Bool:D) | |
ok 2277 - doc/Type/Mu.pod6 chunk 32 compiles | |
# say 42; # OUTPUT: «42» | |
ok 2278 - doc/Type/Mu.pod6 chunk 33 compiles | |
# multi method ACCEPTS(Mu:U: $other) | |
ok 2279 - doc/Type/Mu.pod6 chunk 34 compiles | |
# say 42 ~~ Mu; # OUTPUT: «True» | |
# say 42 ~~ Int; # OUTPUT: «True» | |
# say 42 ~~ Str; # OUTPUT: «False» | |
ok 2280 - doc/Type/Mu.pod6 chunk 35 compiles | |
# multi method WHICH(--> ObjAt:D) | |
ok 2281 - doc/Type/Mu.pod6 chunk 36 compiles | |
# say 42.WHICH eq 42.WHICH; # OUTPUT: «True» | |
ok 2282 - doc/Type/Mu.pod6 chunk 37 compiles | |
# method WHERE(--> Int) | |
ok 2283 - doc/Type/Mu.pod6 chunk 38 compiles | |
# multi method WHY() | |
ok 2284 - doc/Type/Mu.pod6 chunk 39 compiles | |
# multi sub trait_mod:<is>(Mu:U \type, :$export!) | |
ok 2285 - doc/Type/Mu.pod6 chunk 40 compiles | |
# my class SomeClass is export { } | |
ok 2286 - doc/Type/Mu.pod6 chunk 41 compiles | |
# method return() | |
ok 2287 - doc/Type/Mu.pod6 chunk 42 compiles | |
# sub f { (1|2|3).return }; | |
# dd f(); # OUTPUT: «any(1, 2, 3)» | |
ok 2288 - doc/Type/Mu.pod6 chunk 43 compiles | |
# method emit() | |
ok 2289 - doc/Type/Mu.pod6 chunk 44 compiles | |
# react { whenever supply { .emit for "foo", 42, .5 } { | |
# say "received {.^name} ($_)"; | |
# }} | |
# # OUTPUT: | |
# # received Str (foo) | |
# # received Int (42) | |
# # received Rat (0.5) | |
ok 2290 - doc/Type/Mu.pod6 chunk 45 compiles | |
# method take() | |
ok 2291 - doc/Type/Mu.pod6 chunk 46 compiles | |
# sub insert($sep, +@list) { | |
# gather for @list { | |
# FIRST .take, next; | |
# take slip $sep, .item | |
# } | |
# } | |
# say insert ':', <a b c>; | |
# # OUTPUT: «(a : b : c)» | |
ok 2292 - doc/Type/Mu.pod6 chunk 47 compiles | |
# sub take(\item) | |
ok 2293 - doc/Type/Mu.pod6 chunk 48 compiles | |
# #| randomly select numbers for lotto | |
# my $num-selected-numbers = 6; | |
# my $max-lotto-numbers = 49; | |
# gather for ^$num-selected-numbers { | |
# take (1 .. $max-lotto-numbers).pick(1); | |
# }.say; # six random values | |
ok 2294 - doc/Type/Mu.pod6 chunk 49 compiles | |
# sub take-rw(\item) | |
ok 2295 - doc/Type/Mu.pod6 chunk 50 compiles | |
# my @a = 1...3; | |
# sub f(@list){ gather for @list { take-rw $_ } }; | |
# for f(@a) { $_++ }; | |
# say @a; | |
# # OUTPUT: «[2 3 4]» | |
ok 2296 - doc/Type/Mu.pod6 chunk 51 compiles | |
# method so() | |
ok 2297 - doc/Type/Mu.pod6 chunk 52 compiles | |
# my @args = <-a -e -b -v>; | |
# my $verbose-selected = any(@args) eq '-v' | '-V'; | |
# if $verbose-selected.so { | |
# say "Verbose option detected in arguments"; | |
# } # OUTPUT: «Verbose option detected in arguments» | |
ok 2298 - doc/Type/Mu.pod6 chunk 53 compiles | |
# method not() | |
ok 2299 - doc/Type/Mu.pod6 chunk 54 compiles | |
# my @args = <-a -e -b>; | |
# my $verbose-selected = any(@args) eq '-v' | '-V'; | |
# if $verbose-selected.not { | |
# say "Verbose option not present in arguments"; | |
# } # OUTPUT: «Verbose option not present in arguments» | |
ok 2300 - doc/Type/Mu.pod6 chunk 55 compiles | |
# my @args = <-a -e -b>; | |
# my $verbose-selected = any(@args) eq '-v' | '-V'; | |
# if not $verbose-selected { | |
# say "Verbose option not present in arguments"; | |
# } # OUTPUT: «Verbose option not present in arguments» | |
ok 2301 - doc/Type/Mu.pod6 chunk 56 compiles | |
# class NFC is Uni {} | |
ok 2302 - doc/Type/NFC.pod6 chunk 1 compiles | |
# class NFD is Uni {} | |
ok 2303 - doc/Type/NFD.pod6 chunk 1 compiles | |
# class NFKC is Uni {} | |
ok 2304 - doc/Type/NFKC.pod6 chunk 1 compiles | |
# class NFKD is Uni {} | |
ok 2305 - doc/Type/NFKD.pod6 chunk 1 compiles | |
# class Nil is Cool { } | |
ok 2306 - doc/Type/Nil.pod6 chunk 1 compiles | |
# say Nil === Nil.new; # OUTPUT: «True» | |
ok 2307 - doc/Type/Nil.pod6 chunk 2 compiles | |
# sub a( --> Int:D ) { return Nil } | |
# a().say; # OUTPUT: «Nil» | |
ok 2308 - doc/Type/Nil.pod6 chunk 3 compiles | |
# sub a { }; a().say; # OUTPUT: «Nil» | |
# sub b { return }; b().say; # OUTPUT: «Nil» | |
# say (if 1 { }); # OUTPUT: «Nil» | |
# { ; }().say; # OUTPUT: «Nil» | |
# say EVAL ""; # OUTPUT: «Nil» | |
ok 2309 - doc/Type/Nil.pod6 chunk 4 compiles | |
# (1, Nil, 3).elems.say; # OUTPUT: «3» | |
# (for Nil { $_ }).perl.say; # OUTPUT: «(Nil,)» | |
ok 2310 - doc/Type/Nil.pod6 chunk 5 compiles | |
# say Nil.ITotallyJustMadeThisUp; # OUTPUT: «Nil» | |
# say (Nil)[100]; # OUTPUT: «Nil» | |
# say (Nil){100}; # OUTPUT: «Nil» | |
ok 2311 - doc/Type/Nil.pod6 chunk 6 compiles | |
# my Int $x = 42; | |
# $x = Nil; | |
# $x.say; # OUTPUT: «(Int)» | |
# sub f( --> Int:D ){ Nil }; # this definedness constraint is ignored | |
# my Int:D $i = f; # this definedness constraint is not ignored, so throws | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::TypeCheck::Assignment: Type check failed in assignment to $y; expected Int but got Any (Any)» | |
# sub g( --> Int:D ){ fail "oops" }; # this definedness constraint is ignored | |
# my Any:D $h = g; # failure object matches Any:D, so is assigned | |
ok 2312 - doc/Type/Nil.pod6 chunk 7 compiles | |
# my $x = Nil; | |
# $x.say; # OUTPUT: «(Any)» | |
# my Int $y = $x; # will throw an exception | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::TypeCheck::Assignment: Type check failed in assignment to $y; expected Int but got Any (Any)» | |
ok 2313 - doc/Type/Nil.pod6 chunk 8 compiles | |
# my Nil $x; | |
# my Str $s = $x; | |
# $s.say; # OUTPUT: «(Str)» | |
ok 2314 - doc/Type/Nil.pod6 chunk 9 compiles | |
# my Int $x is default(42) = -1; | |
# my $y = 1; | |
# for $x, $y -> $val is rw { $val = Nil unless $val > 0 } | |
# $x.say; # OUTPUT: «42» | |
ok 2315 - doc/Type/Nil.pod6 chunk 10 compiles | |
# method append(*@) | |
ok 2316 - doc/Type/Nil.pod6 chunk 11 compiles | |
# method gist(--> Str:D) | |
ok 2317 - doc/Type/Nil.pod6 chunk 12 compiles | |
# method Str() | |
ok 2318 - doc/Type/Nil.pod6 chunk 13 compiles | |
# method new(*@) | |
ok 2319 - doc/Type/Nil.pod6 chunk 14 compiles | |
# method prepend(*@) | |
ok 2320 - doc/Type/Nil.pod6 chunk 15 compiles | |
# method push(*@) | |
ok 2321 - doc/Type/Nil.pod6 chunk 16 compiles | |
# method unshift(*@) | |
ok 2322 - doc/Type/Nil.pod6 chunk 17 compiles | |
# method Numeric() | |
ok 2323 - doc/Type/Nil.pod6 chunk 18 compiles | |
# class Num is Cool does Real { } | |
ok 2324 - doc/Type/Num.pod6 chunk 1 compiles | |
# method rand(Num:D: --> Num) | |
ok 2325 - doc/Type/Num.pod6 chunk 2 compiles | |
# sub srand(Int $seed --> Int:D) | |
ok 2326 - doc/Type/Num.pod6 chunk 3 compiles | |
# class NumStr is Num is Str { } | |
ok 2327 - doc/Type/NumStr.pod6 chunk 1 compiles | |
# my $f = <42.1e0>; say $f.WHAT; # OUTPUT: «(NumStr)» | |
ok 2328 - doc/Type/NumStr.pod6 chunk 2 compiles | |
# my $num-str = <42e10>; | |
# my Num $num = $num-str; # OK! | |
# my Str $str = $num-str; # OK! | |
# say 42e10 ∈ <42e10 55 1>; # False; ∈ operator cares about object identity | |
ok 2329 - doc/Type/NumStr.pod6 chunk 3 compiles | |
# method new(Num $i, Str $s) | |
ok 2330 - doc/Type/NumStr.pod6 chunk 4 compiles | |
# my $f = NumStr.new(42.1e0, "forty two and a bit"); | |
# say +$f; # OUTPUT: «42.1» | |
# say ~$f; # OUTPUT: «"forty two and a bit"» | |
ok 2331 - doc/Type/NumStr.pod6 chunk 5 compiles | |
# method Numeric | |
ok 2332 - doc/Type/NumStr.pod6 chunk 6 compiles | |
# method Num | |
ok 2333 - doc/Type/NumStr.pod6 chunk 7 compiles | |
# multi sub infix:<cmp>(NumStr:D $a, NumStr:D $b) | |
ok 2334 - doc/Type/NumStr.pod6 chunk 8 compiles | |
# my $f = NumStr.new(42.1e0, "smaller"); | |
# my $g = NumStr.new(43.1e0, "larger"); | |
# say $f cmp $g; # OUTPUT: «Less» | |
# say $f.Str cmp $g.Str; # OUTPUT: «More» | |
ok 2335 - doc/Type/NumStr.pod6 chunk 9 compiles | |
# role Numeric { ... } | |
ok 2336 - doc/Type/Numeric.pod6 chunk 1 compiles | |
# method Real(Numeric:D: --> Real:D) | |
ok 2337 - doc/Type/Numeric.pod6 chunk 2 compiles | |
# method Int(Numeric:D: --> Int:D) | |
ok 2338 - doc/Type/Numeric.pod6 chunk 3 compiles | |
# method Rat(Numeric:D: Real $epsilon = 1.0e-6 --> Rat:D) | |
ok 2339 - doc/Type/Numeric.pod6 chunk 4 compiles | |
# method Num(Numeric:D: --> Num:D) | |
ok 2340 - doc/Type/Numeric.pod6 chunk 5 compiles | |
# method narrow(Numeric:D --> Numeric:D) | |
ok 2341 - doc/Type/Numeric.pod6 chunk 6 compiles | |
# say (4.0 + 0i).narrow.perl; # OUTPUT: «4» | |
# say (4.0 + 0i).narrow.^name; # OUTPUT: «Int» | |
ok 2342 - doc/Type/Numeric.pod6 chunk 7 compiles | |
# multi method ACCEPTS(Numeric:D: $other) | |
ok 2343 - doc/Type/Numeric.pod6 chunk 8 compiles | |
# multi sub log(Numeric:D, Numeric $base = e --> Numeric:D) | |
# multi method log(Numeric:D: Numeric $base = e --> Numeric:D) | |
ok 2344 - doc/Type/Numeric.pod6 chunk 9 compiles | |
# multi sub log10(Numeric:D --> Numeric:D) | |
# multi method log10(Numeric:D: --> Numeric:D) | |
ok 2345 - doc/Type/Numeric.pod6 chunk 10 compiles | |
# multi sub exp(Numeric:D, Numeric:D $base = e --> Numeric:D) | |
# multi method exp(Numeric:D: Numeric:D $base = e --> Numeric:D) | |
ok 2346 - doc/Type/Numeric.pod6 chunk 11 compiles | |
# multi method roots(Numeric:D: Int:D $n --> Positional) | |
ok 2347 - doc/Type/Numeric.pod6 chunk 12 compiles | |
# multi sub abs(Numeric:D --> Real:D) | |
# multi method abs(Numeric:D: --> Real:D) | |
ok 2348 - doc/Type/Numeric.pod6 chunk 13 compiles | |
# multi sub sqrt(Numeric:D --> Numeric:D) | |
# multi method sqrt(Numeric:D --> Numeric:D) | |
ok 2349 - doc/Type/Numeric.pod6 chunk 14 compiles | |
# multi method conj(Numeric:D --> Numeric:D) | |
ok 2350 - doc/Type/Numeric.pod6 chunk 15 compiles | |
# multi method Bool(Numeric:D:) | |
ok 2351 - doc/Type/Numeric.pod6 chunk 16 compiles | |
# method succ(Numeric:D:) | |
ok 2352 - doc/Type/Numeric.pod6 chunk 17 compiles | |
# method pred(Numeric:D:) | |
ok 2353 - doc/Type/Numeric.pod6 chunk 18 compiles | |
# class ObjAt { } | |
ok 2354 - doc/Type/ObjAt.pod6 chunk 1 compiles | |
# enum Order (:Less(-1), :Same(0), :More(1)); | |
ok 2355 - doc/Type/Order.pod6 chunk 1 compiles | |
# multi sub infix:<cmp>(\a, \b --> Order:D) | |
ok 2356 - doc/Type/Order.pod6 chunk 2 compiles | |
# multi sub infix:«<=>»(Int:D \a, Int:D \b --> Order:D) | |
ok 2357 - doc/Type/Order.pod6 chunk 3 compiles | |
# class Pair does Associative {} | |
ok 2358 - doc/Type/Pair.pod6 chunk 1 compiles | |
WARNINGS for /Users/williamcoleda/sandbox/doc/EVAL_2361: | |
Useless use of ":foo(127)" in sink context (line 6) | |
Useless use of ":key<value1 value2>" in sink context (line 5) | |
Useless use of ":key<value>" in sink context (line 4) | |
# Pair.new('key', 'value'); # The canonical way | |
# 'key' => 'value'; # this... | |
# :key<value>; # ...means the same as this | |
# :key<value1 value2>; # But this is key => <value1 value2> | |
# :foo(127); # short for foo => 127 | |
# :127foo; # the same foo => 127 | |
ok 2359 - doc/Type/Pair.pod6 chunk 2 compiles | |
WARNINGS for /Users/williamcoleda/sandbox/doc/EVAL_2362: | |
Useless use of ":key" in sink context (line 2) | |
# :key; # same as key => True | |
# :!key; # same as key => False | |
ok 2360 - doc/Type/Pair.pod6 chunk 3 compiles | |
# sub s(*%h){ say %h.perl }; | |
# s :a1:b2; | |
# # OUTPUT: «{:a1, :b2}» | |
# my $manna = :a1:b2:c3; | |
# say $manna.WHAT; | |
# # OUTPUT: «(Pair)» | |
# $manna = (:a1:b2:c3); | |
# say $manna.WHAT; | |
# # OUTPUT: «(List)» | |
ok 2361 - doc/Type/Pair.pod6 chunk 4 compiles | |
# my $bar = 10; | |
# my %h = :$bar; | |
# dd %h; # OUTPUT: «Hash %h = {:bar(10)}» | |
ok 2362 - doc/Type/Pair.pod6 chunk 5 compiles | |
# method antipair(--> Pair:D) | |
ok 2363 - doc/Type/Pair.pod6 chunk 6 compiles | |
# my $p = (6 => 'Perl').antipair; | |
# say $p.key; # OUTPUT: «Perl» | |
# say $p.value; # OUTPUT: «6» | |
ok 2364 - doc/Type/Pair.pod6 chunk 7 compiles | |
# multi method key(Pair:D:) | |
ok 2365 - doc/Type/Pair.pod6 chunk 8 compiles | |
# my $p = (Perl => 6); | |
# say $p.key; # OUTPUT: «Perl» | |
ok 2366 - doc/Type/Pair.pod6 chunk 9 compiles | |
# multi method value(Pair:D:) is rw | |
ok 2367 - doc/Type/Pair.pod6 chunk 10 compiles | |
# my $p = (Perl => 6); | |
# say $p.value; # OUTPUT: «6» | |
ok 2368 - doc/Type/Pair.pod6 chunk 11 compiles | |
# multi sub infix:<cmp>(Pair:D, Pair:D) | |
ok 2369 - doc/Type/Pair.pod6 chunk 12 compiles | |
# my $a = (Apple => 1); | |
# my $b = (Apple => 2); | |
# say $a cmp $b; | |
ok 2370 - doc/Type/Pair.pod6 chunk 13 compiles | |
# multi method fmt(Pair:D: Str:D $format --> Str:D) | |
ok 2371 - doc/Type/Pair.pod6 chunk 14 compiles | |
# my $pair = :Earth(1); | |
# say $pair.fmt("%s is %.3f AU away from the sun") | |
# # Prints "Earth is 1.000 AU away from the sun" | |
ok 2372 - doc/Type/Pair.pod6 chunk 15 compiles | |
# multi method kv(Pair:D: --> List:D) | |
ok 2373 - doc/Type/Pair.pod6 chunk 16 compiles | |
# my $p = (Perl => 6); | |
# say $p.kv[0]; | |
# say $p.kv[1]; | |
ok 2374 - doc/Type/Pair.pod6 chunk 17 compiles | |
# multi method pairs(Pair:D:) | |
ok 2375 - doc/Type/Pair.pod6 chunk 18 compiles | |
# my $p = (Perl => 6); | |
# say $p.pairs.WHAT; # OUTPUT: «(List)» | |
# say $p.pairs[0]; # OUTPUT: «(Pair)» | |
ok 2376 - doc/Type/Pair.pod6 chunk 19 compiles | |
# multi method antipairs(Pair:D:) | |
ok 2377 - doc/Type/Pair.pod6 chunk 20 compiles | |
# my $p = (6 => 'Perl').antipairs; | |
# say $p.WHAT; # OUTPUT: «(List)» | |
# say $p.first; # OUTPUT: «Perl => 6» | |
# say $p.first.WHAT; # OUTPUT: «(Pair)» | |
ok 2378 - doc/Type/Pair.pod6 chunk 21 compiles | |
# method invert(Pair:D:) | |
ok 2379 - doc/Type/Pair.pod6 chunk 22 compiles | |
# my Pair $p1 = (6 => 'Perl'); | |
# say $p1.invert; # OUTPUT: «Perl => 6» | |
# say $p1.invert.WHAT; # OUTPUT: «(Pair)» | |
# my Pair $p2 = ('Perl' => (5, 6)); | |
# say $p2.invert; # OUTPUT: «(5 => Perl 6 => Perl)» | |
# say $p2.invert.WHAT; # OUTPUT: «(List)» | |
# my Pair $p3 = ('Perl' => { cool => 'language'}); | |
# say $p3.invert; # OUTPUT: «{cool => language => Perl}» | |
# say $p3.invert.WHAT; # OUTPUT: «(Hash)» | |
ok 2380 - doc/Type/Pair.pod6 chunk 23 compiles | |
# multi method keys(Pair:D: --> List:D) | |
ok 2381 - doc/Type/Pair.pod6 chunk 24 compiles | |
# say ('Perl' => 6).keys; # OUTPUT: «(Perl)» | |
ok 2382 - doc/Type/Pair.pod6 chunk 25 compiles | |
# multi method values(Pair:D: --> List:D) | |
ok 2383 - doc/Type/Pair.pod6 chunk 26 compiles | |
# say ('Perl' => 6).values; # OUTPUT: «(6)» | |
ok 2384 - doc/Type/Pair.pod6 chunk 27 compiles | |
# method freeze(Pair:D:) | |
ok 2385 - doc/Type/Pair.pod6 chunk 28 compiles | |
# my $str = "apple"; | |
# my $p = Pair.new('key', $str); | |
# $p.value = "orange"; # this works as expected | |
# $p.say; # OUTPUT: «key => orange» | |
# $p.freeze.say; # OUTPUT: «orange» | |
# $p.value = "a new apple"; # Fails | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Assignment::RO: Cannot modify an immutable Str» | |
ok 2386 - doc/Type/Pair.pod6 chunk 29 compiles | |
# multi method Str(Pair:D: --> Str:D) | |
ok 2387 - doc/Type/Pair.pod6 chunk 30 compiles | |
# my $b = eggs => 3; | |
# say $b.Str; # eggs 3 | |
ok 2388 - doc/Type/Pair.pod6 chunk 31 compiles | |
# class Parameter { } | |
ok 2389 - doc/Type/Parameter.pod6 chunk 1 compiles | |
# my $sig = :(Str $x); | |
# my $param = $sig.params[0]; | |
# say $param.type; # OUTPUT: «Str()» | |
ok 2390 - doc/Type/Parameter.pod6 chunk 2 compiles | |
# method sigil(Parameter:D: --> Str:D) | |
ok 2391 - doc/Type/Parameter.pod6 chunk 3 compiles | |
# method named(Parameter:D: --> Bool:D) | |
ok 2392 - doc/Type/Parameter.pod6 chunk 4 compiles | |
# my Signature $sig = :(Str $x, Bool :$is-named); | |
# say $sig.params[0].named; # OUTPUT: «False» | |
# say $sig.params[1].named; # OUTPUT: «True» | |
ok 2393 - doc/Type/Parameter.pod6 chunk 5 compiles | |
# method named_names(Parameter:D: --> List:D) | |
ok 2394 - doc/Type/Parameter.pod6 chunk 6 compiles | |
# method positional(Parameter:D: --> Bool:D) | |
ok 2395 - doc/Type/Parameter.pod6 chunk 7 compiles | |
# method slurpy(Parameter:D: --> Bool:D) | |
ok 2396 - doc/Type/Parameter.pod6 chunk 8 compiles | |
# method twigil(Parameter:D: --> Str:D) | |
ok 2397 - doc/Type/Parameter.pod6 chunk 9 compiles | |
# method optional(Parameter:D: --> Bool:D) | |
ok 2398 - doc/Type/Parameter.pod6 chunk 10 compiles | |
# method raw(Parameter:D: --> Bool:D) | |
ok 2399 - doc/Type/Parameter.pod6 chunk 11 compiles | |
# sub f(\raw) { | |
# raw = 5; | |
# } | |
# f(my $x); # works | |
# f(42); # dies | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Assignment::RO: Cannot modify an immutable Int» | |
ok 2400 - doc/Type/Parameter.pod6 chunk 12 compiles | |
# sub f($raw is raw) { | |
# $raw = 5; | |
# } | |
ok 2401 - doc/Type/Parameter.pod6 chunk 13 compiles | |
# method capture(Parameter:D: --> Bool:D) | |
ok 2402 - doc/Type/Parameter.pod6 chunk 14 compiles | |
# sub how_many_extra_positionals($!, |capture) { capture.elems.say } | |
# how_many_extra_positionals(0, 1, 2, 3); # RESULT: «3» | |
# say &how_many_extra_positionals.signature.params[1].capture; # OUTPUT: «True» | |
ok 2403 - doc/Type/Parameter.pod6 chunk 15 compiles | |
# method rw(Parameter:D: --> Bool:D) | |
ok 2404 - doc/Type/Parameter.pod6 chunk 16 compiles | |
# method copy(Parameter:D: --> Bool:D) | |
ok 2405 - doc/Type/Parameter.pod6 chunk 17 compiles | |
# method readonly(Parameter:D: --> Bool:D) | |
ok 2406 - doc/Type/Parameter.pod6 chunk 18 compiles | |
# method invocant(Parameter:D: --> Bool:D) | |
ok 2407 - doc/Type/Parameter.pod6 chunk 19 compiles | |
# method type_captures(Parameter:D: --> List:D) | |
ok 2408 - doc/Type/Parameter.pod6 chunk 20 compiles | |
# sub a(::T ::U $x) { T.say } | |
# a(8); # OUTPUT: «Int» | |
# say &a.signature.params[0].type_captures; # OUTPUT: «T U» | |
# sub b($x) { $x.WHAT.say } # does the same thing, but uglier. | |
ok 2409 - doc/Type/Parameter.pod6 chunk 21 compiles | |
# class Pod::Block { } | |
ok 2410 - doc/Type/Pod/Block.pod6 chunk 1 compiles | |
# method contents(--> Positional:D) | |
ok 2411 - doc/Type/Pod/Block.pod6 chunk 2 compiles | |
# method config(--> Map:D) | |
ok 2412 - doc/Type/Pod/Block.pod6 chunk 3 compiles | |
# class Pod::Block::Code is Pod::Block { } | |
ok 2413 - doc/Type/Pod/Block/Code.pod6 chunk 1 compiles | |
# method allowed(--> Positional:D) | |
ok 2414 - doc/Type/Pod/Block/Code.pod6 chunk 2 compiles | |
# class Pod::Block::Named is Pod::Block { } | |
ok 2415 - doc/Type/Pod/Block/Named.pod6 chunk 1 compiles | |
# method name(--> Str:D) | |
ok 2416 - doc/Type/Pod/Block/Named.pod6 chunk 2 compiles | |
# class Pod::Block::Para is Pod::Block { } | |
ok 2417 - doc/Type/Pod/Block/Para.pod6 chunk 1 compiles | |
# class Pod::Item is Pod::Block { } | |
ok 2418 - doc/Type/Pod/Item.pod6 chunk 1 compiles | |
# method level(--> Int) | |
ok 2419 - doc/Type/Pod/Item.pod6 chunk 2 compiles | |
# role Positional { ... } | |
ok 2420 - doc/Type/Positional.pod6 chunk 1 compiles | |
# method of() | |
ok 2421 - doc/Type/Positional.pod6 chunk 2 compiles | |
# role PositionalBindFailover { ... } | |
ok 2422 - doc/Type/PositionalBindFailover.pod6 chunk 1 compiles | |
# sub fifths(@a) { # @a is constraint to Positional | |
# @a[4]; | |
# } | |
# my $seq := gather { # a Seq, which is not Positional | |
# take $_ for 1..*; | |
# } | |
# say fifths($seq); # OUTPUT: «5» | |
ok 2423 - doc/Type/PositionalBindFailover.pod6 chunk 2 compiles | |
# method cache(PositionalBindFailover:D: --> List:D) | |
ok 2424 - doc/Type/PositionalBindFailover.pod6 chunk 3 compiles | |
# method list(PositionalBindFailover:D: --> List:D) | |
ok 2425 - doc/Type/PositionalBindFailover.pod6 chunk 4 compiles | |
# method iterator(PositionalBindFailover:D:) { ... } | |
ok 2426 - doc/Type/PositionalBindFailover.pod6 chunk 5 compiles | |
# class Proc {} | |
ok 2427 - doc/Type/Proc.pod6 chunk 1 compiles | |
# my $proc = run 'echo', 'Hallo world', :out; | |
# my $captured-output = $proc.out.slurp-rest; | |
# say "Output was $captured-output.perl()"; # OUTPUT: «Output was "Hallo world\n"» | |
ok 2428 - doc/Type/Proc.pod6 chunk 2 compiles | |
# my $p1 = run 'echo', 'Hello, world', :out; | |
# my $p2 = run 'cat', '-n', :in($p1.out), :out; | |
# say $p2.out.get; | |
ok 2429 - doc/Type/Proc.pod6 chunk 3 compiles | |
# my $p = run "cat", "-n", :in, :out; | |
# $p.in.say: "Hello,\nworld!"; | |
# $p.in.close; | |
# say $p.out.slurp-rest; | |
# # OUTPUT: «1 Hello, | |
# # 2 world!» | |
ok 2430 - doc/Type/Proc.pod6 chunk 4 compiles | |
# method spawn(*@args ($, *@), :$cwd = $*CWD, Hash() :$env = %*ENV --> Bool:D) | |
ok 2431 - doc/Type/Proc.pod6 chunk 5 compiles | |
# method shell($cmd, :$cwd = $*CWD, :$env --> Bool:D) | |
ok 2432 - doc/Type/Proc.pod6 chunk 6 compiles | |
# method command(Proc:D: --> Array:D) | |
ok 2433 - doc/Type/Proc.pod6 chunk 7 compiles | |
# method exitcode(Proc:D: --> Int:D) | |
ok 2434 - doc/Type/Proc.pod6 chunk 8 compiles | |
# method signal(Proc:D:) | |
ok 2435 - doc/Type/Proc.pod6 chunk 9 compiles | |
# method pid(Proc:D:) | |
ok 2436 - doc/Type/Proc.pod6 chunk 10 compiles | |
# # command with arguments | |
# my $proc = Proc::Async.new('echo', 'foo', 'bar'); | |
# # subscribe to new output from out and err handles: | |
# $proc.stdout.tap(-> $v { print "Output: $v" }, quit => { say 'caught exception ' ~ .^name }); | |
# $proc.stderr.tap(-> $v { print "Error: $v" }); | |
# say "Starting..."; | |
# my $promise = $proc.start; | |
# # wait for the external program to terminate | |
# await $promise; | |
# say "Done."; | |
ok 2437 - doc/Type/Proc/Async.pod6 chunk 1 compiles | |
# use v6.c; | |
# my $prog = Proc::Async.new(:w, 'hexdump', '-C'); | |
# my $promise = $prog.start; | |
# await $prog.write(Buf.new(12, 42)); | |
# $prog.close-stdin; | |
# await $promise; | |
ok 2438 - doc/Type/Proc/Async.pod6 chunk 2 compiles | |
# method new(:$path, *@args, :$w, :$r --> Proc::Async:D) | |
ok 2439 - doc/Type/Proc/Async.pod6 chunk 3 compiles | |
# method stdout(Proc::Async:D: :$bin --> Supply:D) | |
ok 2440 - doc/Type/Proc/Async.pod6 chunk 4 compiles | |
# my $proc = Proc::Async.new(:r, 'echo', 'Perl 6'); | |
# $proc.stdout.tap( -> $str { | |
# say "Got output '$str' from the external program"; | |
# }); | |
# my $promise = $proc.start; | |
# await $promise; | |
ok 2441 - doc/Type/Proc/Async.pod6 chunk 5 compiles | |
# method stderr(Proc::Async:D: :$bin --> Supply:D) | |
ok 2442 - doc/Type/Proc/Async.pod6 chunk 6 compiles | |
# my $proc = Proc::Async.new(:r, 'echo', 'Perl 6'); | |
# $proc.stderr.tap( -> $str { | |
# say "Got error '$str' from the external program"; | |
# }); | |
# my $promise = $proc.start; | |
# await $promise; | |
ok 2443 - doc/Type/Proc/Async.pod6 chunk 7 compiles | |
# method w(Proc::Async:D:) | |
ok 2444 - doc/Type/Proc/Async.pod6 chunk 8 compiles | |
# method start(Proc::Async:D: :$scheduler = $*SCHEDULER, :$cwd = $*CWD --> Promise:D) | |
ok 2445 - doc/Type/Proc/Async.pod6 chunk 9 compiles | |
# method started(Proc::Async:D: --> Bool:D) | |
ok 2446 - doc/Type/Proc/Async.pod6 chunk 10 compiles | |
# method path(Proc::Async:D:) | |
ok 2447 - doc/Type/Proc/Async.pod6 chunk 11 compiles | |
# method args(Proc::Async:D: --> Positional:D) | |
ok 2448 - doc/Type/Proc/Async.pod6 chunk 12 compiles | |
# method write(Proc::Async:D: Blob:D $b, :$scheduler = $*SCHEDULER) | |
ok 2449 - doc/Type/Proc/Async.pod6 chunk 13 compiles | |
# method print(Proc::Async:D: Str(Any) $str, :$scheduler = $*SCHEDULER) | |
ok 2450 - doc/Type/Proc/Async.pod6 chunk 14 compiles | |
# method say(Proc::Async:D: $output, :$scheduler = $*SCHEDULER) | |
ok 2451 - doc/Type/Proc/Async.pod6 chunk 15 compiles | |
# method close-stdin(Proc::Async:D:) | |
ok 2452 - doc/Type/Proc/Async.pod6 chunk 16 compiles | |
# method kill(Proc::Async:D: $signal = "HUP") | |
ok 2453 - doc/Type/Proc/Async.pod6 chunk 17 compiles | |
# my enum PromiseStatus (:Planned(0), :Kept(1), :Broken(2)); | |
# class Promise {} | |
ok 2454 - doc/Type/Promise.pod6 chunk 1 compiles | |
# my $p = Promise.start({ sleep 2; 42}); | |
# $p.then({ say .result }); # will print 42 once the block finished | |
# say $p.status; # OUTPUT: «Planned» | |
# $p.result; # waits for the computation to finish | |
# say $p.status; # OUTPUT: «Kept» | |
ok 2455 - doc/Type/Promise.pod6 chunk 2 compiles | |
# sub async-get-with-promise($user-agent, $url) { | |
# my $p = Promise.new; | |
# my $v = $p.vow; | |
# # do an asynchronous call on a fictive user agent, | |
# # and return the promise: | |
# $user-agent.async-get($url, | |
# on-error => -> $error { | |
# $v.break($error); | |
# }, | |
# on-success => -> $response { | |
# $v.keep($response); | |
# } | |
# ); | |
# return $p; | |
# } | |
ok 2456 - doc/Type/Promise.pod6 chunk 3 compiles | |
# method start(Promise:U: &code, :$scheduler = $*SCHEDULER --> Promise:D) | |
ok 2457 - doc/Type/Promise.pod6 chunk 4 compiles | |
# # these two are equivalent: | |
# my $p1 = Promise.start({ ;#`( do something here ) }); | |
# my $p2 = start { ;#`( do something here ) }; | |
ok 2458 - doc/Type/Promise.pod6 chunk 5 compiles | |
# method in(Promise:U: $seconds, :$scheduler = $*SCHEDULER --> Promise:D) | |
ok 2459 - doc/Type/Promise.pod6 chunk 6 compiles | |
# my $proc = Proc::Async.new('perl6', '-e', 'sleep 10; warn "end"'); | |
# my $result = await Promise.anyof( | |
# my $promise = $proc.start, | |
# Promise.in(5).then: { note 'timeout'; $proc.kill } | |
# ).then: {$promise.result}; | |
# # OUTPUT: «timeout» | |
ok 2460 - doc/Type/Promise.pod6 chunk 7 compiles | |
# method at(Promise:U: $time, :$scheduler = $*SCHEDULER --> Promise:D) | |
ok 2461 - doc/Type/Promise.pod6 chunk 8 compiles | |
# my $p = Promise.at(now + 2).then({ say "2 seconds later" }); | |
# # do other stuff here | |
# await $p; # wait here until the 2 seconds are over | |
ok 2462 - doc/Type/Promise.pod6 chunk 9 compiles | |
# method allof(Promise:U: *@promises --> Promise:D) | |
ok 2463 - doc/Type/Promise.pod6 chunk 10 compiles | |
# my @promises; | |
# for 1..5 -> $t { | |
# push @promises, start { | |
# sleep $t; | |
# }; | |
# } | |
# my $all-done = Promise.allof(@promises); | |
# await $all-done; | |
# @promises>>.result; | |
# say "Promises kept so we get to live another day!"; | |
ok 2464 - doc/Type/Promise.pod6 chunk 11 compiles | |
# method anyof(Promise:U: *@promises --> Promise:D) | |
ok 2465 - doc/Type/Promise.pod6 chunk 12 compiles | |
# my $timeout = 5; | |
# await Promise.anyof( | |
# Promise.in($timeout), | |
# start { | |
# # do a potentially long-running calculation here | |
# }, | |
# ); | |
ok 2466 - doc/Type/Promise.pod6 chunk 13 compiles | |
# method then(Promise:D: &code) | |
ok 2467 - doc/Type/Promise.pod6 chunk 14 compiles | |
# my $timer = Promise.in(2); | |
# my $after = $timer.then({ say "2 seconds are over!"; 'result' }); | |
# say $after.result; # 2 seconds are over | |
# # result | |
ok 2468 - doc/Type/Promise.pod6 chunk 15 compiles | |
# multi method keep(Promise:D:) | |
# multi method keep(Promise:D: \result) | |
ok 2469 - doc/Type/Promise.pod6 chunk 16 compiles | |
# my $p = Promise.new; | |
# if Bool.pick { | |
# $p.keep; | |
# } | |
# else { | |
# $p.break; | |
# } | |
ok 2470 - doc/Type/Promise.pod6 chunk 17 compiles | |
# multi method break(Promise:D:) | |
# multi method break(Promise:D: \cause) | |
ok 2471 - doc/Type/Promise.pod6 chunk 18 compiles | |
# my $p = Promise.new; | |
# $p.break('sorry'); | |
# say $p.status; # OUTPUT: «Broken» | |
# say $p.cause; # OUTPUT: «sorry» | |
ok 2472 - doc/Type/Promise.pod6 chunk 19 compiles | |
# method result(Promise:D) | |
ok 2473 - doc/Type/Promise.pod6 chunk 20 compiles | |
# method cause(Promise:D) | |
ok 2474 - doc/Type/Promise.pod6 chunk 21 compiles | |
# multi method Bool(Promise:D:) | |
ok 2475 - doc/Type/Promise.pod6 chunk 22 compiles | |
# method status(Promise:D --> PromiseStatus) | |
ok 2476 - doc/Type/Promise.pod6 chunk 23 compiles | |
# method scheduler(Promise:D:) | |
ok 2477 - doc/Type/Promise.pod6 chunk 24 compiles | |
# my $p = Promise.new; | |
# my $vow = $p.vow; | |
# $vow.keep($p); | |
# say $p.status; # OUTPUT: «Kept» | |
ok 2478 - doc/Type/Promise.pod6 chunk 25 compiles | |
# method Supply(Promise:D:) | |
ok 2479 - doc/Type/Promise.pod6 chunk 26 compiles | |
# multi sub await(Promise:D) | |
# multi sub await(*@) | |
ok 2480 - doc/Type/Promise.pod6 chunk 27 compiles | |
# class Proxy {} | |
ok 2481 - doc/Type/Proxy.pod6 chunk 1 compiles | |
# sub double() is rw { | |
# my $storage = 0; | |
# Proxy.new( | |
# FETCH => method () { $storage }, | |
# STORE => method ($new) { $storage = 2 * $new } | |
# ) | |
# } | |
# my $doubled := double(); | |
# $doubled = 4; | |
# say $doubled; # OUTPUT: «8» | |
ok 2482 - doc/Type/Proxy.pod6 chunk 2 compiles | |
# method new(:&FETCH!, :&STORE! --> Proxy:D) | |
ok 2483 - doc/Type/Proxy.pod6 chunk 3 compiles | |
# role QuantHash does Associative { } | |
ok 2484 - doc/Type/QuantHash.pod6 chunk 1 compiles | |
# 1 .. 5; # 1 <= $x <= 5 | |
# 1^.. 5; # 1 < $x <= 5 | |
# 1 ..^5; # 1 <= $x < 5 | |
# 1^..^5; # 1 < $x < 5 | |
ok 2485 - doc/Type/Range.pod6 chunk 1 compiles | |
# my $x = 10; | |
# say ^$x; # same as 0 ..^ $x.Numeric | |
ok 2486 - doc/Type/Range.pod6 chunk 2 compiles | |
# for 1..5 { .say }; # OUTPUT: «12345» | |
# ('a' ^..^ 'f').list; # RESULT: «'b', 'c', 'd', 'e'» | |
# 5 ~~ ^5; # RESULT: «False» | |
# 4.5 ~~ 0..^5; # RESULT: «True» | |
# (1.1..5).list; # RESULT: «(1.1, 2.1, 3.1, 4.1)» | |
ok 2487 - doc/Type/Range.pod6 chunk 3 compiles | |
# my @numbers = <4 8 15 16 23 42>; | |
# my $range := 0..2; | |
# .say for @numbers[$range]; # OUTPUT: «4815» | |
# my @range = 0..2; | |
# .say for @numbers[@range]; # OUTPUT: «4815» | |
ok 2488 - doc/Type/Range.pod6 chunk 4 compiles | |
# method min(Range:D:) | |
ok 2489 - doc/Type/Range.pod6 chunk 5 compiles | |
# say (1..5).min; # OUTPUT: «1» | |
# say (1^..^5).min; # OUTPUT: «1» | |
ok 2490 - doc/Type/Range.pod6 chunk 6 compiles | |
# method excludes-min(Range:D: --> Bool:D) | |
ok 2491 - doc/Type/Range.pod6 chunk 7 compiles | |
# say (1..5).excludes-min; # OUTPUT: «False» | |
# say (1^..^5).excludes-min; # OUTPUT: «True» | |
ok 2492 - doc/Type/Range.pod6 chunk 8 compiles | |
# method max(Range:D:) | |
ok 2493 - doc/Type/Range.pod6 chunk 9 compiles | |
# say (1..5).max; # OUTPUT: «5» | |
# say (1^..^5).max; # OUTPUT: «5» | |
ok 2494 - doc/Type/Range.pod6 chunk 10 compiles | |
# method excludes-max(Range:D: --> Bool:D) | |
ok 2495 - doc/Type/Range.pod6 chunk 11 compiles | |
# say (1..5).excludes-max; # OUTPUT: «False» | |
# say (1^..^5).excludes-max; # OUTPUT: «True» | |
ok 2496 - doc/Type/Range.pod6 chunk 12 compiles | |
# method bounds(Range:D: --> Positional) | |
ok 2497 - doc/Type/Range.pod6 chunk 13 compiles | |
# say (1..5).bounds; # OUTPUT: «(1 5)» | |
# say (1^..^5).bounds; # OUTPUT: «(1 5)» | |
ok 2498 - doc/Type/Range.pod6 chunk 14 compiles | |
# method infinite(Range:D: --> Bool:D) | |
ok 2499 - doc/Type/Range.pod6 chunk 15 compiles | |
# say (1..5).infinite; # OUTPUT: «False» | |
# say (1..*).infinite; # OUTPUT: «True» | |
ok 2500 - doc/Type/Range.pod6 chunk 16 compiles | |
# method is-int(Range:D: --> Bool:D) | |
ok 2501 - doc/Type/Range.pod6 chunk 17 compiles | |
# say ('a'..'d').is-int; # OUTPUT: «False» | |
# say (1..^5).is-int; # OUTPUT: «True» | |
# say (1.1..5.5).is-int; # OUTPUT: «False» | |
ok 2502 - doc/Type/Range.pod6 chunk 18 compiles | |
# method bounds(Range:D: --> Positional) | |
ok 2503 - doc/Type/Range.pod6 chunk 19 compiles | |
# multi method minmax(Range:D: --> List:D) | |
ok 2504 - doc/Type/Range.pod6 chunk 20 compiles | |
# my $r1 = (1..5); my $r2 = (1^..5); | |
# say $r1.is-int, ', ', $r2.is-int; # OUTPUT: «True, True» | |
# say $r1.excludes-min, ', ', $r2.excludes-min; # OUTPUT: «False, True» | |
# say $r1.minmax, ', ', $r2.minmax; # OUTPUT: «(1 5), (2 5)» | |
# my $r3 = (1.1..5.2); my $r4 = (1.1..^5.2); | |
# say $r3.is-int, ', ', $r4.is-int; # OUTPUT: «False, False» | |
# say $r3.excludes-max, ', ', $r4.excludes-max; # OUTPUT: «False, True» | |
# say $r3.minmax; # OUTPUT: «(1.1 5.2)» | |
# say $r4.minmax; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::AdHoc: Cannot return minmax on Range with excluded ends» | |
ok 2505 - doc/Type/Range.pod6 chunk 21 compiles | |
# method elems(Range:D: --> Numeric:D) | |
ok 2506 - doc/Type/Range.pod6 chunk 22 compiles | |
# say (1..5).elems; # OUTPUT: «5» | |
# say (1^..^5).elems; # OUTPUT: «3» | |
ok 2507 - doc/Type/Range.pod6 chunk 23 compiles | |
# method list(Range:D: --> List:D) | |
ok 2508 - doc/Type/Range.pod6 chunk 24 compiles | |
# say (1..5).list; # OUTPUT: «(1 2 3 4 5)» | |
# say (1^..^5).list; # OUTPUT: «(2 3 4)» | |
ok 2509 - doc/Type/Range.pod6 chunk 25 compiles | |
# method flat(Range:D: --> List:D) | |
ok 2510 - doc/Type/Range.pod6 chunk 26 compiles | |
# multi method pick(Range:D: --> Any:D) | |
# multi method pick(Range:D: $number --> Seq:D) | |
ok 2511 - doc/Type/Range.pod6 chunk 27 compiles | |
# multi method roll(Range:D: --> Any:D) | |
# multi method roll(Range:D: $number --> Seq:D) | |
ok 2512 - doc/Type/Range.pod6 chunk 28 compiles | |
# multi method sum(--> Numeric:D) | |
ok 2513 - doc/Type/Range.pod6 chunk 29 compiles | |
# (1..10).sum # 55 | |
ok 2514 - doc/Type/Range.pod6 chunk 30 compiles | |
# method reverse(Range:D: --> Seq:D) | |
ok 2515 - doc/Type/Range.pod6 chunk 31 compiles | |
# say (1^..5).reverse; # OUTPUT: «(5 4 3 2)» | |
# say ('a'..'d').reverse; # OUTPUT: «(d c b a)» | |
# say (1..Inf).reverse; # OUTPUT: «(Inf Inf Inf ...)» | |
ok 2516 - doc/Type/Range.pod6 chunk 32 compiles | |
# class Rat is Cool does Rational[Int, UInt64] { } | |
ok 2517 - doc/Type/Rat.pod6 chunk 1 compiles | |
WARNINGS for /Users/williamcoleda/sandbox/doc/EVAL_2520: | |
Useless use of constant value 3.1 in sink context (line 2) | |
# 3.1; # Rat.new(31, 10) | |
# <1/2> # Rat.new(1, 2) | |
ok 2518 - doc/Type/Rat.pod6 chunk 2 compiles | |
# sub approx-sqrt($n, $iterations) { | |
# my $x = $n; | |
# $x = ($x + $n / $x) / 2 for ^$iterations; | |
# return $x; | |
# } | |
# say approx-sqrt(2, 5).WHAT; # OUTPUT: «(Rat)» | |
# say approx-sqrt(2, 10).WHAT; # OUTPUT: «(Num)» | |
ok 2519 - doc/Type/Rat.pod6 chunk 3 compiles | |
# multi method perl(Rat:D: --> Str:D) | |
ok 2520 - doc/Type/Rat.pod6 chunk 4 compiles | |
# say (1/3).perl; # OUTPUT: «<1/3>» | |
# say (2/4).perl; # OUTPUT: «0.5» | |
ok 2521 - doc/Type/Rat.pod6 chunk 5 compiles | |
# class RatStr is Rat is Str {} | |
ok 2522 - doc/Type/RatStr.pod6 chunk 1 compiles | |
# my $f = <42.1>; say $f.WHAT; # OUTPUT: «(RatStr)» | |
ok 2523 - doc/Type/RatStr.pod6 chunk 2 compiles | |
# my $rat-str = <42.1>; | |
# my Rat $rat = $rat-str; # OK! | |
# my Str $str = $rat-str; # OK! | |
# say 42.1 ∈ <42.1 55 1>; # False; ∈ operator cares about object identity | |
ok 2524 - doc/Type/RatStr.pod6 chunk 3 compiles | |
# method new(Rat $i, Str $s) | |
ok 2525 - doc/Type/RatStr.pod6 chunk 4 compiles | |
# my $f = RatStr.new(42.1, "forty two and a bit"); | |
# say +$f; # OUTPUT: «42.1» | |
# say ~$f; # OUTPUT: «"forty two and a bit"» | |
ok 2526 - doc/Type/RatStr.pod6 chunk 5 compiles | |
# method Numeric | |
ok 2527 - doc/Type/RatStr.pod6 chunk 6 compiles | |
# method Rat | |
ok 2528 - doc/Type/RatStr.pod6 chunk 7 compiles | |
# multi sub infix:<cmp>(RatStr:D $a, RatStr:D $b) | |
ok 2529 - doc/Type/RatStr.pod6 chunk 8 compiles | |
# my $f = RatStr.new(42.1, "smaller"); | |
# my $g = RatStr.new(43.1, "larger"); | |
# say $f cmp $g; # OUTPUT: «Less» | |
# say $f.Str cmp $g.Str; # OUTPUT: «More» | |
ok 2530 - doc/Type/RatStr.pod6 chunk 9 compiles | |
# role Rational[::NuT, ::DeT] does Real { ... } | |
ok 2531 - doc/Type/Rational.pod6 chunk 1 compiles | |
# method nude(Rational:D: --> Positional) | |
ok 2532 - doc/Type/Rational.pod6 chunk 2 compiles | |
# method norm(Rational:D: --> Rational:D) | |
ok 2533 - doc/Type/Rational.pod6 chunk 3 compiles | |
# method base-repeating(Rational:D: Int:D() $base) | |
ok 2534 - doc/Type/Rational.pod6 chunk 4 compiles | |
# my ($non-rep, $repeating) = (19/3).base-repeating(10); | |
# say $non-rep; # OUTPUT: «6.» | |
# say $repeating; # OUTPUT: «3» | |
# printf '%s(%s)', $non-rep, $repeating; # OUTPUT: «6.(3)» | |
ok 2535 - doc/Type/Rational.pod6 chunk 5 compiles | |
# say (5/2).base-repeating(10).perl; # OUTPUT: «("2.5", "")» | |
ok 2536 - doc/Type/Rational.pod6 chunk 6 compiles | |
# role Real does Numeric { ... } | |
ok 2537 - doc/Type/Real.pod6 chunk 1 compiles | |
# method Rat(Real:D: Real $epsilon = 1e-6) | |
ok 2538 - doc/Type/Real.pod6 chunk 2 compiles | |
# sub term:<rand> (--> Num:D) | |
# method rand(Real:D: --> Real:D) | |
ok 2539 - doc/Type/Real.pod6 chunk 3 compiles | |
# method sign(Real:D:) | |
ok 2540 - doc/Type/Real.pod6 chunk 4 compiles | |
# method round(Real:D: $scale = 1) | |
ok 2541 - doc/Type/Real.pod6 chunk 5 compiles | |
# method floor(Real:D --> Int:D) | |
ok 2542 - doc/Type/Real.pod6 chunk 6 compiles | |
# method ceiling(Real:D --> Int:D) | |
ok 2543 - doc/Type/Real.pod6 chunk 7 compiles | |
# method truncate(Real:D --> Int:D) | |
ok 2544 - doc/Type/Real.pod6 chunk 8 compiles | |
# method base(Real:D: Int:D $base where 2..36, $digits? --> Str:D) | |
ok 2545 - doc/Type/Real.pod6 chunk 9 compiles | |
# 255.base(16); # 'FF' | |
ok 2546 - doc/Type/Real.pod6 chunk 10 compiles | |
# say pi.base(10, 3); # OUTPUT: «3.142» | |
# say (1/128).base(10, *); # OUTPUT: «0.0078125» | |
# say (1/100).base(10, *); # OUTPUT: «0.01» | |
ok 2547 - doc/Type/Real.pod6 chunk 11 compiles | |
# class Regex is Method { } | |
ok 2548 - doc/Type/Regex.pod6 chunk 1 compiles | |
# rx/ ^ab /; # describes all strings starting with 'ab' | |
# / ^ ab /; # same | |
# rx/ \d ** 2/; # describes all strings containing at least two digits | |
ok 2549 - doc/Type/Regex.pod6 chunk 2 compiles | |
# my regex R { \N }; | |
# say &R.WHAT; # OUTPUT: «(Regex)» | |
ok 2550 - doc/Type/Regex.pod6 chunk 3 compiles | |
# my $match = 'abc' ~~ rx/ ^ab /; | |
# say $match.Bool; # OUTPUT: «True» | |
# say $match.orig; # OUTPUT: «abc» | |
# say $match.Str; # OUTPUT: «ab» | |
# say $match.from; # OUTPUT: «0» | |
# say $match.to; # OUTPUT: «2» | |
ok 2551 - doc/Type/Regex.pod6 chunk 4 compiles | |
# $_ = 'abc'; | |
# if / ^ab / { | |
# say '"abc" begins with "ab"'; | |
# } | |
# else { | |
# say 'This is a weird alternative Universe'; | |
# } | |
ok 2552 - doc/Type/Regex.pod6 chunk 5 compiles | |
# multi method ACCEPTS(Regex:D: Mu --> Match:D) | |
# multi method ACCEPTS(Regex:D: @) | |
# multi method ACCEPTS(Regex:D: %) | |
ok 2553 - doc/Type/Regex.pod6 chunk 6 compiles | |
# multi method Bool(Regex:D: --> Bool:D) | |
ok 2554 - doc/Type/Regex.pod6 chunk 7 compiles | |
# class Routine is Block { } | |
ok 2555 - doc/Type/Routine.pod6 chunk 1 compiles | |
# multi sub f() is default { say "Hello there" } | |
# multi sub f() { say "Hello friend" } | |
# f(); # OUTPUT: «"Hello there"» | |
ok 2556 - doc/Type/Routine.pod6 chunk 2 compiles | |
# method name(Routine:D: --> Str:D) | |
ok 2557 - doc/Type/Routine.pod6 chunk 3 compiles | |
# method package(Routine:D:) | |
ok 2558 - doc/Type/Routine.pod6 chunk 4 compiles | |
# method multi(Routine:D: --> Bool:D) | |
ok 2559 - doc/Type/Routine.pod6 chunk 5 compiles | |
# multi foo ($, $) {}; | |
# say &foo.multi; # OUTPUT: «False» | |
# say &foo.candidates».multi; # OUTPUT: «(True)» | |
ok 2560 - doc/Type/Routine.pod6 chunk 6 compiles | |
# method candidates(Routine:D: --> Positional:D) | |
ok 2561 - doc/Type/Routine.pod6 chunk 7 compiles | |
# method cando(Capture $c) | |
ok 2562 - doc/Type/Routine.pod6 chunk 8 compiles | |
# .signature.say for "foo".^can("comb")[0].cando: \(Cool, "o"); | |
# # OUTPUT: «(Cool $: Str $matcher, $limit = Inf, *%_)» | |
ok 2563 - doc/Type/Routine.pod6 chunk 9 compiles | |
# method wrap(Routine:D: &wrapper) | |
ok 2564 - doc/Type/Routine.pod6 chunk 10 compiles | |
# method unwrap(Routine:D: $wraphandler) | |
ok 2565 - doc/Type/Routine.pod6 chunk 11 compiles | |
# method yada(Routine:D: --> Bool:D) | |
ok 2566 - doc/Type/Routine.pod6 chunk 12 compiles | |
# say (sub f() { ... }).yada; # OUTPUT: «True» | |
# say (sub g() { 1; }).yada; # OUTPUT: «False» | |
ok 2567 - doc/Type/Routine.pod6 chunk 13 compiles | |
# multi sub trait_mod:<is>(Routine $r, :$cached!) | |
ok 2568 - doc/Type/Routine.pod6 chunk 14 compiles | |
# use experimental :cached; | |
# sub nth-prime(Int:D $x where * > 0) is cached { | |
# say "Calculating {$x}th prime"; | |
# return (2..*).grep(*.is-prime)[$x - 1]; | |
# } | |
# say nth-prime(43); | |
# say nth-prime(43); | |
# say nth-prime(43); | |
ok 2569 - doc/Type/Routine.pod6 chunk 15 compiles | |
# multi sub trait_mod:<is>(Routine $r, :$pure!) | |
ok 2570 - doc/Type/Routine.pod6 chunk 16 compiles | |
# sub double(Numeric:D $x) is pure { | |
# 2 * $x; | |
# } | |
ok 2571 - doc/Type/Routine.pod6 chunk 17 compiles | |
# multi sub trait_mod:<is>(Routine $r, :$rw!) | |
ok 2572 - doc/Type/Routine.pod6 chunk 18 compiles | |
# sub walk(\thing, *@keys) is rw { | |
# my $current := thing; | |
# for @keys -> $k { | |
# if $k ~~ Int { | |
# $current := $current[$k]; | |
# } | |
# else { | |
# $current := $current{$k}; | |
# } | |
# } | |
# $current; | |
# } | |
# my %hash; | |
# walk(%hash, 'some', 'key', 1, 2) = 'autovivified'; | |
# say %hash.perl; | |
ok 2573 - doc/Type/Routine.pod6 chunk 19 compiles | |
# ("some" => {"key" => [Any, [Any, Any, "autovivified"]]}).hash | |
ok 2574 - doc/Type/Routine.pod6 chunk 20 compiles | |
# multi sub trait_mod:<is>(Routine $r, :$export!) | |
ok 2575 - doc/Type/Routine.pod6 chunk 21 compiles | |
# module Foo { | |
# sub double($x) is export { | |
# 2 * $x | |
# } | |
# } | |
# import Foo; # makes sub double available | |
# say double 21; # 42 | |
ok 2576 - doc/Type/Routine.pod6 chunk 22 compiles | |
# multi sub trait_mod:<is>(Routine:D $r, :$DEPRECATED!) | |
ok 2577 - doc/Type/Routine.pod6 chunk 23 compiles | |
# sub f() is DEPRECATED('the literal 42') { 42 } | |
# say f(); | |
ok 2578 - doc/Type/Routine.pod6 chunk 24 compiles | |
# multi sub trait_mod:<is>(Routine:D, :$hidden-from-backtrace!) | |
ok 2579 - doc/Type/Routine.pod6 chunk 25 compiles | |
# class Scalar {} | |
ok 2580 - doc/Type/Scalar.pod6 chunk 1 compiles | |
# my $a = 1; | |
# $a.WHAT.say; # OUTPUT: «(Int)» | |
# $a.VAR.WHAT.say; # OUTPUT: «(Scalar)» | |
# my $b := 1; | |
# $b.WHAT.say; # OUTPUT: «(Int)» | |
# $b.VAR.WHAT.say; # OUTPUT: «(Int)» | |
ok 2581 - doc/Type/Scalar.pod6 chunk 2 compiles | |
# my @a = 1, 2, 3; | |
# @a[0].WHAT.say; # OUTPUT: «(Int)» | |
# @a[0].VAR.WHAT.say; # OUTPUT: «(Scalar)» | |
# [1, 2, 3][0].WHAT.say; # OUTPUT: «(Int)» | |
# [1, 2, 3][0].VAR.WHAT.say; # OUTPUT: «(Scalar)» | |
# (1, 2, 3)[0].WHAT.say; # OUTPUT: «(Int)» | |
# (1, 2, 3)[0].VAR.WHAT.say; # OUTPUT: «(Int)» | |
ok 2582 - doc/Type/Scalar.pod6 chunk 3 compiles | |
# [1, $(2, 3)].perl.say; # OUTPUT: «[1, (2, 3)]» | |
# (1, $(2, 3)).perl.say; # OUTPUT: «(1, $(2, 3))» | |
ok 2583 - doc/Type/Scalar.pod6 chunk 4 compiles | |
# my $a = 1; | |
# my $b := $a; | |
# $b = 2; | |
# $a.say; # OUTPUT: «2» | |
ok 2584 - doc/Type/Scalar.pod6 chunk 5 compiles | |
# my \c = 1; | |
# c.WHAT.say; # OUTPUT: «(Int)» | |
# c.VAR.WHAT.say; # OUTPUT: «(Int)» | |
# my $a = 1; | |
# my \d = $a; # just "my \d = $ = 1" works, too | |
# d.WHAT.say; # OUTPUT: «(Int)» | |
# d.VAR.WHAT.say; # OUTPUT: «(Scalar)» | |
# d = 2; # ok | |
# c = 2; # fails | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Assignment::RO: Cannot modify an immutable Int» | |
ok 2585 - doc/Type/Scalar.pod6 chunk 6 compiles | |
# role Scheduler { | |
# has &.uncaught_handler is rw | |
# } | |
ok 2586 - doc/Type/Scheduler.pod6 chunk 1 compiles | |
# method uncaught_handler() is rw | |
ok 2587 - doc/Type/Scheduler.pod6 chunk 2 compiles | |
# method cue(:&code, Instant :$at, :$in, :$every, :$times = 1; :&catch) | |
ok 2588 - doc/Type/Scheduler.pod6 chunk 3 compiles | |
# class Semaphore { } | |
ok 2589 - doc/Type/Semaphore.pod6 chunk 1 compiles | |
# class print-manager { | |
# has Array $!printers; | |
# has Semaphore $!print-control; | |
# method BUILD( Int:D :$nbr-printers ) { | |
# for ^$nbr-printers -> $pc { | |
# $!printers[$pc] = { :name{"printer-$pc"} }; | |
# } | |
# $!print-control .= new($nbr-printers); | |
# } | |
# method find-available-printer-and-print-it($job) { say "Is printed!"; } | |
# method print( $print-job ) { | |
# $!print-control.acquire; | |
# self.find-available-printer-and-print-it($print-job); | |
# $!print-control.release; | |
# } | |
# } | |
ok 2590 - doc/Type/Semaphore.pod6 chunk 2 compiles | |
# method new( int $permits ) | |
ok 2591 - doc/Type/Semaphore.pod6 chunk 3 compiles | |
# method acquire() | |
ok 2592 - doc/Type/Semaphore.pod6 chunk 4 compiles | |
# method try_acquire(--> Bool) | |
ok 2593 - doc/Type/Semaphore.pod6 chunk 5 compiles | |
# method release() | |
ok 2594 - doc/Type/Semaphore.pod6 chunk 6 compiles | |
# class Seq is Cool does Iterable does PositionalBindFailover { } | |
ok 2595 - doc/Type/Seq.pod6 chunk 1 compiles | |
# my @a = 1, 2, 3; | |
# my @b = <a b c>; | |
# my \c = @a Z=> @b; | |
# .say for c; | |
# .say for c; # fails | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Seq::Consumed: This Seq has already been iterated, and its values consumed | |
# # (you might solve this by adding .cache on usages of the Seq, or | |
# # by assigning the Seq into an array)» | |
ok 2596 - doc/Type/Seq.pod6 chunk 2 compiles | |
# method new(Iterator:D $iter --> Seq:D) | |
ok 2597 - doc/Type/Seq.pod6 chunk 3 compiles | |
# method iterator(Seq:D: --> Iterator:D) | |
ok 2598 - doc/Type/Seq.pod6 chunk 4 compiles | |
# method is-lazy(Seq:D: --> Bool:D) | |
ok 2599 - doc/Type/Seq.pod6 chunk 5 compiles | |
# method eager(Seq:D: --> List:D) | |
ok 2600 - doc/Type/Seq.pod6 chunk 6 compiles | |
# multi method from-loop(&body --> Seq:D) | |
# multi method from-loop(&body, &cond, :$repeat --> Seq:D) | |
# multi method from-loop(&body, &cond, &afterward --> Seq:D) | |
ok 2601 - doc/Type/Seq.pod6 chunk 7 compiles | |
# class Set does Setty { } | |
ok 2602 - doc/Type/Set.pod6 chunk 1 compiles | |
# my $fruits = set <peach apple orange apple apple>; | |
# say $fruits.elems; # OUTPUT: «3» | |
# say $fruits.keys.sort; # OUTPUT: «apple orange peach» | |
ok 2603 - doc/Type/Set.pod6 chunk 2 compiles | |
# my $fruits = set <peach apple orange apple apple>; | |
# say $fruits<apple>; # OUTPUT: «True» | |
# say $fruits<kiwi>; # OUTPUT: «False» | |
ok 2604 - doc/Type/Set.pod6 chunk 3 compiles | |
# my $n = set "zero" => 0, "one" => 1, "two" => 2; | |
# say $n.keys.perl; # OUTPUT: «(:two(2), :zero(0), :one(1)).Seq» | |
# say $n.keys.map(&WHAT); # OUTPUT: «((Pair) (Pair) (Pair))» | |
ok 2605 - doc/Type/Set.pod6 chunk 4 compiles | |
# my $n = ("zero" => 0, "one" => 1, "two" => 2).Set; | |
# say $n.keys.perl; # OUTPUT: «("one", "two").Seq» | |
# say $n.keys.map(&WHAT); # OUTPUT: «((Str) (Str))» | |
ok 2606 - doc/Type/Set.pod6 chunk 5 compiles | |
# say (1..5) (^) 4; # OUTPUT: «set(1, 2, 3, 5)» | |
ok 2607 - doc/Type/Set.pod6 chunk 6 compiles | |
# my ($a, $b) = set(1, 2, 3), set(2, 4); | |
# say $a (<) $b; # OUTPUT: «False» | |
# say $a (&) $b; # OUTPUT: «set(2)» | |
# say $a (^) $b; # OUTPUT: «set(1, 3, 4)» | |
# # Unicode versions: | |
# say $a ⊂ $b; # OUTPUT: «False» | |
# say $a ∩ $b; # OUTPUT: «set(2)» | |
# say $a ⊖ $b; # OUTPUT: «set(1, 3, 4)» | |
ok 2608 - doc/Type/Set.pod6 chunk 7 compiles | |
# sub set(*@args --> Set) | |
ok 2609 - doc/Type/Set.pod6 chunk 8 compiles | |
# class SetHash does Setty { } | |
ok 2610 - doc/Type/SetHash.pod6 chunk 1 compiles | |
# my $fruits = <peach apple orange apple apple>.SetHash; | |
# say $fruits.elems; # OUTPUT: «3» | |
# say $fruits.keys.sort; # OUTPUT: «apple orange peach» | |
ok 2611 - doc/Type/SetHash.pod6 chunk 2 compiles | |
# my $fruits = <peach apple orange apple apple>.SetHash; | |
# say $fruits<apple>; # OUTPUT: «True» | |
# say $fruits<kiwi>; # OUTPUT: «False» | |
# $fruits<apple kiwi> = False, True; | |
# say $fruits.keys.sort; # OUTPUT: «kiwi orange peach» | |
ok 2612 - doc/Type/SetHash.pod6 chunk 3 compiles | |
# my $n = SetHash.new: "zero" => 0, "one" => 1, "two" => 2; | |
# say $n.keys.perl; # OUTPUT: «(:two(2), :zero(0), :one(1)).Seq» | |
# say $n.keys.map(&WHAT); # OUTPUT: «((Pair) (Pair) (Pair))» | |
ok 2613 - doc/Type/SetHash.pod6 chunk 4 compiles | |
# my $n = ("zero" => 0, "one" => 1, "two" => 2).SetHash; | |
# say $n.keys.perl; # OUTPUT: «("one", "two").Seq» | |
# say $n.keys.map(&WHAT); # OUTPUT: «((Str) (Str))» | |
ok 2614 - doc/Type/SetHash.pod6 chunk 5 compiles | |
# my ($a, $b) = SetHash.new(1, 2, 3), SetHash.new(2, 4); | |
# say $a (<) $b; # OUTPUT: «False» | |
# say $a (&) $b; # OUTPUT: «set(2)» | |
# say $a (^) $b; # OUTPUT: «set(1, 3, 4)» | |
# say $a (|) $b; # OUTPUT: «set(1, 2, 3, 4)» | |
# # Unicode versions: | |
# say $a ⊂ $b; # OUTPUT: «False» | |
# say $a ∩ $b; # OUTPUT: «set(2)» | |
# say $a ⊖ $b; # OUTPUT: «set(1, 3, 4)» | |
# say $a ∪ $b; # OUTPUT: «set(1, 2, 3, 4)» | |
ok 2615 - doc/Type/SetHash.pod6 chunk 6 compiles | |
# role Setty does QuantHash { } | |
ok 2616 - doc/Type/Setty.pod6 chunk 1 compiles | |
# method new-from-pairs(*@pairs --> Setty:D) | |
ok 2617 - doc/Type/Setty.pod6 chunk 2 compiles | |
# say Set.new-from-pairs: 'butter' => 0.22, 'salt' => 0, 'sugar' => 0.02; | |
# # OUTPUT: «set(butter, sugar)» | |
ok 2618 - doc/Type/Setty.pod6 chunk 3 compiles | |
# method grab($count = 1) | |
ok 2619 - doc/Type/Setty.pod6 chunk 4 compiles | |
# method grabpairs($count = 1) | |
ok 2620 - doc/Type/Setty.pod6 chunk 5 compiles | |
# multi method pick($count = 1) | |
ok 2621 - doc/Type/Setty.pod6 chunk 6 compiles | |
# multi method roll($count = 1) | |
ok 2622 - doc/Type/Setty.pod6 chunk 7 compiles | |
# multi method keys(Setty:D: --> Seq:D) | |
ok 2623 - doc/Type/Setty.pod6 chunk 8 compiles | |
# my $s = Set.new(1, 2, 3); | |
# say $s.keys; # OUTPUT: «(3 1 2)» | |
ok 2624 - doc/Type/Setty.pod6 chunk 9 compiles | |
# multi method values(Setty:D: --> Seq:D) | |
ok 2625 - doc/Type/Setty.pod6 chunk 10 compiles | |
# my $s = Set.new(1, 2, 3); | |
# say $s.values; # OUTPUT: «(True True True)» | |
ok 2626 - doc/Type/Setty.pod6 chunk 11 compiles | |
# multi method kv(Setty:D: --> Seq:D) | |
ok 2627 - doc/Type/Setty.pod6 chunk 12 compiles | |
# my $s = Set.new(1, 2, 3); | |
# say $s.kv; # OUTPUT: «(3 True 1 True 2 True)» | |
ok 2628 - doc/Type/Setty.pod6 chunk 13 compiles | |
# method elems(--> Int) | |
ok 2629 - doc/Type/Setty.pod6 chunk 14 compiles | |
# method total(--> Int) | |
ok 2630 - doc/Type/Setty.pod6 chunk 15 compiles | |
# method default(--> False) | |
ok 2631 - doc/Type/Setty.pod6 chunk 16 compiles | |
# my $s1 = SetHash.new(1, 2, 3); | |
# say $s1{2}; # OUTPUT: «True» | |
# $s1{2} = Nil; | |
# say $s1{2}; # OUTPUT: «False» | |
# # access non initialized element | |
# say $s1{4}; # OUTPUT: «False» | |
ok 2632 - doc/Type/Setty.pod6 chunk 17 compiles | |
# method ACCEPTS($other) | |
ok 2633 - doc/Type/Setty.pod6 chunk 18 compiles | |
# method Bag(Setty:D: --> Bag:D) | |
ok 2634 - doc/Type/Setty.pod6 chunk 19 compiles | |
# my Bag $b = Set.new(1, 2, 3).Bag; | |
# say $b; # OUTPUT: «bag(3, 1, 2)» | |
ok 2635 - doc/Type/Setty.pod6 chunk 20 compiles | |
# method BagHash(Setty:D: --> BagHash:D) | |
ok 2636 - doc/Type/Setty.pod6 chunk 21 compiles | |
# my BagHash $b = Set.new(1, 2, 3).BagHash; | |
# say $b; # OUTPUT: «BagHash.new(3, 1, 2)» | |
ok 2637 - doc/Type/Setty.pod6 chunk 22 compiles | |
# multi method Bool(Setty:D: --> Bool:D) | |
ok 2638 - doc/Type/Setty.pod6 chunk 23 compiles | |
# my $s1 = Set.new(1, 2, 3); | |
# say $s1.Bool; # OUTPUT: «True» | |
# my $s2 = $s1 ∩ Set.new(4, 5); # set intersection operator | |
# say $s2.Bool; # OUTPUT: «False» | |
ok 2639 - doc/Type/Setty.pod6 chunk 24 compiles | |
# method Mix(Setty:D: --> Mix:D) | |
ok 2640 - doc/Type/Setty.pod6 chunk 25 compiles | |
# my Mix $b = Set.new(1, 2, 3).Mix; | |
# say $b; # OUTPUT: «mix(3, 1, 2)» | |
ok 2641 - doc/Type/Setty.pod6 chunk 26 compiles | |
# method MixHash(Setty:D: --> MixHash:D) | |
ok 2642 - doc/Type/Setty.pod6 chunk 27 compiles | |
# my MixHash $b = Set.new(1, 2, 3).MixHash; | |
# say $b; # OUTPUT: «MixHash.new(3, 1, 2)» | |
ok 2643 - doc/Type/Setty.pod6 chunk 28 compiles | |
# class Signature { } | |
ok 2644 - doc/Type/Signature.pod6 chunk 1 compiles | |
# sub f($x) { } | |
# # ^^^^ Signature of sub f | |
# my method x() { } | |
# # ^^ Signature of a method | |
# my $s = sub (*@a) { } | |
# # ^^^^^ Signature of an anonymous function | |
# for <a b c> -> $x { } | |
# # ^^ Signature of a Block | |
# my ($a, @b) = 5, (6, 7, 8); | |
# # ^^^^^^^^ Signature of a variable declarator | |
# my $sig = :($a, $b); | |
# # ^^^^^^^^ Standalone Signature object | |
ok 2645 - doc/Type/Signature.pod6 chunk 2 compiles | |
# sub f(&c:(Int)) { } | |
# sub will-work(Int) { } | |
# sub won't-work(Str) { } | |
# f(&will-work); | |
# f(&won't-work); | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::AdHoc: Constraint type check failed for parameter '&c'» | |
# f(-> Int { 'this works too' } ); | |
ok 2646 - doc/Type/Signature.pod6 chunk 3 compiles | |
# my $sig = :(Int $i, Str $s); | |
# say (10, 'answer') ~~ $sig; | |
# # OUTPUT: «True» | |
# given ('answer', 10) { | |
# when :(Str, Int) { say 'match' } | |
# when $sig { say 'mismatch' } | |
# } | |
# # OUTPUT: «match» | |
ok 2647 - doc/Type/Signature.pod6 chunk 4 compiles | |
# my %h = left => 1, right => 2; | |
# say %h ~~ :(:$left, :$right); | |
# # OUTPUT: «True» | |
ok 2648 - doc/Type/Signature.pod6 chunk 5 compiles | |
# my $sig = :($a, @b, %c); | |
# sub add($a, $b) { $a + $b }; | |
ok 2649 - doc/Type/Signature.pod6 chunk 6 compiles | |
# method ($a: @b, %c) {}; # first argument is the invocant | |
# class Foo { | |
# method whoami($me:) { | |
# "Well I'm class $me.^name(), of course!" | |
# } | |
# } | |
# say Foo.whoami; # OUTPUT: «Well I'm class Foo, of course!» | |
ok 2650 - doc/Type/Signature.pod6 chunk 7 compiles | |
# my $sig = :($, @, %a); # two anonymous and a "normal" parameter | |
# $sig = :(Int, Positional); # just a type is also fine (two parameters) | |
# sub baz(Str) { "Got passed a Str" } | |
ok 2651 - doc/Type/Signature.pod6 chunk 8 compiles | |
# sub f(Real $x where { $x > 0 }, Real $y where { $y >= $x }) { } | |
ok 2652 - doc/Type/Signature.pod6 chunk 9 compiles | |
# multi factorial(Int $ where 0) { 1 } | |
# multi factorial(Int $x) { $x * factorial($x - 1) } | |
ok 2653 - doc/Type/Signature.pod6 chunk 10 compiles | |
# multi factorial(0) { 1 } | |
ok 2654 - doc/Type/Signature.pod6 chunk 11 compiles | |
# sub one-of-them(:$a, :$b, :$c where { $a.defined ^^ $b.defined ^^ $c.defined }) { | |
# $a // $b // $c | |
# }; | |
# say one-of-them(c=>42); # OUTPUT: «42» | |
ok 2655 - doc/Type/Signature.pod6 chunk 12 compiles | |
# sub f(Int $a, UInt $i? where { !$i.defined or $i > 5 } ) { ... } | |
ok 2656 - doc/Type/Signature.pod6 chunk 13 compiles | |
# sub f(*@a where {$_.all ~~ Int}) { say @a }; | |
# f(42); | |
# f(<a>); | |
# CATCH { default { say .^name, ' ==> ', .Str } } | |
# # OUTPUT: «[42]Constraint type check failed for parameter '@a' in sub f at ...» | |
ok 2657 - doc/Type/Signature.pod6 chunk 14 compiles | |
# sub f(Int :$i){}; | |
# f :i<forty-two>; | |
# CATCH { default { say .^name, ' ==> ', .Str } } | |
# # OUTPUT: «X::TypeCheck::Binding ==> Type check failed in binding to $i; expected Int but got Str ("forty-two")» | |
ok 2658 - doc/Type/Signature.pod6 chunk 15 compiles | |
# sub limit-lines(Str $s, Int $limit) { | |
# my @lines = $s.lines; | |
# @lines[0 .. min @lines.elems, $limit].join("\n") | |
# } | |
# say (limit-lines "a \n b \n c \n d \n", 3).perl; # "a \n b \n c " | |
# say limit-lines Str, 3; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Multi::NoMatch: Cannot resolve caller lines(Str: ); none of these signatures match: | |
# # (Cool:D $: |c is raw) | |
# # (Str:D $: :$count!, *%_) | |
# # (Str:D $: $limit, *%_) | |
# # (Str:D $: *%_)» | |
# say limit-lines "a \n b", Int # Always returns the max number of lines | |
ok 2659 - doc/Type/Signature.pod6 chunk 16 compiles | |
# sub limit-lines(Str:D $s, Int $limit) { }; | |
# say limit-lines Str, 3; | |
# CATCH { default { put .^name ~ '--' ~~ .Str } }; | |
# # OUTPUT: «X::AdHoc--Parameter '$s' requires an instance of type Str, but a | |
# # type object was passed. Did you forget a .new?» | |
ok 2660 - doc/Type/Signature.pod6 chunk 17 compiles | |
# multi limit-lines(Str $s, Int:D $limit) { } | |
# multi limit-lines(Str $s, Int:U $) { $s } | |
# say limit-lines "a \n b \n c", Int; # OUTPUT: «"a \n b \n c"» | |
ok 2661 - doc/Type/Signature.pod6 chunk 18 compiles | |
# sub f(&c:(Int, Str)) { say c(10, 'ten') }; | |
# sub g(Int $i, Str $s) { $s ~ $i }; | |
# f(&g); | |
# # OUTPUT: «ten10» | |
ok 2662 - doc/Type/Signature.pod6 chunk 19 compiles | |
# sub foo(--> Int) { my Int $i; $i }; | |
# sub baz(--> Int:D) { 1 } | |
# sub bar() returns Int { 1 }; | |
# sub does-not-work(--> Int) { "" }; # throws X::TypeCheck::Return | |
ok 2663 - doc/Type/Signature.pod6 chunk 20 compiles | |
# sub foo() of Int { 1 }; | |
# my Int sub bar { 1 }; | |
ok 2664 - doc/Type/Signature.pod6 chunk 21 compiles | |
# sub foo(--> 123) { return } | |
ok 2665 - doc/Type/Signature.pod6 chunk 22 compiles | |
# sub foo(--> Int) { Nil }; | |
# say foo.perl; # OUTPUT: «Nil» | |
ok 2666 - doc/Type/Signature.pod6 chunk 23 compiles | |
# sub f(Int(Str) $want-int, Str() $want-str) { say $want-int.WHAT, $want-str.WHAT } | |
# f '10', 10; | |
# # OUTPUT: «(Int)(Str)» | |
# use MONKEY; | |
# augment class Str { method Date() { Date.new(self) } }; | |
# sub foo(Date(Str) $d) { say $d.WHAT; say $d }; | |
# foo "2016-12-01"; | |
# # OUTPUT: «Date.new(2016,11,1)» | |
ok 2667 - doc/Type/Signature.pod6 chunk 24 compiles | |
# $ = :($a, @b); # exactly two arguments, where the second one must be Positional | |
# $ = :($a, *@b); # at least one argument, @b slurps up any beyond that | |
# $ = :(*%h); # no positional arguments, but any number of named arguments | |
# sub one-arg (@) { } | |
# sub slurpy (*@) { } | |
# one-arg (5, 6, 7); # ok, same as one-arg((5, 6, 7)) | |
# slurpy (5, 6, 7); # ok | |
# slurpy 5, 6, 7 ; # ok | |
# # one-arg(5, 6, 7) ; # X::TypeCheck::Argument | |
# # one-arg 5, 6, 7 ; # X::TypeCheck::Argument | |
# sub named-names (*%named-args) { %named-args.keys }; | |
# say named-names :foo(42) :bar<baz>; # OUTPUT: «foo bar» | |
ok 2668 - doc/Type/Signature.pod6 chunk 25 compiles | |
# my @array = <a b c>; | |
# my $list := <d e f>; | |
# sub a(*@a) { @a.perl.say }; | |
# a(@array); # OUTPUT: «["a", "b", "c"]» | |
# a(1, $list, [2, 3]); # OUTPUT: «[1, "d", "e", "f", 2, 3]» | |
# a([1, 2]); # OUTPUT: «[1, 2]» | |
# a(1, [1, 2], ([3, 4], 5)); # OUTPUT: «[1, 1, 2, 3, 4 5]» | |
# a(($_ for 1, 2, 3)); # OUTPUT: «[1, 2, 3]» | |
ok 2669 - doc/Type/Signature.pod6 chunk 26 compiles | |
# my @array = <a b c>; | |
# my $list := <d e f>; | |
# sub b(**@b) { @b.perl.say }; | |
# b(@array); # OUTPUT: «[["a", "b", "c"]]» | |
# b(1, $list, [2, 3]); # OUTPUT: «[1, ("d", "e", "f"), [2, 3]]» | |
# b([1, 2]); # OUTPUT: «[[1, 2]]» | |
# b(1, [1, 2], ([3, 4], 5)); # OUTPUT: «[1, [1, 2], ([3, 4], 5)]» | |
# b(($_ for 1, 2, 3)); # OUTPUT: «[(1, 2, 3),]» | |
ok 2670 - doc/Type/Signature.pod6 chunk 27 compiles | |
# my @array = <a b c>; | |
# my $list := <d e f>; | |
# sub c(+@b) { @b.perl.say }; | |
# c(@array); # OUTPUT: «["a", "b", "c"]» | |
# c(1, $list, [2, 3]); # OUTPUT: «[1, ("d", "e", "f"), [2, 3]]» | |
# c([1, 2]); # OUTPUT: «[1, 2]» | |
# c(1, [1, 2], ([3, 4], 5)); # OUTPUT: «[1, [1, 2], ([3, 4], 5)]» | |
# c(($_ for 1, 2, 3)); # OUTPUT: «[1, 2, 3]» | |
ok 2671 - doc/Type/Signature.pod6 chunk 28 compiles | |
# sub f(::T $p1, T $p2, ::C){ | |
# # $p1 and $p2 are of the same type T, that we don't know yet | |
# # C will hold a type we derive from a type object or value | |
# my C $closure = $p1 / $p2; | |
# return sub (T $p1) { | |
# $closure * $p1; | |
# } | |
# } | |
# # The first parameter is Int and so must be the 2nd. | |
# # We derive the 3rd type from calling the operator that is used in &f. | |
# my &s = f(10, 2, Int.new / Int.new); | |
# say s(2); # 10 / 2 * 2 == 10 | |
ok 2672 - doc/Type/Signature.pod6 chunk 29 compiles | |
# $ = :($a); # a positional parameter | |
# $ = :(:$a); # a named parameter of name 'a' | |
# $ = :(*@a); # a slurpy positional parameter | |
# $ = :(*%h); # a slurpy named parameter | |
ok 2673 - doc/Type/Signature.pod6 chunk 30 compiles | |
# sub pos($x, $y) { "x=$x y=$y" } | |
# pos(4, 5); # RESULT: «x=4 y=5» | |
ok 2674 - doc/Type/Signature.pod6 chunk 31 compiles | |
# sub named(:$x, :$y) { "x=$x y=$y" } | |
# named( y => 5, x => 4); # RESULT: «x=4 y=5» | |
ok 2675 - doc/Type/Signature.pod6 chunk 32 compiles | |
# sub named(:official($private)) { "Official business!" if $private } | |
# named :official; | |
ok 2676 - doc/Type/Signature.pod6 chunk 33 compiles | |
# sub ( :color(:colour($c)) ) { } # 'color' and 'colour' are both OK | |
# sub ( :color(:$colour) ) { } # same API for the caller | |
ok 2677 - doc/Type/Signature.pod6 chunk 34 compiles | |
# multi f(:$named) { note &?ROUTINE.signature }; | |
# multi f(:$also-named) { note &?ROUTINE.signature }; | |
# for 'named', 'also-named' -> $n { | |
# f(|($n => rand)) # RESULT: «(:$named)(:$also-named)» | |
# } | |
# my $pair = :named(1); | |
# f |$pair; # RESULT: «(:$named)» | |
ok 2678 - doc/Type/Signature.pod6 chunk 35 compiles | |
# sub f(:$also-named) { note &?ROUTINE.signature }; | |
# my %pairs = also-named => 4; | |
# f |%pairs; # «(:$also-named)» | |
ok 2679 - doc/Type/Signature.pod6 chunk 36 compiles | |
# class C { has $.x; has $.y; has @.z }; | |
# my %h = <x y z> Z=> (5, 20, [1,2]); | |
# say C.new(|%h.Map); | |
# # OUTPUT: «C.new(x => 5, y => 20, z => [1, 2])» | |
ok 2680 - doc/Type/Signature.pod6 chunk 37 compiles | |
# $ = :(Str $id); # required parameter | |
# $ = :($base = 10); # optional parameter, default value 10 | |
# $ = :(Int $x?); # optional parameter, default is the Int type object | |
ok 2681 - doc/Type/Signature.pod6 chunk 38 compiles | |
# $ = :(:%config); # optional parameter | |
# $ = :(:$debug = False); # optional parameter, defaults to False | |
# $ = :(:$name!); # mandatory 'name' named parameter | |
ok 2682 - doc/Type/Signature.pod6 chunk 39 compiles | |
# $ = :($goal, $accuracy = $goal / 100); | |
# $ = :(:$excludes = ['.', '..']); # a new Array for every call | |
ok 2683 - doc/Type/Signature.pod6 chunk 40 compiles | |
# sub first(@array ($first, *@rest)) { $first } | |
ok 2684 - doc/Type/Signature.pod6 chunk 41 compiles | |
# sub first([$f, *@]) { $f } | |
ok 2685 - doc/Type/Signature.pod6 chunk 42 compiles | |
# sub all-dimensions(% (:length(:$x), :width(:$y), :depth(:$z))) { | |
# $x andthen $y andthen $z andthen True | |
# } | |
ok 2686 - doc/Type/Signature.pod6 chunk 43 compiles | |
# for <Peter Paul Merry>.pairs -> (:key($index), :value($guest)) { } | |
ok 2687 - doc/Type/Signature.pod6 chunk 44 compiles | |
# sub foo(|c(Int, Str)){ | |
# put "called with {c.perl}" | |
# }; | |
# foo(42, "answer"); | |
# # OUTPUT: «called with \(42, "answer")» | |
ok 2688 - doc/Type/Signature.pod6 chunk 45 compiles | |
# multi sub f(Int $i, Str $s;; :$b) { dd $i, $s, $b }; | |
# f(10, 'answer'); | |
# # OUTPUT: «10"answer"Any $b = Any» | |
ok 2689 - doc/Type/Signature.pod6 chunk 46 compiles | |
# sub a(Int $i, Str $s) { say $i.WHAT, $s.WHAT } | |
# sub b(|c) { say c.WHAT; a(|c) } | |
# b(42, "answer"); | |
# # OUTPUT: «(Capture)(Int)(Str)» | |
ok 2690 - doc/Type/Signature.pod6 chunk 47 compiles | |
# sub count-up($x is copy) { | |
# $x = Inf if $x ~~ Whatever; | |
# .say for 1..$x; | |
# } | |
ok 2691 - doc/Type/Signature.pod6 chunk 48 compiles | |
# sub swap($x is rw, $y is rw) { | |
# ($x, $y) = ($y, $x); | |
# } | |
ok 2692 - doc/Type/Signature.pod6 chunk 49 compiles | |
# sub ip-expand-ipv6($ip is copy where m:i/^<[a..f\d\:]>**3..39$/) { } | |
ok 2693 - doc/Type/Signature.pod6 chunk 50 compiles | |
# method params(Signature:D: --> Positional) | |
ok 2694 - doc/Type/Signature.pod6 chunk 51 compiles | |
# method arity(Signature:D: --> Int:D) | |
ok 2695 - doc/Type/Signature.pod6 chunk 52 compiles | |
# method count(Signature:D: --> Real:D) | |
ok 2696 - doc/Type/Signature.pod6 chunk 53 compiles | |
# :($a, $b --> Int).returns # RESULT: «Int» | |
ok 2697 - doc/Type/Signature.pod6 chunk 54 compiles | |
# multi method ACCEPTS(Signature:D: Capture $topic) | |
# multi method ACCEPTS(Signature:D: @topic) | |
# multi method ACCEPTS(Signature:D: %topic) | |
# multi method ACCEPTS(Signature:D: Signature $topic) | |
ok 2698 - doc/Type/Signature.pod6 chunk 55 compiles | |
# (1, 2, :foo) ~~ :($a, $b, :foo($bar)); # RESULT: «True» | |
# <a b c d> ~~ :(Int $a); # RESULT: «False» | |
ok 2699 - doc/Type/Signature.pod6 chunk 56 compiles | |
# :($a, $b) ~~ :($foo, $bar, $baz?); # RESULT: «True» | |
# :(Int $n) ~~ :(Str); # RESULT: «False» | |
ok 2700 - doc/Type/Signature.pod6 chunk 57 compiles | |
# class Slip is List {} | |
ok 2701 - doc/Type/Slip.pod6 chunk 1 compiles | |
# say <a b c>.map({ ($_, $_.uc).Slip }).join('|'); # OUTPUT: «a|A|b|B|c|C» | |
ok 2702 - doc/Type/Slip.pod6 chunk 2 compiles | |
# say <a b c>.map({ $_, $_.uc }).join('|'); # OUTPUT: «a A|b B|c C» | |
ok 2703 - doc/Type/Slip.pod6 chunk 3 compiles | |
# # This says "1" and then says "2", rather than saying "(1 2)" | |
# .say for gather { | |
# take slip(1, 2); | |
# } | |
ok 2704 - doc/Type/Slip.pod6 chunk 4 compiles | |
# my $l = (1, 2, 3); | |
# say (1, slip 2, 3).perl; # says (1, 2, 3) , slips 2, 3 into (1, …) | |
# say (0, slip $l).perl; # says (0, $(1, 2, 3)), $l does not break apart | |
# say (0, $l.Slip).perl; # says (0, 1, 2, 3) , slips from $l into (0, …) | |
# say (|$l).perl; # says slip(1, 2, 3) , breaks apart $l | |
# say (0, (|$l, 4), 5); # says (0 (1 2 3 4) 5), slips from $l into (…, 4) | |
# say (0, ($l.Slip, 4), 5); # says (0 (1 2 3 4) 5), slips from $l into (…, 4) | |
# say (0, (slip $l, 4), 5); # says (0 (1 2 3) 4 5), slips ($l, 4) into (0, …, 5) | |
# say (0, ($l, 4).Slip, 5); # says (0 (1 2 3) 4 5), slips ($l, 4) into (0, …, 5) | |
ok 2705 - doc/Type/Slip.pod6 chunk 5 compiles | |
# my \l = gather for 1..10 -> $a, $b { take |($a, $b) }; say l.perl; | |
# # OUTPUT: «((1, 2), (3, 4), (5, 6), (7, 8), (9, 10)).Seq» | |
# my \m= gather for 1..10 -> $a, $b { take ($a, $b).Slip }; say m.perl; | |
# # OUTPUT: «(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).Seq» | |
ok 2706 - doc/Type/Slip.pod6 chunk 6 compiles | |
# sub slip(*@ --> Slip:D) | |
ok 2707 - doc/Type/Slip.pod6 chunk 7 compiles | |
# class Stash is Hash { } | |
ok 2708 - doc/Type/Stash.pod6 chunk 1 compiles | |
# class Boring { | |
# class Nested { }; | |
# our sub package_sub { } | |
# my sub lexical { }; | |
# method a_method() { } | |
# } | |
# say Boring::.^name; # OUTPUT: «Stash» | |
# say Boring.WHO === Boring::; # OUTPUT: «True» | |
ok 2709 - doc/Type/Stash.pod6 chunk 2 compiles | |
# class Str is Cool does Stringy { } | |
ok 2710 - doc/Type/Str.pod6 chunk 1 compiles | |
# multi sub chop(Str:D --> Str:D) | |
# multi method chop(Str:D: $chars = 1 --> Str:D) | |
ok 2711 - doc/Type/Str.pod6 chunk 2 compiles | |
# multi sub chomp(Str:D --> Str:D) | |
# multi method chomp(Str:D: --> Str:D) | |
ok 2712 - doc/Type/Str.pod6 chunk 3 compiles | |
# say chomp("abc\n"); # OUTPUT: «abc» | |
# say "def\r\n".chomp; # OUTPUT: «def» NOTE: \r\n is a single grapheme! | |
# say "foo\r".chomp; # OUTPUT: «foo» | |
ok 2713 - doc/Type/Str.pod6 chunk 4 compiles | |
# multi sub lc(Str:D --> Str:D) | |
# multi method lc(Str:D: --> Str:D) | |
ok 2714 - doc/Type/Str.pod6 chunk 5 compiles | |
# lc("A"); # RESULT: «"a"» | |
# "A".lc; # RESULT: «"a"» | |
ok 2715 - doc/Type/Str.pod6 chunk 6 compiles | |
# multi sub uc(Str:D --> Str:D) | |
# multi method uc(Str:D: --> Str:D) | |
ok 2716 - doc/Type/Str.pod6 chunk 7 compiles | |
# multi sub fc(Str:D --> Str:D) | |
# multi method fc(Str:D: --> Str:D) | |
ok 2717 - doc/Type/Str.pod6 chunk 8 compiles | |
# multi sub tc(Str:D --> Str:D) | |
# multi method tc(Str:D: --> Str:D) | |
ok 2718 - doc/Type/Str.pod6 chunk 9 compiles | |
# multi sub tclc(Str:D --> Str:D) | |
# multi method tclc(Str:D: --> Str:D) | |
ok 2719 - doc/Type/Str.pod6 chunk 10 compiles | |
# multi sub wordcase(Cool $x --> Str) | |
# multi sub wordcase(Str:D $x --> Str) | |
# multi method wordcase(Str:D: :&filter = &tclc, Mu :$where = True --> Str) | |
ok 2720 - doc/Type/Str.pod6 chunk 11 compiles | |
# multi method unival(Str:D --> Numeric) | |
ok 2721 - doc/Type/Str.pod6 chunk 12 compiles | |
# say '4'.unival; # OUTPUT: «4» | |
# say '¾'.unival; # OUTPUT: «0.75» | |
# say 'a'.unival; # OUTPUT: «NaN» | |
ok 2722 - doc/Type/Str.pod6 chunk 13 compiles | |
# multi method univals(Str:D --> List) | |
ok 2723 - doc/Type/Str.pod6 chunk 14 compiles | |
# say "4a¾".univals; # OUTPUT: «(4 NaN 0.75)» | |
ok 2724 - doc/Type/Str.pod6 chunk 15 compiles | |
# multi sub chars(Cool $x --> Int:D) | |
# multi sub chars(Str:D $x --> Int:D) | |
# multi sub chars(str $x --> int) | |
# multi method chars(Str:D: --> Int:D) | |
ok 2725 - doc/Type/Str.pod6 chunk 16 compiles | |
# multi method encode(Str:D: $encoding, $nf --> Blob) | |
ok 2726 - doc/Type/Str.pod6 chunk 17 compiles | |
# multi sub index(Cool $s, Str:D $needle, Cool $startpos = 0 --> Int) | |
# multi method index(Cool $needle, Cool $startpos = 0 --> Int) | |
ok 2727 - doc/Type/Str.pod6 chunk 18 compiles | |
# say index "Camelia is a butterfly", "a"; # OUTPUT: «1» | |
# say index "Camelia is a butterfly", "a", 2; # OUTPUT: «6» | |
# say index "Camelia is a butterfly", "er"; # OUTPUT: «17» | |
# say index "Camelia is a butterfly", "Camel"; # OUTPUT: «0» | |
# say index "Camelia is a butterfly", "Onion"; # OUTPUT: «Nil» | |
# say index("Camelia is a butterfly", "Onion").defined ?? 'OK' !! 'NOT'; # OUTPUT: «NOT» | |
ok 2728 - doc/Type/Str.pod6 chunk 19 compiles | |
# multi sub rindex(Str:D $haystack, Str:D $needle, Int $startpos = $haystack.chars --> Int) | |
# multi method rindex(Str:D $haystack: Str:D $needle, Int $startpos = $haystack.chars --> Int) | |
ok 2729 - doc/Type/Str.pod6 chunk 20 compiles | |
# say rindex "Camelia is a butterfly", "a"; # OUTPUT: «11» | |
# say rindex "Camelia is a butterfly", "a", 10; # OUTPUT: «6» | |
ok 2730 - doc/Type/Str.pod6 chunk 21 compiles | |
# method match($pat, :continue(:$c), :pos(:$p), :global(:$g), :overlap(:$ov), :exhaustive(:$ex), :st(:$nd), :rd(:$th), :$nth, :$x --> Match) | |
ok 2731 - doc/Type/Str.pod6 chunk 22 compiles | |
# say "properly".match('perl'); # OUTPUT: «「perl」» | |
# say "properly".match(/p.../); # OUTPUT: «「perl」» | |
# say "1 2 3".match([1,2,3]); # OUTPUT: «「1 2 3」» | |
# say "a1xa2".match(/a./, :continue(2)); # OUTPUT: «「a2」» | |
# say "abracadabra".match(/ a .* a /, :exhaustive); | |
# # OUTPUT: «(「abracadabra」 「abracada」 「abraca」 「abra」 「acadabra」 「acada」 「aca」 「adabra」 「ada」 「abra」)» | |
# say 'several words here'.match(/\w+/,:global); # OUTPUT: «(「several」 「words」 「here」)» | |
# say 'abcdef'.match(/.*/, :pos(2)); # OUTPUT: «「cdef」» | |
# say "foo[bar][baz]".match(/../, :1st); # OUTPUT: «「fo」» | |
# say "foo[bar][baz]".match(/../, :2nd); # OUTPUT: «「o[」» | |
# say "foo[bar][baz]".match(/../, :3rd); # OUTPUT: «「ba」» | |
# say "foo[bar][baz]".match(/../, :4th); # OUTPUT: «「r]」» | |
# say "foo[bar][baz]bada".match('ba', :x(2)); # OUTPUT: «(「ba」 「ba」)» | |
ok 2732 - doc/Type/Str.pod6 chunk 23 compiles | |
# multi sub parse-base(Str:D $num, Int:D $radix --> Numeric) | |
# multi method parse-base(Str:D $num: Int:D $radix --> Numeric) | |
ok 2733 - doc/Type/Str.pod6 chunk 24 compiles | |
# 1337.base(32).parse-base(32).say; # OUTPUT: «1337» | |
# 'Perl6'.parse-base(30).say; # OUTPUT: «20652936» | |
# 'FF.DD'.parse-base(16).say; # OUTPUT: «255.863281» | |
ok 2734 - doc/Type/Str.pod6 chunk 25 compiles | |
# say split(";", "a;b;c").perl; # OUTPUT: «("a", "b", "c")» | |
# say split(";", "a;b;c", :v).perl; # OUTPUT: «("a", ";", "b", ";", "c")» | |
# say split(";", "a;b;c", 2).perl; # OUTPUT: «("a", "b;c").Seq» | |
# say split(";", "a;b;c", 2, :v).perl; # OUTPUT: «("a", ";", "b;c")» | |
# say split(";", "a;b;c,d").perl; # OUTPUT: «("a", "b", "c,d")» | |
# say split(/\;/, "a;b;c,d").perl; # OUTPUT: «("a", "b", "c,d")» | |
# say split(<; ,>, "a;b;c,d").perl; # OUTPUT: «("a", "b", "c", "d")» | |
# say split(/<[;,]>/, "a;b;c,d").perl; # OUTPUT: «("a", "b", "c", "d")» | |
# say split(<; ,>, "a;b;c,d", :k).perl; # OUTPUT: «("a", 0, "b", 0, "c", 1, "d")» | |
# say split(<; ,>, "a;b;c,d", :kv).perl; # OUTPUT: «("a", 0, ";", "b", 0, ";", "c", 1, ",", "d")» | |
# say "".split("x").perl; # OUTPUT: «("",)» | |
# say "".split("x", :skip-empty).perl; # OUTPUT: «("",)» | |
# say "abcde".split("").perl; # OUTPUT: «("", "a", "b", "c", "d", "e", "")» | |
# say "abcde".split("",:skip-empty).perl; # OUTPUT: «("a", "b", "c", "d", "e")» | |
ok 2735 - doc/Type/Str.pod6 chunk 26 compiles | |
# multi sub comb(Str:D $matcher, Str:D $input, $limit = Inf) | |
# multi sub comb(Regex:D $matcher, Str:D $input, $limit = Inf, Bool :$match) | |
# multi sub comb(Int:D $size, Str:D $input, $limit = Inf) | |
# multi method comb(Str:D $input:) | |
# multi method comb(Str:D $input: Str:D $matcher, $limit = Inf) | |
# multi method comb(Str:D $input: Regex:D $matcher, $limit = Inf, Bool :$match) | |
# multi method comb(Str:D $input: Int:D $size, $limit = Inf) | |
ok 2736 - doc/Type/Str.pod6 chunk 27 compiles | |
# say "abc".comb.perl; # OUTPUT: «("a", "b", "c").Seq» | |
# say 'abcdefghijk'.comb(3).perl; # OUTPUT: «("abc", "def", "ghi", "jk").Seq» | |
# say 'abcdefghijk'.comb(3, 2).perl; # OUTPUT: «("abc", "def").Seq» | |
# say comb(/\w/, "a;b;c").perl; # OUTPUT: «("a", "b", "c").Seq» | |
# say comb(/\N/, "a;b;c").perl; # OUTPUT: «("a", ";", "b", ";", "c").Seq» | |
# say comb(/\w/, "a;b;c", 2).perl; # OUTPUT: «("a", "b").Seq» | |
# say comb(/\w\;\w/, "a;b;c", 2).perl; # OUTPUT: «("a;b",).Seq» | |
ok 2737 - doc/Type/Str.pod6 chunk 28 compiles | |
# multi sub lines(Str:D $input, $limit = Inf --> Positional) | |
# multi method lines(Str:D $input: $limit = Inf --> Positional) | |
ok 2738 - doc/Type/Str.pod6 chunk 29 compiles | |
# say lines("a\nb").perl; # OUTPUT: «("a", "b").Seq» | |
# say lines("a\nb").elems; # OUTPUT: «2» | |
# say "a\nb".lines.elems; # OUTPUT: «2» | |
# say "a\n".lines.elems; # OUTPUT: «1» | |
ok 2739 - doc/Type/Str.pod6 chunk 30 compiles | |
# multi sub words(Str:D $input, $limit = Inf --> Positional) | |
# multi method words(Str:D $input: $limit = Inf --> Positional) | |
ok 2740 - doc/Type/Str.pod6 chunk 31 compiles | |
# say "a\nb\n".words.perl; # OUTPUT: «("a", "b").Seq» | |
# say "hello world".words.perl; # OUTPUT: «("hello", "world").Seq» | |
# say "foo:bar".words.perl; # OUTPUT: «("foo:bar",).Seq» | |
# say "foo:bar\tbaz".words.perl; # OUTPUT: «("foo:bar", "baz").Seq» | |
ok 2741 - doc/Type/Str.pod6 chunk 32 compiles | |
# multi sub flip(Str:D --> Str:D) | |
# multi method flip(Str:D: --> Str:D) | |
ok 2742 - doc/Type/Str.pod6 chunk 33 compiles | |
# "Perl".flip; # RESULT: «lreP» | |
# "ABBA".flip; # RESULT: «ABBA» | |
ok 2743 - doc/Type/Str.pod6 chunk 34 compiles | |
# multi sub sprintf( Str:D $format, *@args --> Str:D) | |
ok 2744 - doc/Type/Str.pod6 chunk 35 compiles | |
# grammar Str::SprintfFormat { | |
# regex format_token { '%': <index>? <precision>? <modifier>? <directive> } | |
# token index { \d+ '$' } | |
# token precision { <flags>? <vector>? <precision_count> } | |
# token flags { <[ \x20 + 0 \# \- ]>+ } | |
# token precision_count { [ <[1..9]>\d* | '*' ]? [ '.' [ \d* | '*' ] ]? } | |
# token vector { '*'? v } | |
# token modifier { < ll l h V q L > } | |
# token directive { < % c s d u o x e f g X E G b p n i D U O F > } | |
# } | |
ok 2745 - doc/Type/Str.pod6 chunk 36 compiles | |
# sprintf '%2$d %1$d', 12, 34; # OUTPUT: «34 12» | |
# sprintf '%3$d %d %1$d', 1, 2, 3; # OUTPUT: «3 1 1» | |
ok 2746 - doc/Type/Str.pod6 chunk 37 compiles | |
# sprintf '<% d>', 12; # OUTPUT: «< 12>» | |
# sprintf '<% d>', 0; # OUTPUT: «< 0>"» | |
# sprintf '<% d>', -12; # OUTPUT: «<-12>» | |
# sprintf '<%+d>', 12; # OUTPUT: «<+12>» | |
# sprintf '<%+d>', 0; # OUTPUT: «<+0>"» | |
# sprintf '<%+d>', -12; # OUTPUT: «<-12>» | |
# sprintf '<%6s>', 12; # OUTPUT: «< 12>» | |
# sprintf '<%-6s>', 12; # OUTPUT: «<12 >» | |
# sprintf '<%06s>', 12; # OUTPUT: «<000012>» | |
# sprintf '<%#o>', 12; # OUTPUT: «<014>» | |
# sprintf '<%#x>', 12; # OUTPUT: «<0xc>» | |
# sprintf '<%#X>', 12; # OUTPUT: «<0XC>» | |
# sprintf '<%#b>', 12; # OUTPUT: «<0b1100>» | |
# sprintf '<%#B>', 12; # OUTPUT: «<0B1100>» | |
ok 2747 - doc/Type/Str.pod6 chunk 38 compiles | |
# sprintf '<%+ d>', 12; # OUTPUT: «<+12>» | |
# sprintf '<% +d>', 12; # OUTPUT: «<+12>» | |
ok 2748 - doc/Type/Str.pod6 chunk 39 compiles | |
Potential difficulties: | |
Leading 0 does not indicate octal in Perl 6. Please use 0o12 if you mean that. | |
at /Users/williamcoleda/sandbox/doc/EVAL_2751:2 | |
------> [32m class :: {sprintf '<%#.5o>', 012[33m⏏[31m; # OUTPUT: «<000012>»[0m | |
Leading 0 does not indicate octal in Perl 6. Please use 0o12345 if you mean that. | |
at /Users/williamcoleda/sandbox/doc/EVAL_2751:3 | |
------> [32msprintf '<%#.5o>', 012345[33m⏏[31m; # OUTPUT: «<012345>»[0m | |
# sprintf '<%#.5o>', 012; # OUTPUT: «<000012>» | |
# sprintf '<%#.5o>', 012345; # OUTPUT: «<012345>» | |
# sprintf '<%#.0o>', 0; # OUTPUT: «<>» # zero precision results in no output! | |
ok 2749 - doc/Type/Str.pod6 chunk 40 compiles | |
# sprintf "<%s>", "a"; # OUTPUT: «<a>» | |
# sprintf "<%6s>", "a"; # OUTPUT: «< a>» | |
# sprintf "<%*s>", 6, "a"; # OUTPUT: «< a>» | |
ok 2750 - doc/Type/Str.pod6 chunk 41 compiles | |
# sprintf "<%2s>", "long"; # OUTPUT: «<long>» (does not truncate) | |
ok 2751 - doc/Type/Str.pod6 chunk 42 compiles | |
# # these examples are subject to system-specific variation | |
# sprintf '<%f>', 1; # OUTPUT: «"<1.000000>"» | |
# sprintf '<%.1f>', 1; # OUTPUT: «"<1.0>"» | |
# sprintf '<%.0f>', 1; # OUTPUT: «"<1>"» | |
# sprintf '<%e>', 10; # OUTPUT: «"<1.000000e+01>"» | |
# sprintf '<%.1e>', 10; # OUTPUT: «"<1.0e+01>"» | |
ok 2752 - doc/Type/Str.pod6 chunk 43 compiles | |
# # These examples are subject to system-specific variation. | |
# sprintf '<%g>', 1; # OUTPUT: «<1>» | |
# sprintf '<%.10g>', 1; # OUTPUT: «<1>» | |
# sprintf '<%g>', 100; # OUTPUT: «<100>» | |
# sprintf '<%.1g>', 100; # OUTPUT: «<1e+02>» | |
# sprintf '<%.2g>', 100.01; # OUTPUT: «<1e+02>» | |
# sprintf '<%.5g>', 100.01; # OUTPUT: «<100.01>» | |
# sprintf '<%.4g>', 100.01; # OUTPUT: «<100>» | |
ok 2753 - doc/Type/Str.pod6 chunk 44 compiles | |
# sprintf '<%.5s>', "truncated"; # OUTPUT: «<trunc>» | |
# sprintf '<%10.5s>', "truncated"; # OUTPUT: «< trunc>» | |
ok 2754 - doc/Type/Str.pod6 chunk 45 compiles | |
# sprintf '<%.*s>', 7, "string"; # OUTPUT: «<string>» | |
# sprintf '<%.*s>', 3, "string"; # OUTPUT: «<str>» | |
# sprintf '<%.*s>', 0, "string"; # OUTPUT: «<>» | |
# sprintf '<%.*s>', -1, "string"; # OUTPUT: «<string>» | |
# sprintf '<%.*d>', 1, 0; # OUTPUT: «<0>» | |
# sprintf '<%.*d>', 0, 0; # OUTPUT: «<>» | |
# sprintf '<%.*d>', -1, 0; # OUTPUT: «<0>» | |
ok 2755 - doc/Type/Str.pod6 chunk 46 compiles | |
# my $a = 5; my $b = 2; my $c = 'net'; | |
# sprintf "<%*.*s>", $a, $b, $c; # OUTPUT: «< ne>» | |
ok 2756 - doc/Type/Str.pod6 chunk 47 compiles | |
# sprintf Q:b "<b>%s</b>\n", "Perl 6"; # OUTPUT: «<b>Perl 6</b>» | |
# sprintf "<b>\%s</b>\n", "Perl 6"; # OUTPUT: «<b>Perl 6</b>» | |
# sprintf "<b>%s\</b>\n", "Perl 6"; # OUTPUT: «<b>Perl 6</b>» | |
ok 2757 - doc/Type/Str.pod6 chunk 48 compiles | |
# multi method starts-with(Str:D: Str(Cool) $needle --> True:D) | |
ok 2758 - doc/Type/Str.pod6 chunk 49 compiles | |
# say "Hello, World".starts-with("Hello"); # OUTPUT: «True» | |
# say "https://perl6.org/".starts-with('ftp'); # OUTPUT: «False» | |
ok 2759 - doc/Type/Str.pod6 chunk 50 compiles | |
# multi method ends-with(Str:D: Str(Cool) $needle --> True:D) | |
ok 2760 - doc/Type/Str.pod6 chunk 51 compiles | |
# say "Hello, World".ends-with('Hello'); # OUTPUT: «False» | |
# say "Hello, World".ends-with('ld'); # OUTPUT: «True» | |
ok 2761 - doc/Type/Str.pod6 chunk 52 compiles | |
# multi method subst(Str:D: $matcher, $replacement, *%opts) | |
ok 2762 - doc/Type/Str.pod6 chunk 53 compiles | |
# my $some-string = "Some foo"; | |
# my $another-string = $some-string.subst(/foo/, "string"); # gives 'Some string' | |
# $some-string.=subst(/foo/, "string"); # in-place substitution. $some-string is now 'Some string' | |
ok 2763 - doc/Type/Str.pod6 chunk 54 compiles | |
# my $i = 41; | |
# my $str = "The answer is secret."; | |
# my $real-answer = $str.subst(/secret/, {++$i}); # The answer to everything | |
ok 2764 - doc/Type/Str.pod6 chunk 55 compiles | |
# my $str = "Hey foo foo foo"; | |
# $str.subst(/foo/, "bar", :g); # global substitution - returns Hey bar bar bar | |
# $str.subst(/foo/, "no subst", :x(0)); # targeted substitution. Number of times to substitute. Returns back unmodified. | |
# $str.subst(/foo/, "bar", :x(1)); #replace just the first occurrence. | |
# $str.subst(/foo/, "bar", :nth(3)); # replace nth match alone. Replaces the third foo. Returns Hey foo foo bar | |
ok 2765 - doc/Type/Str.pod6 chunk 56 compiles | |
# say 'ooooo'.subst: 'o', 'x', :1st; # OUTPUT: «xoooo» | |
# say 'ooooo'.subst: 'o', 'x', :2nd; # OUTPUT: «oxooo» | |
# say 'ooooo'.subst: 'o', 'x', :3rd; # OUTPUT: «ooxoo» | |
# say 'ooooo'.subst: 'o', 'x', :4th; # OUTPUT: «oooxo» | |
ok 2766 - doc/Type/Str.pod6 chunk 57 compiles | |
# my $some-string = "Some foo"; | |
# my $match = $some-string.subst-mutate(/foo/, "string"); | |
# say $some-string; # OUTPUT: «Some string» | |
# say $match; # OUTPUT: «「foo」» | |
# $some-string.subst-mutate(/<[oe]>/, '', :g); # remove every o and e, notice the :g named argument from .subst | |
ok 2767 - doc/Type/Str.pod6 chunk 58 compiles | |
# multi sub substr(Str:D $s, Int:D $from, Int:D $chars = $s.chars - $from --> Str:D) | |
# multi sub substr(Str:D $s, Range $from-to --> Str:D) | |
# multi method substr(Str:D $s: Int:D $from, Int:D $chars = $s.chars - $from --> Str:D) | |
# multi method substr(Str:D $s: Range $from-to --> Str:D) | |
ok 2768 - doc/Type/Str.pod6 chunk 59 compiles | |
# substr("Long string", 6, 3); # RESULT: «tri» | |
# substr("Long string", 6); # RESULT: «tring» | |
# substr("Long string", 6, *-1); # RESULT: «trin» | |
# substr("Long string", *-3, *-1); # RESULT: «in» | |
ok 2769 - doc/Type/Str.pod6 chunk 60 compiles | |
# multi method substr-eq(Str:D: Str(Cool) $test-string, Int(Cool) $from --> Bool) | |
# multi method substr-eq(Cool:D: Str(Cool) $test-string, Int(Cool) $from --> Bool) | |
ok 2770 - doc/Type/Str.pod6 chunk 61 compiles | |
# my $string = "foobar"; | |
# say $string.substr-eq("bar", 3); # OUTPUT: «True» | |
ok 2771 - doc/Type/Str.pod6 chunk 62 compiles | |
# my $string = "foobar"; | |
# say $string.substr-eq("barz", 3); # OUTPUT: «False» | |
ok 2772 - doc/Type/Str.pod6 chunk 63 compiles | |
# my $string = "foobar"; | |
# say $string.substr-eq("foobar", 0); # OUTPUT: «True» | |
ok 2773 - doc/Type/Str.pod6 chunk 64 compiles | |
# my $integer = 342; | |
# say $integer.substr-eq(42, 1); # OUTPUT: «True» | |
ok 2774 - doc/Type/Str.pod6 chunk 65 compiles | |
# my $integer = 342; | |
# say $integer.substr-eq(342, 0); # OUTPUT: «True» | |
ok 2775 - doc/Type/Str.pod6 chunk 66 compiles | |
# my $integer = 342; | |
# say $integer.substr-eq(42, 3); # OUTPUT: «False» | |
# say $integer.substr-eq(7342, 0); # OUTPUT: «False» | |
ok 2776 - doc/Type/Str.pod6 chunk 67 compiles | |
# method substr-rw($from, $length?) | |
ok 2777 - doc/Type/Str.pod6 chunk 68 compiles | |
# my $string = "abc"; | |
# $string.substr-rw(1, 1) = "z"; | |
# $string.say; # OUTPUT: «azc» | |
ok 2778 - doc/Type/Str.pod6 chunk 69 compiles | |
# my $string = "abc"; | |
# substr-rw($string, 1, 1) = "z"; | |
# $string.say; # OUTPUT: «azc» | |
ok 2779 - doc/Type/Str.pod6 chunk 70 compiles | |
# my $string = "A character in the 'Flintstones' is: barney"; | |
# $string ~~ /(barney)/; | |
# my $ref := substr-rw($string, $0.from, $0.to); | |
# $string.say; | |
# # OUTPUT: «A character in the 'Flintstones' is: barney» | |
# $ref = "fred"; | |
# $string.say; | |
# # OUTPUT: «A character in the 'Flintstones' is: fred» | |
# $ref = "wilma"; | |
# $string.say; | |
# # OUTPUT: «A character in the 'Flintstones' is: wilma» | |
ok 2780 - doc/Type/Str.pod6 chunk 71 compiles | |
# multi sub samemark(Str:D $string, Str:D $pattern --> Str:D) | |
# method samemark(Str:D: Str:D $pattern --> Str:D) | |
ok 2781 - doc/Type/Str.pod6 chunk 72 compiles | |
# say 'åäö'.samemark('aäo'); # OUTPUT: «aäo» | |
# say 'åäö'.samemark('a'); # OUTPUT: «aao» | |
# say samemark('Pêrl', 'a'); # OUTPUT: «Perl» | |
# say samemark('aöä', ''); # OUTPUT: «aöä» | |
ok 2782 - doc/Type/Str.pod6 chunk 73 compiles | |
# method succ(Str:D --> Str:D) | |
ok 2783 - doc/Type/Str.pod6 chunk 74 compiles | |
# '12.34'.succ; # RESULT: «13.34» | |
# 'img001.png'.succ; # RESULT: «img002.png» | |
ok 2784 - doc/Type/Str.pod6 chunk 75 compiles | |
# 'aa'.succ; # RESULT: «ab» | |
# 'az'.succ; # RESULT: «ba» | |
# '109'.succ; # RESULT: «110» | |
# 'α'.succ; # RESULT: «β» | |
# 'a9'.succ; # RESULT: «b0» | |
ok 2785 - doc/Type/Str.pod6 chunk 76 compiles | |
# method pred(Str:D: --> Str:D) | |
ok 2786 - doc/Type/Str.pod6 chunk 77 compiles | |
# multi sub ord(Str:D --> Int:D) | |
# multi method ord(Str:D: --> Int:D) | |
ok 2787 - doc/Type/Str.pod6 chunk 78 compiles | |
# ord("A"); # 65 | |
# "«".ord; # 171 | |
ok 2788 - doc/Type/Str.pod6 chunk 79 compiles | |
# multi method ords(Str:D: --> Positional) | |
ok 2789 - doc/Type/Str.pod6 chunk 80 compiles | |
# "aå«".ords; # (97 229 171) | |
ok 2790 - doc/Type/Str.pod6 chunk 81 compiles | |
# multi method trans(Str:D: Pair:D \what, *%n --> Str) | |
# multi method trans(Str:D: *@changes, :complement(:$c), :squash(:$s), :delete(:$d) --> Str) | |
ok 2791 - doc/Type/Str.pod6 chunk 82 compiles | |
# my $str = 'say $x<b> && $y<a>'; | |
# $str.=trans( '<' => '«' ); | |
# $str.=trans( '<' => '«', '>' => '»' ); | |
# $str.=trans( [ '<' , '>' , '&' ] => | |
# [ '<', '>', '&' ]); | |
# $str.=trans( ['a'..'y'] => ['A'..'z'] ); | |
# "abcdefghij".trans(/<[aeiou]> \w/ => ''); # RESULT: «cdgh» | |
# "a123b123c".trans(['a'..'z'] => 'x', :complement); # RESULT: «axxxbxxxc» | |
# "a123b123c".trans('23' => '', :delete); # RESULT: «a1b1c» | |
# "aaa1123bb123c".trans('a'..'z' => 'A'..'Z', :squash); # RESULT: «A1123B123C» | |
# "aaa1123bb123c".trans('a'..'z' => 'x', :complement, :squash); # RESULT: «aaaxbbxc» | |
ok 2792 - doc/Type/Str.pod6 chunk 83 compiles | |
# multi method indent(Int $steps where { $_ == 0 } ) | |
# multi method indent(Int $steps where { $_ > 0 } ) | |
# multi method indent($steps where { .isa(Whatever) || .isa(Int) && $_ < 0 } ) | |
ok 2793 - doc/Type/Str.pod6 chunk 84 compiles | |
# " indented by 2 spaces\n indented even more".indent(*) | |
# eq "indented by 2 spaces\n indented even more" | |
ok 2794 - doc/Type/Str.pod6 chunk 85 compiles | |
# method trim(Str:D: --> Str) | |
ok 2795 - doc/Type/Str.pod6 chunk 86 compiles | |
# my $line = ' hello world '; | |
# say '<' ~ $line.trim ~ '>'; # OUTPUT: «<hello world>» | |
# say '<' ~ trim($line) ~ '>'; # OUTPUT: «<hello world>» | |
# $line.trim; | |
# say '<' ~ $line ~ '>'; # OUTPUT: «< hello world >» | |
# $line.=trim; | |
# say '<' ~ $line ~ '>'; # OUTPUT: «<hello world>» | |
ok 2796 - doc/Type/Str.pod6 chunk 87 compiles | |
# method trim-trailing(Str:D: --> Str) | |
ok 2797 - doc/Type/Str.pod6 chunk 88 compiles | |
# method trim-leading(Str:D: --> Str) | |
ok 2798 - doc/Type/Str.pod6 chunk 89 compiles | |
# method NFC(Str:D: --> NFC:D) | |
ok 2799 - doc/Type/Str.pod6 chunk 90 compiles | |
# method NFD(Str:D: --> NFD:D) | |
ok 2800 - doc/Type/Str.pod6 chunk 91 compiles | |
# method NFKC(Str:D: --> NFKC:D) | |
ok 2801 - doc/Type/Str.pod6 chunk 92 compiles | |
# method NFKD(Str:D: --> NFKD:D) | |
ok 2802 - doc/Type/Str.pod6 chunk 93 compiles | |
# multi method ACCEPTS(Str:D: $other) | |
ok 2803 - doc/Type/Str.pod6 chunk 94 compiles | |
# multi sub val(Str:D $MAYBEVAL, :$val-or-fail) | |
ok 2804 - doc/Type/Str.pod6 chunk 95 compiles | |
# say val("42").WHAT; # OUTPUT: «(IntStr)» | |
# say val("42e0").WHAT; # OUTPUT: «(NumStr)» | |
# say val("42.0").WHAT; # OUTPUT: «(RatStr)» | |
# say val("42+0i").WHAT; # OUTPUT: «(ComplexStr)» | |
ok 2805 - doc/Type/Str.pod6 chunk 96 compiles | |
# role Stringy { ... } | |
ok 2806 - doc/Type/Stringy.pod6 chunk 1 compiles | |
# class Sub is Routine { } | |
ok 2807 - doc/Type/Sub.pod6 chunk 1 compiles | |
# my $s = sub ($a, $b) { $a + $b }; | |
# say $s.WHAT; # OUTPUT: «(Sub)» | |
# say $s(2, 5); # OUTPUT: «7» | |
# sub postfix:<♥>($a){ say „I love $a!“ } | |
# 42♥; | |
# # OUTPUT: «I love 42!» | |
# sub postcircumfix:<⸨ ⸩>(Positional $a, Whatever){ say $a[0], '…', $a[*-1] } | |
# [1,2,3,4]⸨*⸩; | |
# # OUTPUT: «1…4» | |
# constant term:<♥> = "♥"; # We don't want to quote "love", do we? | |
# sub circumfix:<α ω>($a){ say „$a is the beginning and the end.“ }; | |
# α♥ω; | |
# # OUTPUT: «♥ is the beginning and the end.» | |
ok 2808 - doc/Type/Sub.pod6 chunk 2 compiles | |
# sub Int(Str $s){'oi‽'}; | |
# say [Int, Int('42'),&Int('42')]; | |
# # OUTPUT: «[(Int) 42 oi‽]» | |
ok 2809 - doc/Type/Sub.pod6 chunk 3 compiles | |
# say 'start'; | |
# multi sub trait_mod:<is>(Sub $s, :$foo){ | |
# say "⟨is foo⟩ has been called with ⟨$foo⟩ on {$s.WHICH}"; | |
# } | |
# sub bar() is foo<oi‽> { | |
# say 'bar has been called' | |
# } | |
# bar(); | |
# # OUTPUT: «⟨is foo⟩ has been called with ⟨oi‽⟩ on Sub|47563000startbar has been called» | |
ok 2810 - doc/Type/Sub.pod6 chunk 4 compiles | |
# multi trait_mod:<is>(Variable $a, :@foo [$firstpos, *@restpos, :$named, *%restnameds]) { | |
# say [$firstpos, @restpos, $named, %restnameds] | |
# } | |
# my $x is foo[1,2,3,:named<a>, :2b, :3c] = 1 | |
# # OUTPUT: «[1 [2 3] a {b => 2, c => 3}]» | |
ok 2811 - doc/Type/Sub.pod6 chunk 5 compiles | |
# multi sub trait_mod:<is> (Sub $s, :$foo) is foo { | |
# say 'is foo called' | |
# } | |
# sub bar {} | |
# &trait_mod:<is>(&bar, :foo); | |
# # OUTPUT: «is foo calledis foo called» | |
ok 2812 - doc/Type/Sub.pod6 chunk 6 compiles | |
# class Submethod is Routine {} | |
ok 2813 - doc/Type/Submethod.pod6 chunk 1 compiles | |
# class Area { | |
# has $.size; | |
# submethod BUILD(:$x, :$y, :$z) { | |
# $!size = $x * $y * $z; | |
# } | |
# } | |
ok 2814 - doc/Type/Submethod.pod6 chunk 2 compiles | |
# class Supplier { } | |
ok 2815 - doc/Type/Supplier.pod6 chunk 1 compiles | |
# my $supplier = Supplier.new; | |
# my $supply_1 = $supplier.Supply; | |
# $supply_1.tap(-> $v { say "One $v" }); | |
# my $supply_2 = $supplier.Supply; | |
# $supply_2.tap(-> $v { say "Two $v" }); | |
# $supplier.emit(42); | |
ok 2816 - doc/Type/Supplier.pod6 chunk 2 compiles | |
# method new() | |
ok 2817 - doc/Type/Supplier.pod6 chunk 3 compiles | |
# method Supply(Supplier:D: --> Supply) | |
ok 2818 - doc/Type/Supplier.pod6 chunk 4 compiles | |
# method emit(Supplier:D: Mu \value) | |
ok 2819 - doc/Type/Supplier.pod6 chunk 5 compiles | |
# method done(Supplier:D:) | |
ok 2820 - doc/Type/Supplier.pod6 chunk 6 compiles | |
# my $supplier = Supplier.new; | |
# my $supply = $supplier.Supply; | |
# $supply.tap(-> $v { say $v }, done => { say "no more answers" }); | |
# $supplier.emit(42); | |
# $supplier.done; | |
ok 2821 - doc/Type/Supplier.pod6 chunk 7 compiles | |
# multi method quit(Supplier:D: Exception $ex) | |
# multi method quit(Supplier:D: Str() $message) | |
ok 2822 - doc/Type/Supplier.pod6 chunk 8 compiles | |
# class Supply {} | |
ok 2823 - doc/Type/Supply.pod6 chunk 1 compiles | |
# my $supplier = Supplier.new; | |
# my $supply = $supplier.Supply; | |
# $supply.tap(-> $v { say "$v" }); | |
# $supplier.emit(42); # Will cause the tap to output "42" | |
ok 2824 - doc/Type/Supply.pod6 chunk 2 compiles | |
# my $s = Supply.from-list(0 .. 5); | |
# my $t = $s.tap(-> $v { say $v }, done => { say "no more ticks" }); | |
ok 2825 - doc/Type/Supply.pod6 chunk 3 compiles | |
# method act(Supply:D: &act --> Tap:D) | |
ok 2826 - doc/Type/Supply.pod6 chunk 4 compiles | |
# method Channel(Supply:D: --> Channel:D) | |
ok 2827 - doc/Type/Supply.pod6 chunk 5 compiles | |
# method Promise(Supply:D: --> Promise:D) | |
ok 2828 - doc/Type/Supply.pod6 chunk 6 compiles | |
# my $supplier = Supplier.new; | |
# my $s = $supplier.Supply; | |
# my $p = $s.Promise; | |
# $p.then(-> $v { say "got $v.result()" }); | |
# $supplier.emit('cha'); # not output yet | |
# $supplier.done(); # got cha | |
ok 2829 - doc/Type/Supply.pod6 chunk 7 compiles | |
# method live(Supply:D: --> Bool:D) | |
ok 2830 - doc/Type/Supply.pod6 chunk 8 compiles | |
# say Supplier.new.Supply.live; # OUTPUT: «True» | |
ok 2831 - doc/Type/Supply.pod6 chunk 9 compiles | |
# method schedule-on(Supply:D: $scheduler) | |
ok 2832 - doc/Type/Supply.pod6 chunk 10 compiles | |
# method wait(Supply:D:) | |
ok 2833 - doc/Type/Supply.pod6 chunk 11 compiles | |
# my $s = Supplier.new; | |
# start { | |
# sleep 1; | |
# say "One second: running."; | |
# sleep 1; | |
# $s.emit(42); | |
# $s.done; | |
# } | |
# $s.Supply.wait; | |
# say "Two seconds: done"; | |
ok 2834 - doc/Type/Supply.pod6 chunk 12 compiles | |
# method list(Supply:D: --> List:D) | |
ok 2835 - doc/Type/Supply.pod6 chunk 13 compiles | |
# method grab(Supply:D: &process --> Supply:D) | |
ok 2836 - doc/Type/Supply.pod6 chunk 14 compiles | |
# method reverse(Supply:D: --> Supply:D) | |
ok 2837 - doc/Type/Supply.pod6 chunk 15 compiles | |
# method sort(Supply:D: &by? --> Supply:D) | |
ok 2838 - doc/Type/Supply.pod6 chunk 16 compiles | |
# method from-list(Supply:U: *@values --> Supply:D) | |
ok 2839 - doc/Type/Supply.pod6 chunk 17 compiles | |
# my $s = Supply.from-list(1, 2, 3); | |
# $s.tap(&say); # OUTPUT: «123» | |
ok 2840 - doc/Type/Supply.pod6 chunk 18 compiles | |
# method share(Supply:D: --> Supply:D) | |
ok 2841 - doc/Type/Supply.pod6 chunk 19 compiles | |
# # this says in turn: "first 1" "first 2" "second 2" "first 3" "second 3" | |
# my $s = Supply.interval(1).share; | |
# $s.tap: { "first $_".say }; | |
# sleep 1.1; | |
# $s.tap: { "second $_".say }; | |
# sleep 2 | |
ok 2842 - doc/Type/Supply.pod6 chunk 20 compiles | |
# method flat(Supply:D: --> Supply:D) | |
ok 2843 - doc/Type/Supply.pod6 chunk 21 compiles | |
# method do(Supply:D: &do --> Supply:D) | |
ok 2844 - doc/Type/Supply.pod6 chunk 22 compiles | |
# method interval(Supply:U: $interval, $delay = 0 --> Supply:D) | |
ok 2845 - doc/Type/Supply.pod6 chunk 23 compiles | |
# method grep(Supply:D: Mu $test --> Supply:D) | |
ok 2846 - doc/Type/Supply.pod6 chunk 24 compiles | |
# my $supplier = Supplier.new; | |
# my $all = $supplier.Supply; | |
# my $ints = $all.grep(Int); | |
# $ints.tap(&say); | |
# $supplier.emit($_) for 1, 'a string', 3.14159; # prints only 1 | |
ok 2847 - doc/Type/Supply.pod6 chunk 25 compiles | |
# method map(Supply:D: &mapper --> Supply:D) | |
ok 2848 - doc/Type/Supply.pod6 chunk 26 compiles | |
# my $supplier = Supplier.new; | |
# my $all = $supplier.Supply; | |
# my $double = $all.map(-> $value { $value * 2 }); | |
# $double.tap(&say); | |
# $supplier.emit(4); # RESULT: «8» | |
ok 2849 - doc/Type/Supply.pod6 chunk 27 compiles | |
# method batch(Supply:D: :$elems, :$seconds --> Supply:D) | |
ok 2850 - doc/Type/Supply.pod6 chunk 28 compiles | |
# method elems(Supply:D: $seconds? --> Supply:D) | |
ok 2851 - doc/Type/Supply.pod6 chunk 29 compiles | |
# method head(Supply:D: Int(Cool) $number = 1 --> Supply:D) | |
ok 2852 - doc/Type/Supply.pod6 chunk 30 compiles | |
# method tail(Supply:D: Int(Cool) $number = 1 --> Supply:D) | |
ok 2853 - doc/Type/Supply.pod6 chunk 31 compiles | |
# method rotor(Supply:D: @cycle --> Supply:D) | |
ok 2854 - doc/Type/Supply.pod6 chunk 32 compiles | |
# method delayed(Supply:D: $seconds --> Supply:D) | |
ok 2855 - doc/Type/Supply.pod6 chunk 33 compiles | |
# my $s = Supply.from-list(^6); # set up supply | |
# my $t = $s.throttle: 3, # only allow 3 at a time | |
# { # code block to run | |
# say "running $_"; # announce we've started | |
# sleep rand; # wait some random time | |
# say "done $_" # announce we're done | |
# } # don't need ; because } at end of line | |
# $t.wait; # wait for the supply to be done | |
ok 2856 - doc/Type/Supply.pod6 chunk 34 compiles | |
# method stable(Supply:D: $seconds, :$scheduler --> Supply:D) | |
ok 2857 - doc/Type/Supply.pod6 chunk 35 compiles | |
# method reduce(Supply:D: &with --> Supply:D) | |
ok 2858 - doc/Type/Supply.pod6 chunk 36 compiles | |
# method lines(Supply:D: :$chomp = True --> Supply:D) | |
ok 2859 - doc/Type/Supply.pod6 chunk 37 compiles | |
# method words(Supply:D: --> Supply:D) | |
ok 2860 - doc/Type/Supply.pod6 chunk 38 compiles | |
# method unique(Supply:D: :$as, :$with, :$expires --> Supply:D) | |
ok 2861 - doc/Type/Supply.pod6 chunk 39 compiles | |
# method squish(Supply:D: :$as, :$with, :$expires --> Supply:D) | |
ok 2862 - doc/Type/Supply.pod6 chunk 40 compiles | |
# method max(Supply:D: &by = &infix:<cmp> --> Supply:D) | |
ok 2863 - doc/Type/Supply.pod6 chunk 41 compiles | |
# method min(Supply:D: &by = &infix:<cmp> --> Supply:D) | |
ok 2864 - doc/Type/Supply.pod6 chunk 42 compiles | |
# method minmax(Supply:D: &by = &infix:<cmp> --> Supply:D) | |
ok 2865 - doc/Type/Supply.pod6 chunk 43 compiles | |
# method start(Supply:D: &startee --> Supply:D) | |
ok 2866 - doc/Type/Supply.pod6 chunk 44 compiles | |
# method migrate(Supply:D: --> Supply:D) | |
ok 2867 - doc/Type/Supply.pod6 chunk 45 compiles | |
# method merge(Supply @*supplies --> Supply:D) | |
ok 2868 - doc/Type/Supply.pod6 chunk 46 compiles | |
# method zip(Supply @*supplies, :&with = &[,] --> Supply:D) | |
ok 2869 - doc/Type/Supply.pod6 chunk 47 compiles | |
# method zip-latest(Supply @*supplies, :&with = &[,], :$initial --> Supply:D) | |
ok 2870 - doc/Type/Supply.pod6 chunk 48 compiles | |
# sub signal(@*signals, :$scheduler) | |
ok 2871 - doc/Type/Supply.pod6 chunk 49 compiles | |
# signal(SIGINT).tap( { say "Thank you for your attention"; exit 0 } ); | |
ok 2872 - doc/Type/Supply.pod6 chunk 50 compiles | |
# signal(Signal(2)).tap( -> $sig { say "Received signal: $sig" } ); | |
ok 2873 - doc/Type/Supply.pod6 chunk 51 compiles | |
# class Tap {} | |
ok 2874 - doc/Type/Tap.pod6 chunk 1 compiles | |
# my $s = Supplier.new; | |
# my $tap = $s.Supply.tap( | |
# -> $v { say "the value is $v" }, | |
# done => { say "Supply is done" }, | |
# closing => { say "Tap closed" }, | |
# quit => -> $ex { say "Supply finished with error $ex" }, | |
# ); | |
# # later | |
# $tap.close; | |
ok 2875 - doc/Type/Tap.pod6 chunk 2 compiles | |
# method emit(Tap:D: --> Callable:D) | |
ok 2876 - doc/Type/Tap.pod6 chunk 3 compiles | |
# method done(Tap:D:) | |
ok 2877 - doc/Type/Tap.pod6 chunk 4 compiles | |
# method quit(Tap:D:) | |
ok 2878 - doc/Type/Tap.pod6 chunk 5 compiles | |
# method closing(Tap:D:) | |
ok 2879 - doc/Type/Tap.pod6 chunk 6 compiles | |
# method supply(Tap:D:) | |
ok 2880 - doc/Type/Tap.pod6 chunk 7 compiles | |
# method close(Tap:D:) | |
ok 2881 - doc/Type/Tap.pod6 chunk 8 compiles | |
# class Thread {} | |
ok 2882 - doc/Type/Thread.pod6 chunk 1 compiles | |
# use v6.c; | |
# my @threads = (^10).map: { | |
# Thread.start( | |
# name => "Sleepsorter $_", | |
# sub { | |
# my $rand = (^10).pick; | |
# sleep $rand; | |
# say $rand; | |
# }, | |
# ); | |
# } | |
# .finish for @threads; | |
ok 2883 - doc/Type/Thread.pod6 chunk 2 compiles | |
# method new(:&code!, Bool :$app_lifetime = False, Str :$name = '<anon>' --> Thread:D) | |
ok 2884 - doc/Type/Thread.pod6 chunk 3 compiles | |
# method start(Thread:U: &code, Bool :$app_lifetime = False, Str :$name = '<anon>' --> Thread:D) | |
ok 2885 - doc/Type/Thread.pod6 chunk 4 compiles | |
# method run(Thread:D:) | |
ok 2886 - doc/Type/Thread.pod6 chunk 5 compiles | |
# method id(Thread:D: --> Int:D) | |
ok 2887 - doc/Type/Thread.pod6 chunk 6 compiles | |
# method finish(Thread:D) | |
ok 2888 - doc/Type/Thread.pod6 chunk 7 compiles | |
# method join(Thread:D) | |
ok 2889 - doc/Type/Thread.pod6 chunk 8 compiles | |
# method yield(Thread:U) | |
ok 2890 - doc/Type/Thread.pod6 chunk 9 compiles | |
# Thread.yield; | |
ok 2891 - doc/Type/Thread.pod6 chunk 10 compiles | |
# method app_lifetime(Thread:D: --> Bool:D) | |
ok 2892 - doc/Type/Thread.pod6 chunk 11 compiles | |
# my $t1 = Thread.new(code => { for 1..5 -> $v { say $v }}); | |
# my $t2 = Thread.new(code => { for 1..5 -> $v { say $v }}, :app_lifetime); | |
# say $t1.app_lifetime; # OUTPUT: «False» | |
# say $t2.app_lifetime; # OUTPUT: «True» | |
ok 2893 - doc/Type/Thread.pod6 chunk 12 compiles | |
# method name(Thread:D: --> Str:D) | |
ok 2894 - doc/Type/Thread.pod6 chunk 13 compiles | |
# my $t1 = Thread.new(code => { for 1..5 -> $v { say $v }}); | |
# my $t2 = Thread.new(code => { for 1..5 -> $v { say $v }}, name => 'my thread'); | |
# say $t1.name; # OUTPUT: «<anon>» | |
# say $t2.name; # OUTPUT: «my thread» | |
ok 2895 - doc/Type/Thread.pod6 chunk 14 compiles | |
# method Str(Thread:D: --> Str:D) | |
ok 2896 - doc/Type/Thread.pod6 chunk 15 compiles | |
# my $t = Thread.new(code => { for 1..5 -> $v { say $v }}, name => 'calc thread'); | |
# say $t.Str; # OUTPUT: «Thread<3>(calc thread)» | |
ok 2897 - doc/Type/Thread.pod6 chunk 16 compiles | |
# method new(Int :$initial_threads = 0, Int :$max_threads=16) | |
ok 2898 - doc/Type/ThreadPoolScheduler.pod6 chunk 1 compiles | |
# my UInt $u = 0xffff_ffff_ffff_ffff_ffff_ffff_ffff_ffff; # 64-bit unsigned value | |
# say $u.base(16); # OUTPUT: «FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF» (32 digits) | |
# ++$u; | |
# say $u.base(16); # OUTPUT: «100000000000000000000000000000000» (33 digits!) | |
# my Int $i = $u; | |
# say $i.base(16); # same as above | |
# say $u.WHAT; # OUTPUT: «(Int)» - UInt is a subset, so the type is still Int. | |
# say $i.WHAT; # OUTPUT: «(Int)» | |
# # Difference in assignment | |
# my UInt $a = 5; # nothing wrong | |
# my UInt $b = -5; # Exception about failed type check | |
# my UInt $c = 0; | |
# --$c; # Exception again | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::TypeCheck::Assignment: Type check failed in assignment to $b; expected UInt but got Int (-5)» | |
# # Non-assignment operations are fine | |
# my UInt $d = 3; | |
# say $a - 3; # OUTPUT: «-3» | |
ok 2899 - doc/Type/UInt.pod6 chunk 1 compiles | |
# class Uni does Positional[uint32] does Stringy { } | |
ok 2900 - doc/Type/Uni.pod6 chunk 1 compiles | |
# method new(*@codes --> Uni:D) | |
ok 2901 - doc/Type/Uni.pod6 chunk 2 compiles | |
# method NFC(Uni:D: --> NFC:D) | |
ok 2902 - doc/Type/Uni.pod6 chunk 3 compiles | |
# method NFD(Uni:D: --> NFD:D) | |
ok 2903 - doc/Type/Uni.pod6 chunk 4 compiles | |
# method NFKC(Uni:D: --> NFKC:D) | |
ok 2904 - doc/Type/Uni.pod6 chunk 5 compiles | |
# method NFKD(Uni:D: --> NFKD:D) | |
ok 2905 - doc/Type/Uni.pod6 chunk 6 compiles | |
# method codes(Uni:D: --> Int:D) | |
ok 2906 - doc/Type/Uni.pod6 chunk 7 compiles | |
# method elems(Uni:D: --> Int:D) | |
ok 2907 - doc/Type/Uni.pod6 chunk 8 compiles | |
# class Variable {} | |
ok 2908 - doc/Type/Variable.pod6 chunk 1 compiles | |
# method name(Variable:D: str) | |
ok 2909 - doc/Type/Variable.pod6 chunk 2 compiles | |
# multi sub trait_mod:<is>(Variable:D, :$default!) | |
ok 2910 - doc/Type/Variable.pod6 chunk 3 compiles | |
# my Int $x is default(42); | |
# say $x; # OUTPUT: «42» | |
# $x = 5; | |
# say $x; # OUTPUT: «5» | |
# # explicit reset: | |
# $x = Nil; | |
# say $x; # OUTPUT: «42» | |
ok 2911 - doc/Type/Variable.pod6 chunk 4 compiles | |
# multi sub trait_mod:<is>(Variable:D, :$dynamic) | |
ok 2912 - doc/Type/Variable.pod6 chunk 5 compiles | |
# multi sub trait_mod:<of>(Mu:U $target, Mu:U $type) | |
ok 2913 - doc/Type/Variable.pod6 chunk 6 compiles | |
# my $i of Int = 42; | |
# $i = "forty plus two"; | |
# CATCH { default { say .^name, ' ', .Str } } | |
# # OUTPUT: «X::TypeCheck::Assignment Type check failed in assignment to $i; expected Int but got Str ("forty plus two")» | |
ok 2914 - doc/Type/Variable.pod6 chunk 7 compiles | |
# class Version { } | |
ok 2915 - doc/Type/Version.pod6 chunk 1 compiles | |
# say v1.0.1 ~~ v1.*; # OUTPUT: «True» | |
ok 2916 - doc/Type/Version.pod6 chunk 2 compiles | |
# say v1.2 ~~ v1.0; # OUTPUT: «False» | |
# say v1.2 ~~ v1.0+; # OUTPUT: «True» | |
ok 2917 - doc/Type/Version.pod6 chunk 3 compiles | |
# say v1.2 cmp v2.1; # OUTPUT: «Less» | |
ok 2918 - doc/Type/Version.pod6 chunk 4 compiles | |
# method new(Str:D $s) | |
ok 2919 - doc/Type/Version.pod6 chunk 5 compiles | |
# method parts(Version:D: --> List:D) | |
ok 2920 - doc/Type/Version.pod6 chunk 6 compiles | |
# my $v1 = v1.0.1; | |
# my $v2 = v1.0.1+; | |
# say $v1.parts; # OUTPUT: «(1 0 1)» | |
# say $v2.parts; # OUTPUT: «(1 0 1)» | |
ok 2921 - doc/Type/Version.pod6 chunk 7 compiles | |
# method plus(Version:D: --> Bool:D) | |
ok 2922 - doc/Type/Version.pod6 chunk 8 compiles | |
# my $v1 = v1.0.1; | |
# my $v2 = v1.0.1+; | |
# say $v1.plus; # OUTPUT: «False» | |
# say $v2.plus; # OUTPUT: «True» | |
ok 2923 - doc/Type/Version.pod6 chunk 9 compiles | |
# method Str(Version:D: --> Str:D) | |
ok 2924 - doc/Type/Version.pod6 chunk 10 compiles | |
# my $v1 = v1.0.1; | |
# my $v2 = Version.new('1.0.1'); | |
# say $v1.Str; # OUTPUT: «1.0.1» | |
# say $v2.Str; # OUTPUT: «1.0.1» | |
ok 2925 - doc/Type/Version.pod6 chunk 11 compiles | |
# method gist(Version:D: --> Str:D) | |
ok 2926 - doc/Type/Version.pod6 chunk 12 compiles | |
# my $v1 = v1.0.1; | |
# my $v2 = Version.new('1.0.1'); | |
# say $v1.gist; # OUTPUT: «v1.0.1» | |
# say $v2.gist; # OUTPUT: «v1.0.1» | |
ok 2927 - doc/Type/Version.pod6 chunk 13 compiles | |
# class Whatever { } | |
ok 2928 - doc/Type/Whatever.pod6 chunk 1 compiles | |
# my $c = * + 2; # same as -> $x { $x + 2 }; | |
# say $c(4); # OUTPUT: «6» | |
ok 2929 - doc/Type/Whatever.pod6 chunk 2 compiles | |
# my $c = * + *; # same as -> $x, $y { $x + $y } | |
ok 2930 - doc/Type/Whatever.pod6 chunk 3 compiles | |
# my $c = 4 * * + 5; # same as -> $x { 4 * $x + 5 } | |
ok 2931 - doc/Type/Whatever.pod6 chunk 4 compiles | |
# <a b c>.map: *.uc; # same as <a b c>.map: -> $char { $char.uc } | |
ok 2932 - doc/Type/Whatever.pod6 chunk 5 compiles | |
# say (1..*).WHAT; # OUTPUT: «(Range)» | |
# say (1..*-1).WHAT; # OUTPUT: «(WhateverCode)» | |
ok 2933 - doc/Type/Whatever.pod6 chunk 6 compiles | |
# my @a = 1..4; | |
# say @a[0..*]; # OUTPUT: «(1 2 3 4)» | |
# say @a[0..*-2]; # OUTPUT: «(1 2 3)» | |
ok 2934 - doc/Type/Whatever.pod6 chunk 7 compiles | |
# my $x = *; | |
# $x + 2; # Not a closure, dies because it can't coerce $x to Numeric | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Multi::NoMatch: Cannot resolve caller Numeric(Whatever: ); none of these signatures match: | |
# # (Mu:U \v: *%_)» | |
ok 2935 - doc/Type/Whatever.pod6 chunk 8 compiles | |
# multi method ACCEPTS(Whatever:D: Mu $other) | |
ok 2936 - doc/Type/Whatever.pod6 chunk 9 compiles | |
# class WhateverCode is Code { } | |
ok 2937 - doc/Type/WhateverCode.pod6 chunk 1 compiles | |
# class Cycle { | |
# has $.pos; | |
# has @.vals; | |
# } | |
# multi sub get_val(Cycle $c, Int $idx) { | |
# $c.vals[$idx % $c.vals.elems] | |
# } | |
# # Define what to do with a stand-alone * as the second argument | |
# multi sub get_val(Cycle $c, Whatever $idx) { | |
# get_val($c, $c.pos); | |
# } | |
# # Define what to do with a * in an expression | |
# multi sub get_val(Cycle $c, WhateverCode $idx) { | |
# get_val($c, $idx($c.pos)); | |
# } | |
# my Cycle $c .= new(:pos(2), :vals(0..^10)); | |
# say get_val($c, 3); # OUTPUT: «3» | |
# say get_val($c, *); # OUTPUT: «2» | |
# say get_val($c, *-1); # OUTPUT: «1» | |
ok 2938 - doc/Type/WhateverCode.pod6 chunk 2 compiles | |
# sub f() { say 'f was called' } | |
# my $wrap-handle = &f.wrap({ say 'before'; callsame; say 'after' }); | |
# f; | |
# $wrap-handle.restore; | |
# f; | |
# # OUTPUT: «beforef was calledafterf was called» | |
ok 2939 - doc/Type/WrapHandle.pod6 chunk 1 compiles | |
# method restore(--> Bool:D) | |
ok 2940 - doc/Type/WrapHandle.pod6 chunk 2 compiles | |
# try { | |
# die [404, 'File not found']; # throw non-exception object | |
# } | |
# say "Got HTTP code ", | |
# $!.payload[0], # 404 | |
# " and backtrace ", | |
# $!.backtrace; | |
ok 2941 - doc/Type/X/AdHoc.pod6 chunk 1 compiles | |
# method payload(X::AdHoc:D) | |
ok 2942 - doc/Type/X/AdHoc.pod6 chunk 2 compiles | |
# class X::Anon::Augment does X::Comp { } | |
ok 2943 - doc/Type/X/Anon/Augment.pod6 chunk 1 compiles | |
# method package-kind returns Str:D | |
ok 2944 - doc/Type/X/Anon/Augment.pod6 chunk 2 compiles | |
# class X::Anon::Multi does X::Comp { } | |
ok 2945 - doc/Type/X/Anon/Multi.pod6 chunk 1 compiles | |
# method multiness(--> Str:D) | |
ok 2946 - doc/Type/X/Anon/Multi.pod6 chunk 2 compiles | |
# method routine-type(--> Str:D) | |
ok 2947 - doc/Type/X/Anon/Multi.pod6 chunk 3 compiles | |
# class X::Assignment::RO is Exception {} | |
ok 2948 - doc/Type/X/Assignment/RO.pod6 chunk 1 compiles | |
# sub f() { 42 }; | |
# f() = 'new value'; # throws an X::Assignment::RO | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Assignment::RO: Cannot modify an immutable Any» | |
ok 2949 - doc/Type/X/Assignment/RO.pod6 chunk 2 compiles | |
# method typename(X::Assignment::RO:D: --> Str) | |
ok 2950 - doc/Type/X/Assignment/RO.pod6 chunk 3 compiles | |
# class X::Attribute::NoPackage does X::Comp { } | |
ok 2951 - doc/Type/X/Attribute/NoPackage.pod6 chunk 1 compiles | |
# method name(--> Str:D) | |
ok 2952 - doc/Type/X/Attribute/NoPackage.pod6 chunk 2 compiles | |
# class X::Attribute::Package does X::Comp { } | |
ok 2953 - doc/Type/X/Attribute/Package.pod6 chunk 1 compiles | |
# method name(--> Str:D) | |
ok 2954 - doc/Type/X/Attribute/Package.pod6 chunk 2 compiles | |
# method package-kind(--> Str:D) | |
ok 2955 - doc/Type/X/Attribute/Package.pod6 chunk 3 compiles | |
# class X::Attribute::Undeclared is X::Undeclared { } | |
ok 2956 - doc/Type/X/Attribute/Undeclared.pod6 chunk 1 compiles | |
# class X::Augment::NoSuchType does X::Comp { } | |
ok 2957 - doc/Type/X/Augment/NoSuchType.pod6 chunk 1 compiles | |
# method package-kind(--> Str:D) | |
ok 2958 - doc/Type/X/Augment/NoSuchType.pod6 chunk 2 compiles | |
# class X::Bind is Exception {} | |
ok 2959 - doc/Type/X/Bind.pod6 chunk 1 compiles | |
# class X::Bind::NativeType does X::Comp { } | |
ok 2960 - doc/Type/X/Bind/NativeType.pod6 chunk 1 compiles | |
# my int $x = 3; | |
ok 2961 - doc/Type/X/Bind/NativeType.pod6 chunk 2 compiles | |
# method name(--> Str:D) | |
ok 2962 - doc/Type/X/Bind/NativeType.pod6 chunk 3 compiles | |
# class X::Bind::Slice is Exception {} | |
ok 2963 - doc/Type/X/Bind/Slice.pod6 chunk 1 compiles | |
# my @a; @a[0, 1] := [42]; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Bind::Slice: Cannot bind to Array slice» | |
ok 2964 - doc/Type/X/Bind/Slice.pod6 chunk 2 compiles | |
# my %h; %h<a b> := {}; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Bind::Slice: Cannot bind to Hash slice» | |
ok 2965 - doc/Type/X/Bind/Slice.pod6 chunk 3 compiles | |
# method type(X::Bind::Slice:D:) | |
ok 2966 - doc/Type/X/Bind/Slice.pod6 chunk 4 compiles | |
# class X::Caller::NotDynamic is Exception { } | |
ok 2967 - doc/Type/X/Caller/NotDynamic.pod6 chunk 1 compiles | |
# class X::Channel::ReceiveOnClosed {} | |
ok 2968 - doc/Type/X/Channel/ReceiveOnClosed.pod6 chunk 1 compiles | |
# my $s = Channel.new; | |
# $s.close; | |
# $s.receive; # Cannot receive a message on a closed channel | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Channel::ReceiveOnClosed: Cannot receive a message on a closed channel» | |
ok 2969 - doc/Type/X/Channel/ReceiveOnClosed.pod6 chunk 2 compiles | |
# method Channel(X::Channel::ReceiveOnClosed:D: --> Channel:D) | |
ok 2970 - doc/Type/X/Channel/ReceiveOnClosed.pod6 chunk 3 compiles | |
# class X::Channel::SendOnClosed {} | |
ok 2971 - doc/Type/X/Channel/SendOnClosed.pod6 chunk 1 compiles | |
# my $s = Channel.new; | |
# $s.close; | |
# $s.send(42); | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Channel::SendOnClosed: Cannot send a message on a closed channel» | |
ok 2972 - doc/Type/X/Channel/SendOnClosed.pod6 chunk 2 compiles | |
# method Channel(X::Channel::SendOnClosed:D: --> Channel:D) | |
ok 2973 - doc/Type/X/Channel/SendOnClosed.pod6 chunk 3 compiles | |
# role X::Comp is Exception { } | |
ok 2974 - doc/Type/X/Comp.pod6 chunk 1 compiles | |
# class X::Composition::NotComposable is Exception { } | |
ok 2975 - doc/Type/X/Composition/NotComposable.pod6 chunk 1 compiles | |
# method target-name(--> Str:D) | |
ok 2976 - doc/Type/X/Composition/NotComposable.pod6 chunk 2 compiles | |
# method composer(--> Mu) | |
ok 2977 - doc/Type/X/Composition/NotComposable.pod6 chunk 3 compiles | |
# class X::Constructor::Positional is Exception { } | |
ok 2978 - doc/Type/X/Constructor/Positional.pod6 chunk 1 compiles | |
# class A { }; | |
# A.new(2, 3); | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Constructor::Positional: Default constructor for 'A' only takes named arguments» | |
ok 2979 - doc/Type/X/Constructor/Positional.pod6 chunk 2 compiles | |
# class X::ControlFlow is Exception { } | |
ok 2980 - doc/Type/X/ControlFlow.pod6 chunk 1 compiles | |
# last; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::ControlFlow: last without loop construct» | |
ok 2981 - doc/Type/X/ControlFlow.pod6 chunk 2 compiles | |
# method illegal returns Str:D | |
ok 2982 - doc/Type/X/ControlFlow.pod6 chunk 3 compiles | |
# method enclosing returns Str:D | |
ok 2983 - doc/Type/X/ControlFlow.pod6 chunk 4 compiles | |
# class X::ControlFlow::Return is X::ControlFlow { } | |
ok 2984 - doc/Type/X/ControlFlow/Return.pod6 chunk 1 compiles | |
# return; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::ControlFlow::Return: Attempt to return outside of any Routine» | |
ok 2985 - doc/Type/X/ControlFlow/Return.pod6 chunk 2 compiles | |
# say DateTime.new('2015-12-24T12:23:00+0200'); # works | |
# say DateTime.new('2015-12-24T12:23:00', timezone => 7200); # works | |
ok 2986 - doc/Type/X/DateTime/TimezoneClash.pod6 chunk 1 compiles | |
# method scope(--> Str:D) | |
ok 2987 - doc/Type/X/Declaration/Scope.pod6 chunk 1 compiles | |
# method declaration(--> Str:D) | |
ok 2988 - doc/Type/X/Declaration/Scope.pod6 chunk 2 compiles | |
# class X::Declaration::Scope::Multi is X::Declaration::Scope { } | |
ok 2989 - doc/Type/X/Declaration/Scope/Multi.pod6 chunk 1 compiles | |
# class X::Does::TypeObject is Exception {} | |
ok 2990 - doc/Type/X/Does/TypeObject.pod6 chunk 1 compiles | |
# method type(X::Does::TypeObject:D: --> Mu:U) | |
ok 2991 - doc/Type/X/Does/TypeObject.pod6 chunk 2 compiles | |
# class X::Eval::NoSuchLang is Exception { } | |
ok 2992 - doc/Type/X/Eval/NoSuchLang.pod6 chunk 1 compiles | |
# EVAL 'boo', lang => "bar"; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Eval::NoSuchLang: No compiler available for language 'bar'» | |
ok 2993 - doc/Type/X/Eval/NoSuchLang.pod6 chunk 2 compiles | |
# method lang() | |
ok 2994 - doc/Type/X/Eval/NoSuchLang.pod6 chunk 3 compiles | |
# class X::Export::NameClash does X::Comp { } | |
ok 2995 - doc/Type/X/Export/NameClash.pod6 chunk 1 compiles | |
# role X::IO does X::OS {} | |
ok 2996 - doc/Type/X/IO.pod6 chunk 1 compiles | |
# class X::Inheritance::NotComposed is Exception {} | |
ok 2997 - doc/Type/X/Inheritance/NotComposed.pod6 chunk 1 compiles | |
# method child-name(X::Inheritance::NotComposed:D: --> Str:D) | |
ok 2998 - doc/Type/X/Inheritance/NotComposed.pod6 chunk 2 compiles | |
# method parent-name(X::Inheritance::NotComposed:D: --> Str:D) | |
ok 2999 - doc/Type/X/Inheritance/NotComposed.pod6 chunk 3 compiles | |
# class X::Inheritance::Unsupported does X::Comp { } | |
ok 3000 - doc/Type/X/Inheritance/Unsupported.pod6 chunk 1 compiles | |
# class X::Method::InvalidQualifier is Exception { } | |
ok 3001 - doc/Type/X/Method/InvalidQualifier.pod6 chunk 1 compiles | |
# 1.Str::split(/a/); | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Method::InvalidQualifier: Cannot dispatch to method split on Str because it is not inherited or done by Int» | |
ok 3002 - doc/Type/X/Method/InvalidQualifier.pod6 chunk 2 compiles | |
# method method(--> Str:D) | |
ok 3003 - doc/Type/X/Method/InvalidQualifier.pod6 chunk 3 compiles | |
# class X::Method::NotFound is Exception {} | |
ok 3004 - doc/Type/X/Method/NotFound.pod6 chunk 1 compiles | |
# method method(--> Str:D) | |
ok 3005 - doc/Type/X/Method/NotFound.pod6 chunk 2 compiles | |
# method typename returns Str:D | |
ok 3006 - doc/Type/X/Method/NotFound.pod6 chunk 3 compiles | |
# method private(--> Bool:D) | |
ok 3007 - doc/Type/X/Method/NotFound.pod6 chunk 4 compiles | |
# class X::Method::Private::Permission does X::Comp { } | |
ok 3008 - doc/Type/X/Method/Private/Permission.pod6 chunk 1 compiles | |
# method method(--> Str:D) | |
ok 3009 - doc/Type/X/Method/Private/Permission.pod6 chunk 2 compiles | |
# method source-package(--> Mu:D) | |
ok 3010 - doc/Type/X/Method/Private/Permission.pod6 chunk 3 compiles | |
# method calling-package(--> Mu:D) | |
ok 3011 - doc/Type/X/Method/Private/Permission.pod6 chunk 4 compiles | |
# class X::Method::Private::Unqualified does X::Comp { } | |
ok 3012 - doc/Type/X/Method/Private/Unqualified.pod6 chunk 1 compiles | |
# method method(--> Str:D) | |
ok 3013 - doc/Type/X/Method/Private/Unqualified.pod6 chunk 2 compiles | |
# class X::Mixin::NotComposable is Exception { } | |
ok 3014 - doc/Type/X/Mixin/NotComposable.pod6 chunk 1 compiles | |
# class A { }; | |
# 1 but A; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Mixin::NotComposable: Cannot mix in non-composable type A into object of type Int» | |
ok 3015 - doc/Type/X/Mixin/NotComposable.pod6 chunk 2 compiles | |
# method target() | |
ok 3016 - doc/Type/X/Mixin/NotComposable.pod6 chunk 3 compiles | |
# method rolish() | |
ok 3017 - doc/Type/X/Mixin/NotComposable.pod6 chunk 4 compiles | |
# class X::NYI is Exception { } | |
ok 3018 - doc/Type/X/NYI.pod6 chunk 1 compiles | |
# class X::NoDispatcher is Exception { } | |
ok 3019 - doc/Type/X/NoDispatcher.pod6 chunk 1 compiles | |
# nextsame; # In the mainline | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::NoDispatcher: nextsame is not in the dynamic scope of a dispatcher» | |
ok 3020 - doc/Type/X/NoDispatcher.pod6 chunk 2 compiles | |
# method redispatcher(--> Str:D) | |
ok 3021 - doc/Type/X/NoDispatcher.pod6 chunk 3 compiles | |
# class X::Numeric::Real is Exception { } | |
ok 3022 - doc/Type/X/Numeric/Real.pod6 chunk 1 compiles | |
# say (1+2i).Int; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Numeric::Real: Can not convert 1+2i to Int: imaginary part not zero» | |
ok 3023 - doc/Type/X/Numeric/Real.pod6 chunk 2 compiles | |
# method source(--> Numeric:D) | |
ok 3024 - doc/Type/X/Numeric/Real.pod6 chunk 3 compiles | |
# method target() | |
ok 3025 - doc/Type/X/Numeric/Real.pod6 chunk 4 compiles | |
# method reason(--> Str:D) | |
ok 3026 - doc/Type/X/Numeric/Real.pod6 chunk 5 compiles | |
# role X::OS { has $.os-error } | |
ok 3027 - doc/Type/X/OS.pod6 chunk 1 compiles | |
# method os-error(--> Str:D) | |
ok 3028 - doc/Type/X/OS.pod6 chunk 2 compiles | |
# class X::Obsolete does X::Comp { } | |
ok 3029 - doc/Type/X/Obsolete.pod6 chunk 1 compiles | |
# method old(--> Str:D) | |
ok 3030 - doc/Type/X/Obsolete.pod6 chunk 2 compiles | |
# method replacement(--> Str:D) | |
ok 3031 - doc/Type/X/Obsolete.pod6 chunk 3 compiles | |
# method when(--> Str:D) | |
ok 3032 - doc/Type/X/Obsolete.pod6 chunk 4 compiles | |
# class X::OutOfRange is Exception { } | |
ok 3033 - doc/Type/X/OutOfRange.pod6 chunk 1 compiles | |
# say 42[2]; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::OutOfRange: Index out of range. Is: 2, should be in 0..0» | |
ok 3034 - doc/Type/X/OutOfRange.pod6 chunk 2 compiles | |
# method what(--> Str:D) | |
ok 3035 - doc/Type/X/OutOfRange.pod6 chunk 3 compiles | |
# method got() | |
ok 3036 - doc/Type/X/OutOfRange.pod6 chunk 4 compiles | |
# method range(--> Range:D) | |
ok 3037 - doc/Type/X/OutOfRange.pod6 chunk 5 compiles | |
# method comment(--> Str) | |
ok 3038 - doc/Type/X/OutOfRange.pod6 chunk 6 compiles | |
# class X::Package::Stubbed does X::Comp { } | |
ok 3039 - doc/Type/X/Package/Stubbed.pod6 chunk 1 compiles | |
# method packages(--> Positional:D) | |
ok 3040 - doc/Type/X/Package/Stubbed.pod6 chunk 2 compiles | |
# class X::Parameter::Default does X::Comp { } | |
ok 3041 - doc/Type/X/Parameter/Default.pod6 chunk 1 compiles | |
# class X::Parameter::MultipleTypeConstraints does X::Comp { } | |
ok 3042 - doc/Type/X/Parameter/MultipleTypeConstraints.pod6 chunk 1 compiles | |
# class X::Parameter::Placeholder does X::Comp { } | |
ok 3043 - doc/Type/X/Parameter/Placeholder.pod6 chunk 1 compiles | |
# class X::Parameter::Twigil does X::Comp { } | |
ok 3044 - doc/Type/X/Parameter/Twigil.pod6 chunk 1 compiles | |
# class X::Parameter::WrongOrder does X::Comp { } | |
ok 3045 - doc/Type/X/Parameter/WrongOrder.pod6 chunk 1 compiles | |
# class X::Phaser::Multiple does X::Comp { } | |
ok 3046 - doc/Type/X/Phaser/Multiple.pod6 chunk 1 compiles | |
# sub f($x) { PRE { $x ~~ Int } }; | |
# f "foo"; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: X::Phaser::PrePost: Precondition '{ $x ~~ Int }' failed«» | |
ok 3047 - doc/Type/X/Phaser/PrePost.pod6 chunk 1 compiles | |
# method phaser(--> Str:D) | |
ok 3048 - doc/Type/X/Phaser/PrePost.pod6 chunk 2 compiles | |
# method condition(--> Str:D) | |
ok 3049 - doc/Type/X/Phaser/PrePost.pod6 chunk 3 compiles | |
# class X::Placeholder::Block does X::Comp {} | |
ok 3050 - doc/Type/X/Placeholder/Block.pod6 chunk 1 compiles | |
# class X::Placeholder::Mainline is X::Placeholder::Block { } | |
ok 3051 - doc/Type/X/Placeholder/Mainline.pod6 chunk 1 compiles | |
# role X::Pod { } | |
ok 3052 - doc/Type/X/Pod.pod6 chunk 1 compiles | |
# role X::Proc::Async is Exception { ... } | |
ok 3053 - doc/Type/X/Proc/Async.pod6 chunk 1 compiles | |
# method proc(X::Proc::Async:D --> Proc::Async) | |
ok 3054 - doc/Type/X/Proc/Async.pod6 chunk 2 compiles | |
# class X::Proc::Async::AlreadyStarted is Exception {} | |
ok 3055 - doc/Type/X/Proc/Async/AlreadyStarted.pod6 chunk 1 compiles | |
# my $proc = Proc::Async.new("echo"); | |
# $proc.start; | |
# $proc.start; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Proc::Async::AlreadyStarted: Process has already been started» | |
ok 3056 - doc/Type/X/Proc/Async/AlreadyStarted.pod6 chunk 2 compiles | |
# class X::Proc::Async::CharsOrBytes is Exception {} | |
ok 3057 - doc/Type/X/Proc/Async/CharsOrBytes.pod6 chunk 1 compiles | |
# my $proc = Proc::Async.new('echo'); | |
# $proc.stdout.tap(&print); | |
# $proc.stdout(:bin).tap(&print); | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Proc::Async::CharsOrBytes: Can only tap one of chars or bytes supply for stdout» | |
ok 3058 - doc/Type/X/Proc/Async/CharsOrBytes.pod6 chunk 2 compiles | |
# method handle(X::Proc::Async::CharsOrBytes:D: --> Str:D) | |
ok 3059 - doc/Type/X/Proc/Async/CharsOrBytes.pod6 chunk 3 compiles | |
# class X::Proc::Async::MustBeStarted is Exception {} | |
ok 3060 - doc/Type/X/Proc/Async/MustBeStarted.pod6 chunk 1 compiles | |
# Proc::Async.new('echo', :w).say(42); | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Proc::Async::MustBeStarted: Process must be started first before calling 'say'» | |
ok 3061 - doc/Type/X/Proc/Async/MustBeStarted.pod6 chunk 2 compiles | |
# method method(X::Proc::Async::MustBeStarted:D --> Str:D) | |
ok 3062 - doc/Type/X/Proc/Async/MustBeStarted.pod6 chunk 3 compiles | |
# class X::Proc::Async::OpenForWriting is Exception {} | |
ok 3063 - doc/Type/X/Proc/Async/OpenForWriting.pod6 chunk 1 compiles | |
# my $proc = Proc::Async.new("echo"); | |
# $proc.start; | |
# $proc.say(42); | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Proc::Async::OpenForWriting: Process must be opened for writing with :w to call 'say'» | |
ok 3064 - doc/Type/X/Proc/Async/OpenForWriting.pod6 chunk 2 compiles | |
# my $prog = Proc::Async.new(:w, 'cat'); | |
# $prog.stdout.tap( -> $str { | |
# print $str; | |
# }); | |
# my $promise = $prog.start; | |
# await $prog.say('foo'); | |
# $prog.close-stdin; | |
# await $promise; | |
ok 3065 - doc/Type/X/Proc/Async/OpenForWriting.pod6 chunk 3 compiles | |
# method method(X::Proc::Async::OpenForWriting:D:) | |
ok 3066 - doc/Type/X/Proc/Async/OpenForWriting.pod6 chunk 4 compiles | |
# class X::Proc::Async::TapBeforeSpawn is Exception {} | |
ok 3067 - doc/Type/X/Proc/Async/TapBeforeSpawn.pod6 chunk 1 compiles | |
# my $proc = Proc::Async.new("echo", "foo"); | |
# $proc.start; | |
# $proc.stdout.tap(&print); | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Proc::Async::TapBeforeSpawn: To avoid data races, you must tap stdout before running the process» | |
ok 3068 - doc/Type/X/Proc/Async/TapBeforeSpawn.pod6 chunk 2 compiles | |
# my $proc = Proc::Async.new("echo", "foo"); | |
# $proc.stdout.tap(&print); | |
# await $proc.start; | |
ok 3069 - doc/Type/X/Proc/Async/TapBeforeSpawn.pod6 chunk 3 compiles | |
# method handle(X::Proc::Async::TapBeforeSpawn:D: --> Str:D) | |
ok 3070 - doc/Type/X/Proc/Async/TapBeforeSpawn.pod6 chunk 4 compiles | |
# class X::Proc::Unsuccessful is Exception {} | |
ok 3071 - doc/Type/X/Proc/Unsuccessful.pod6 chunk 1 compiles | |
# method proc(X::Proc::Unsuccessful:D --> Proc) | |
ok 3072 - doc/Type/X/Proc/Unsuccessful.pod6 chunk 2 compiles | |
# class X::Promise::CauseOnlyValidOnBroken is Exception { } | |
ok 3073 - doc/Type/X/Promise/CauseOnlyValidOnBroken.pod6 chunk 1 compiles | |
# method promise() | |
ok 3074 - doc/Type/X/Promise/CauseOnlyValidOnBroken.pod6 chunk 2 compiles | |
# method status() | |
ok 3075 - doc/Type/X/Promise/CauseOnlyValidOnBroken.pod6 chunk 3 compiles | |
# class X::Promise::Vowed is Exception { } | |
ok 3076 - doc/Type/X/Promise/Vowed.pod6 chunk 1 compiles | |
# method promise() | |
ok 3077 - doc/Type/X/Promise/Vowed.pod6 chunk 2 compiles | |
# class X::Redeclaration does X::Comp { } | |
ok 3078 - doc/Type/X/Redeclaration.pod6 chunk 1 compiles | |
# my $x; | |
# sub f() { | |
# my $x; # not a redeclaration, | |
# # because it's in an inner scope | |
# sub f() { }; # same | |
# } | |
ok 3079 - doc/Type/X/Redeclaration.pod6 chunk 2 compiles | |
# class X::Role::Initialization is Exception { } | |
ok 3080 - doc/Type/X/Role/Initialization.pod6 chunk 1 compiles | |
# method role() | |
ok 3081 - doc/Type/X/Role/Initialization.pod6 chunk 2 compiles | |
# class X::Seq::Consumed is Exception { } | |
ok 3082 - doc/Type/X/Seq/Consumed.pod6 chunk 1 compiles | |
# class X::Sequence::Deduction is Exception { } | |
ok 3083 - doc/Type/X/Sequence/Deduction.pod6 chunk 1 compiles | |
# my class X::Signature::NameClash does X::Comp { } | |
ok 3084 - doc/Type/X/Signature/NameClash.pod6 chunk 1 compiles | |
# method name(--> Str:D) | |
ok 3085 - doc/Type/X/Signature/NameClash.pod6 chunk 2 compiles | |
# method placeholder(--> Str:D) | |
ok 3086 - doc/Type/X/Signature/Placeholder.pod6 chunk 1 compiles | |
# class X::Str::Numeric is Exception { } | |
ok 3087 - doc/Type/X/Str/Numeric.pod6 chunk 1 compiles | |
# say +"42 answers"; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::Str::Numeric: Cannot convert string to number: trailing characters after number in '42⏏ answers' (indicated by ⏏)» | |
ok 3088 - doc/Type/X/Str/Numeric.pod6 chunk 2 compiles | |
# method source(--> Str:D) | |
ok 3089 - doc/Type/X/Str/Numeric.pod6 chunk 3 compiles | |
# method pos(--> Int:D) | |
ok 3090 - doc/Type/X/Str/Numeric.pod6 chunk 4 compiles | |
# method reason(--> Int:D) | |
ok 3091 - doc/Type/X/Str/Numeric.pod6 chunk 5 compiles | |
# class X::StubCode is Exception { } | |
ok 3092 - doc/Type/X/StubCode.pod6 chunk 1 compiles | |
# role X::Syntax does X::Comp { } | |
ok 3093 - doc/Type/X/Syntax.pod6 chunk 1 compiles | |
# class X::Syntax::Augment::WithoutMonkeyTyping does X::Syntax { } | |
ok 3094 - doc/Type/X/Syntax/Augment/WithoutMonkeyTyping.pod6 chunk 1 compiles | |
# class X::Syntax::Comment::Embedded does X::Syntax { } | |
ok 3095 - doc/Type/X/Syntax/Comment/Embedded.pod6 chunk 1 compiles | |
# class X::Syntax::InfixInTermPosition does X::Syntax { } | |
ok 3096 - doc/Type/X/Syntax/InfixInTermPosition.pod6 chunk 1 compiles | |
# method infix(--> Str:D) | |
ok 3097 - doc/Type/X/Syntax/InfixInTermPosition.pod6 chunk 2 compiles | |
# class X::Syntax::Malformed does X::Syntax {} | |
ok 3098 - doc/Type/X/Syntax/Malformed.pod6 chunk 1 compiles | |
# method what(X::Syntax::Malformed:D: --> Str) | |
ok 3099 - doc/Type/X/Syntax/Malformed.pod6 chunk 2 compiles | |
# class X::Syntax::Missing does X::Syntax { } | |
ok 3100 - doc/Type/X/Syntax/Missing.pod6 chunk 1 compiles | |
# method what(--> Str:D) | |
ok 3101 - doc/Type/X/Syntax/Missing.pod6 chunk 2 compiles | |
# class X::Syntax::NegatedPair does X::Syntax { } | |
ok 3102 - doc/Type/X/Syntax/NegatedPair.pod6 chunk 1 compiles | |
# class X::Syntax::NoSelf does X::Syntax { } | |
ok 3103 - doc/Type/X/Syntax/NoSelf.pod6 chunk 1 compiles | |
# class X::Syntax::Number::RadixOutOfRange does X::Syntax { } | |
ok 3104 - doc/Type/X/Syntax/Number/RadixOutOfRange.pod6 chunk 1 compiles | |
# method radix(--> Int:D) | |
ok 3105 - doc/Type/X/Syntax/Number/RadixOutOfRange.pod6 chunk 2 compiles | |
# class X::Syntax::P5 does X::Syntax { } | |
ok 3106 - doc/Type/X/Syntax/P5.pod6 chunk 1 compiles | |
# class X::Syntax::Regex::Adverb does X::Syntax { } | |
ok 3107 - doc/Type/X/Syntax/Regex/Adverb.pod6 chunk 1 compiles | |
# method adverb(--> Str:D) | |
ok 3108 - doc/Type/X/Syntax/Regex/Adverb.pod6 chunk 2 compiles | |
# method construct(--> Str:D) | |
ok 3109 - doc/Type/X/Syntax/Regex/Adverb.pod6 chunk 3 compiles | |
# class X::Syntax::Regex::SolitaryQuantifier does X::Syntax { } | |
ok 3110 - doc/Type/X/Syntax/Regex/SolitaryQuantifier.pod6 chunk 1 compiles | |
# class X::Syntax::Reserved does X::Syntax { } | |
ok 3111 - doc/Type/X/Syntax/Reserved.pod6 chunk 1 compiles | |
# method reserved(--> Str:D) | |
ok 3112 - doc/Type/X/Syntax/Reserved.pod6 chunk 2 compiles | |
# method instead(--> Str) | |
ok 3113 - doc/Type/X/Syntax/Reserved.pod6 chunk 3 compiles | |
# class X::Syntax::Self::WithoutObject does X::Syntax { } | |
ok 3114 - doc/Type/X/Syntax/Self/WithoutObject.pod6 chunk 1 compiles | |
# class X::Syntax::Signature::InvocantMarker does X::Syntax { } | |
ok 3115 - doc/Type/X/Syntax/Signature/InvocantMarker.pod6 chunk 1 compiles | |
# class X::Syntax::Term::MissingInitializer does X::Syntax { } | |
ok 3116 - doc/Type/X/Syntax/Term/MissingInitializer.pod6 chunk 1 compiles | |
# my \foo = 42; | |
ok 3117 - doc/Type/X/Syntax/Term/MissingInitializer.pod6 chunk 2 compiles | |
# class X::Syntax::UnlessElse does X::Syntax { } | |
ok 3118 - doc/Type/X/Syntax/UnlessElse.pod6 chunk 1 compiles | |
# class X::Syntax::Variable::Match does X::Syntax { } | |
ok 3119 - doc/Type/X/Syntax/Variable/Match.pod6 chunk 1 compiles | |
# class X::Syntax::Variable::Numeric does X::Syntax { } | |
ok 3120 - doc/Type/X/Syntax/Variable/Numeric.pod6 chunk 1 compiles | |
# method what returns Str:D | |
ok 3121 - doc/Type/X/Syntax/Variable/Numeric.pod6 chunk 2 compiles | |
# class X::Syntax::Variable::Twigil does X::Syntax { } | |
ok 3122 - doc/Type/X/Syntax/Variable/Twigil.pod6 chunk 1 compiles | |
# method twigil(--> Str:D) | |
ok 3123 - doc/Type/X/Syntax/Variable/Twigil.pod6 chunk 2 compiles | |
# method scope(--> Str:D) | |
ok 3124 - doc/Type/X/Syntax/Variable/Twigil.pod6 chunk 3 compiles | |
# role X::Temporal is Exception { } | |
ok 3125 - doc/Type/X/Temporal.pod6 chunk 1 compiles | |
# class X::TypeCheck is Exception { } | |
ok 3126 - doc/Type/X/TypeCheck.pod6 chunk 1 compiles | |
# method operation(--> Str:D) | |
ok 3127 - doc/Type/X/TypeCheck.pod6 chunk 2 compiles | |
# method got() | |
ok 3128 - doc/Type/X/TypeCheck.pod6 chunk 3 compiles | |
# method expected() | |
ok 3129 - doc/Type/X/TypeCheck.pod6 chunk 4 compiles | |
# class X::TypeCheck::Assignment is X::TypeCheck { } | |
ok 3130 - doc/Type/X/TypeCheck/Assignment.pod6 chunk 1 compiles | |
# my Int $x = "foo"; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::TypeCheck::Assignment: Type check failed in assignment to $x; expected Int but got Str ("foo")» | |
ok 3131 - doc/Type/X/TypeCheck/Assignment.pod6 chunk 2 compiles | |
# class X::TypeCheck::Binding is X::TypeCheck { } | |
ok 3132 - doc/Type/X/TypeCheck/Binding.pod6 chunk 1 compiles | |
# my Int $x := "foo"; | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::TypeCheck::Binding: Type check failed in binding; expected Int but got Str ("foo")» | |
ok 3133 - doc/Type/X/TypeCheck/Binding.pod6 chunk 2 compiles | |
# class X::TypeCheck::Return is X::TypeCheck { } | |
ok 3134 - doc/Type/X/TypeCheck/Return.pod6 chunk 1 compiles | |
# sub f(--> Int) { "foo" } | |
# f(); | |
# CATCH { default { put .^name, ': ', .Str } }; | |
# # OUTPUT: «X::TypeCheck::Return: Type check failed for return value; expected Int but got Str ("foo")» | |
ok 3135 - doc/Type/X/TypeCheck/Return.pod6 chunk 2 compiles | |
# class X::TypeCheck::Splice is X::TypeCheck does X::Comp { } | |
ok 3136 - doc/Type/X/TypeCheck/Splice.pod6 chunk 1 compiles | |
# use experimental :macros; | |
# macro a { | |
# quasi { 'foo' } | |
# } | |
# say a; # foo | |
ok 3137 - doc/Type/X/TypeCheck/Splice.pod6 chunk 2 compiles | |
# method action(--> Str:D) | |
ok 3138 - doc/Type/X/TypeCheck/Splice.pod6 chunk 3 compiles | |
# class X::Undeclared does X::Comp {} | |
ok 3139 - doc/Type/X/Undeclared.pod6 chunk 1 compiles | |
# class int is Int is repr('P6int') { } | |
ok 3140 - doc/Type/nativeInt.pod6 chunk 1 compiles | |
# Looks like you failed 1 test of 3140 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment