lexical means it is only available within that scope,
or in sub-scopes

{
    my $a;
    {
        $a = 42;
    }
}
$a  # error

{
    sub foo (){}
    # my sub foo (){}  # identical
    {
        foo();
    }
}
foo() # error

---

Note that

    sub foo (){}

is really short for

    my only sub foo (){}

The `only` and the `my` are implied

---

For something to be attached to a namespace
it has to be declared as `our` or `has`.

    module Foo {
        constant Bar = 42;
        # our constant Bar = 42; # identical

        our sub foo (){64} # in the namespace
    }
    say Foo::Bar; # 42
    say Baz::foo; # 64

    class Baz {
        method bar (){42}
        # has method bar (){42} # identical

        our sub foo (){64}
    }
    say Baz.bar; # 42
    say Baz::foo; # 64
On Fri, Sep 14, 2018 at 6:15 AM Todd Chester <toddandma...@zoho.com> wrote:
>
>  > On 14/09/2018 12:59, Todd Chester wrote:
>  >> Hi All,
>  >>
>  >> I am in the process of converting a YUGE program I wrote in
>  >> Perl 5 to Perl 6.  I used "xx::yy" at lot for readability
>  >> so I could tell where something came from.
>  >>
>  >> I take it "::" means something different is Perl 6 than Perl 5.
>  >>
>  >> $ p6 'use lib "/home/linuxutil"; use PrintColors;
>  >> PrintColors::PrintRed "Hi\n";'
>  >>
>  >> Could not find symbol '&PrintRed'
>  >>    in block <unit> at -e line 1
>  >>
>  >> In p5 "PrintColors::PrintRed" means to use the routine called
>  >> "PrintRed" found in a modules called "PrintColors".
>  >>
>  >> Does p6 have an equivalent?
>  >>
>  >> Many thanks,
>  >> -T
>
> On 09/14/2018 04:01 AM, Timo Paulssen wrote:
> > It's important for the PrintRed sub inside PrintColors to be declared
> > "our", otherwise it is "my" scoped, i.e. limited to the lexical extent
> > of the module file.
> >
>
> sub PrintRed   ( $Str ) is export { print color('bold'), color('red'),
> "$Str", color('reset'); }
>
> I have never understood the use of "our" in a module.
> I can't tell the difference.
>
> Also, did you answer my question about "::" and did it
> just go over my head?
>
> The p5 guys use to tell me "its lexiconical", meaning it was figured
> out on the fly.  (Took me forever to catch on.)  Is that any
> relation to your use of the word "lexical"?
>
> https://www.dictionary.com/browse/lexical?s=t
>
>     adjective
>
>     of or relating to the words or vocabulary of a language,
>     especially as distinguished from its grammatical and
>     syntactical aspects.
>
>     of, relating to, or of the nature of a lexicon.
>
> -T

Reply via email to