Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -1,5 +1,19 @@
my @y = <A B C D>; #Array of strings 'A', 'B', 'C', and 'D'
my @y = <A B C D>; # Array of strings 'A', 'B', 'C', and 'D'
say @y[2]; # the @-sigil requires the container to implement the role Positional
@y[1,2] = 'x','y'; # that's where subscripts and many other things come from
say @y; # OUTPUT«[A x y D]␤» # we start to count at 0 btw.
my $x = @y; # $x is now a reference for the array @y
say $x[1]; # prints 'B' follow by a newline character
say $x[1]; # prints 'x' followed by a newline character
my Int $with-type-check; # type checks are enforced by the compiler
my Int:D $defined-i = 10; # definedness can also be asked for and default values are required in that case
my Int:D $after-midnight where * > 24 = 25; # SQL is fun and so is Perl 6
my \bad = 'good'; # if you don't like sigils
say bad; # you don't have to use them
say "this is quite bad"; # but then string interpolation
say "this is quite {bad}" # becomes more wordy

View file

@ -1,14 +1,6 @@
# $x can contain only Int objects
my Int $x;
say ++$; # this is an anonymous state variable
say ++$; # this is a different anonymous state variable, prefix:<++> forces it into numerical context and defaults it to 0
say $+=2 for 1..10 # here we do something useful with another anonymous variable
# $x can only contain native integers (not integer objects)
my int $x;
#A variable may itself be bound to a container type that specifies how the container works, without specifying what kinds of things it contains.
# $x is implemented by the MyScalar class
my $x is MyScalar;
#Constraints and container types can be used together:
# $x can contain only Int objects,
# and is implemented by the MyScalar class
my Int $x is MyScalar;
sub foo { $^a * $^b } # for positional arguments we often can't be bothered to declare them or to give them fancy names
say foo 3, 4;