Raku slang permitting Not to use sigils
use Slang::Nogil;
nogil = 3;
say nogil + 39; # OUTPUT: 42
say $nogil; # OUTPUT: 3
say "Interpolate $nogil"; # OUTPUT: "Interpolate 3"
say "Interpolate {nogil * 10 + 12}"; # OUTPUT: "Interpolate 42"
use Slang::Nogil;
local = "value";
say local; # OUTPUT: "value"
sub fct(param) {
say param;
}
fct("argument"); # OUTPUT: "argument"
If you're going through hell, keep going (Winston Churchill)
"Nogil" variables are hidden scalar variables. You can refer to them with or without the scalar sigil '$'. For example, you can interpolate them prefixing by a '$' in double quoted strings.
Scalars are autodeclared to an Raku Any instance. which is augmented to get '' and 0 and default Str and Int.
Some pragmas are added to the importing scope:
- no strict: can declare without
my
:
say varname = 42; # OUTPUTS: 42
-
lib: '.', 'lib', 't', 't/lib': can import module in those directories
A tool is only worth by the hand that animates it (Marshall of Lattre)
- sigilless variables:
my \foo = $ = 41; # a sigilless scalar variable
my \bar = @ = 1,2,3,4,5; # a sigilless array
my \baz = % = a => 42, b => 666; # a sigilless hash
my $var = 1;
sub fct is rw { $var; } # Note the is tw trait
fct() = 2; # Note the necessary ()
say fct; # OUTPUTS: 2
Doubtless this is somewhat interesting to someone somewhere, but we'll restrain ourselves from talking about them somehow (TimToady)
Brief: Sigils can be seem as type declaration. They permit compiler optimisation and avoid user error at compile time.
Note that this plugin only aliases the scalar sigil (by void).
You are strongly recommended to keep using the @
, %
and &
sigils.
If those are absent from your code, guess you are writing, like most of us, "baby Raku" and losing some awesome compiler optimisations.
- Syntactic disambiguation : you can call a variable whatever you want, even if there happens to be a keyword with that name
- Here: routines (
&
) and sigless (\\
) variables override nosig (``) variables.
- Here: routines (
- Readability : the data in the program stands out thanks to the sigil
- Here: the way of the poet is in your palm. Never say the aggresive: "it doesn't make sense" and prefer the humble "I don't understand".
- Defining assignment semantics : in Perl 6 assignment means "copy in to", thus my @a = @b means iterate @b and put each thing in it into @a, thus any future assignments to @b will not affect @a
- Here:
=
assign:=
bind. I think ...
- Here:
- Restricting what can be bound there : only Positional things to @, for example
- Here: you can by default affect anything to a scalar. Same for a nogil. Just take care to give transform it to the good type before (ex
var-hash = %(1=>2, 3=>4)
). Some containerisation (object reference)
- Here: you can by default affect anything to a scalar. Same for a nogil. Just take care to give transform it to the good type before (ex
- In the case of the $, controlling what will be considered a single item
- Here: use nogil or scalar.
- In the case of @ on a signature parameter, causing an incoming Seq to be cached
- Here:
var-array = @(1..3)
. But then you may get it trouble to iterate or push. If using a list, you better explicit it to the compiler.
- Here:
- Interpolation in double quoted strings
- Here: use the
$
or{}
construct
- Here: use the
Source: jnthn
I don't know, Lord, if you are happy with me; but I am very happy with You (Louis Bourdaloue)
- Grammar: European sigil € -> from the time
token sigil
was a proto - Grammar: Slang Mouq Tuto -> aimed at
use v5
, shows very well the skeleton - QAST: QASTalicious -> list QAST operations
- Array: Negative Array indexing -> Show the code related to
@arr[-1]
- Array: multi order: where clause is called first. Try
no precompilation
in module - Str: Slice like Array: At -> FETCH
- Str: Str as Array: Assign -> STORE
- Str: Pythonic -> Operator overload
postcircumfix:<[ ]>
- Nogil Tests