Skip to content

Constants Should Be Covered in Raku Essentials #17

@gitjeff2

Description

@gitjeff2

Unless I missed something, constants aren't covered at all in the course. Constants are worthy of mention, most likely in the Variables and Data Types Essentials section. It should be noted that in Raku, unlike Perl, constants can be lexically scoped with my just like a variable.

Thus, this code works as expected:

my constant $A="bar";    
    
sub foo {    
    my constant $A="foo";    
    say $A;    
}    
    
foo();    
say $A;    

The user can expect the following output:

$ ./constant.raku 
foo
bar

Attempts to redefine a constant will throw an error. Given the importance of read-only variables in FP, this is all worth revisiting in Course 5: Functional, Concurrent, and Reactive Programming.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions