3 ms·
> less readable due to double symbols Double symbols? What do you mean by that? > increased symbol madness Could you elaborate what you mean by that? > It'
by lizmat 8y ago
> less readable due to double symbols
Double symbols? What do you mean by that?
> increased symbol madness
Could you elaborate what you mean by that?
> It's like giving you the equivalent of a swiss army knife for each and every tool inside your toolbox.
Please note that the link you've given, is about being able to restrict calling a subroutine by making sure that the first 2 parameters are of the same type (regardless of which type). Generally one knows which types to expect. And even so, typechecking is an optional thing in Perl 6 (hence the term "gradual typechecking".
> The latter looks like it was designed by a mad scientist on LSD.
I think that's uncalled for. But that's your opinion. The same mad scientist who gave you Perl 5, by that reasoning, by the way.
- petre 8y agoI mean $.x and $!x or such craziness: submethod BUILD(:&!callback, :@!dependencies) { } https://docs.perl6.org/language/015-classtut#Private_Methods https://docs.perl6.org/language/015-classtut#Private_Methods or the quite useful Z=> operator. my %hash = @keys Z=> @values; or the Bat range operators: (1^..^5).list; # (2 3 4) I know. It was meant as a Perl6 example chosen at random. It looks as something taken out of the Discworld novels: https://en.wikipedia.org/wiki/Unseen_University#Octavo https://en.wikipedia.org/wiki/Unseen_University#Octavo
- b2gills 8y agoYou don't understand what the following means 1 ^..^ 5 It means a Range of values from 1 to 5 excluding 1 and 5. 1 ~~ 1^..^5; # False 5 ~~ 1^..^5; # False 1.000001 ~~ 1^..^5; # True 4.999999 ~~ 1^..^5; # True It is short for Range.new( 1, 5, excludes-min => True, excludes-max => True ) One of the benefits if you want to get the first 10 items from an array is that you can use the numbers 0 and 10 @a[ 0..^10 ] It also means you don't have to do so many +1 or -1 when generating a sequence $n+1 .. $m-1 $n ^..^ $m We don't have to declare ranges with a number past the end like Python range(0,n+1) 0..$n … but we can if it increases clarity range(0,m) 0..^$m Since we don't use prefix ^ for anything else, we have it as shorthand for the above 0..^$m ^$m --- Perl 6 doesn't have a Z=> operator. It has a Z meta-operator and a => operator. my %hash = @keys Z[=>] @values; short for my %hash = zip( @keys, @values ).map: -> ( $key, $value ) { Pair.new( $key, $value } I would like to know which of those you can scan over and be sure it is correct without much thought. We also don't have a += operator, instead = is also a meta-operator $i += 2; $i [+]= 2; # more explicit, but identical Which means that if you modify an existing infix operator or add a new one, you get something like += for free. sub infix:< +++ > ( $l, $r ) { $l + 1 + $r } $i +++= 1; Note that since operators are so simple, we don't have to re-use operators for completely different operations. Just add a new one. --- Sigils and Twigils allow us to know the scope of a variable and that it is a variable, at a glance. sub value () { 10 } submethod BUILD ( $value ) { $!value = $value || value # ^ ^ ^ # | | \_ not a variable # | \__________ subroutine scoped # \_____________________ class scoped } There are also compile time "variables" say $?LINE; and dynamic variables (thread local) say %*ENV; This makes it so that when you modify a dynamic variable, it is immediately obvious that is what you are doing. sub foo () { $*foo = 42; } my $*foo = 0; foo(); say $*foo; # 42 sub bar () { $bar = 42; # compile-time error } my $bar = 0; bar(); say $bar;