Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
19
Task/Variables/Raku/variables-1.raku
Normal file
19
Task/Variables/Raku/variables-1.raku
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
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 '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 Raku
|
||||
|
||||
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
|
||||
6
Task/Variables/Raku/variables-2.raku
Normal file
6
Task/Variables/Raku/variables-2.raku
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
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
|
||||
|
||||
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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue