Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Raku (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Sigil invariance=== In Perl, [[Sigil (computer programming)|''sigils'']] – the punctuation characters that precede a variable name – change depending on how the variable is used: # Perl code <!--Can't use tag "source lang" because of colorized emphasis on sigil--> my {{font color|red|@}}array = ('a', 'b', 'c'); my $element = {{font color|red|$}}array[1]; # $element equals 'b', my @extract = {{font color|red|@}}array[1, 2]; # @extract equals ('b', 'c') my $element = {{font color|red|@}}array[1]; # 'b' comes with a warning (5.10 option) In Raku, sigils are invariant, which means that they do not change based on whether it is the array or the array element that is needed:<ref name="syn2"/> <!--Can't use tag "source lang" because of colorized emphasis on sigil--> # Raku code my {{font color|red|@}}array = 'a', 'b', 'c'; my $element = {{font color|red|@}}array[1]; # $element equals 'b' my @extract = {{font color|red|@}}array[1, 2]; # @extract equals ('b', 'c') my @extract = {{font color|red|@}}array[1]; # @extract equals ('b') The variance in Perl is inspired by number agreement in English and many other natural languages: "'''This''' apple." # $a CORRECT "'''These''' apples." # @a CORRECT "'''This''' third apple." # $a[3] CORRECT "'''These''' third apple." # @a[3] WRONG However, this conceptual mapping breaks down when using [[Reference (computer science)|references]], since they may refer to data structures even though they are scalars. Thus, dealing with nested data structures may require an expression of both singular and plural form in a single term: <!-- compare the following two code blocks by using the same style syntax--> <syntaxhighlight lang="perl"> # Perl code: retrieve a list from the leaf of a hash containing hashes that contain arrays my @trans_verbs = @{ $dictionary{ 'verb' }{ 'transitive' } }; </syntaxhighlight> This complexity has no equivalent either in common use of natural language or in other programming languages,{{dubious|date=October 2015}} and it causes high [[cognitive load]] when writing code to manipulate complex data structures. This is the same code in Raku: <syntaxhighlight lang="raku"> # Raku code: retrieve a list from the leaf of a hash containing hashes that contain arrays my @trans_verbs = %dictionary<verb><transitive><>; </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)