develooper Front page | perl.perl5.porters | Postings from January 2022

Re: Pre-RFC: a `module` keyword

Thread Previous | Thread Next
From:
Ovid via perl5-porters
Date:
January 24, 2022 20:57
Subject:
Re: Pre-RFC: a `module` keyword
Message ID:
1049143199.948632.1643057874462@mail.yahoo.com
On Monday, 24 January 2022, 21:39:08 CET, Tomasz Konojacki <me@xenu.pl> wrote:

> > * Strict, warnings, utf8 source, signatures, and "no feature 'indirect'" by default
>
> We can't make the "module" keyword visible without a feature flag. "use
> VERSION" will still be needed and that enables all the nice stuff
> anyway. 

My intention for the full RFC was:

    use feature 'module';

> Well, apart from "use utf8". It's been decided that it's a bad
> default: https://www.nntp.perl.org/group/perl.perl5.porters/2021/08/msg261164.html

The change is lexically scoped, so ...

    use 5.38.0;

    module My::Module :version(.1) {
        # use utf8 is only applied here in brand new code
    }

    # use utf8 does not apply here

> > * :export is handled natively leaving the import() free for other uses
>
> I don't see why a new keyword is needed for that. If we want ':export'
> attribute (which is an interesting idea), it can be implemented without
> the "module" keyword. Perl already supports attributes on subs and we
> already have a few built-in ones (such as :const, :method etc.).

There is no new keyword. Instead, this follows the Corinna "KIM syntax" (https://ovid.github.io/articles/language-design-consistency.html) to ensure language design consistency. :import is a modifier, not a keyword. This RFC would introduce only one new keyword, `module`, and `:import` doesn't exist without that feature.

> The "package" keyword currently doesn't take attributes, but I think it
> can be changed. "package Foo :bar" is a syntax error, so it probably
> doesn't conflict with anything.

Agreed, but I'm trying to create something which is entirely lexically scoped in a new syntax to avoid complicating existing code.

> We should be always wary of adding new keywords, especially the ones that
> do the same thing as already existing keywords but slightly differently.
> We will be stuck with both keywords forever. It will make the language
> more complex and confusing.

Agreed. That's why only `module` is a new keyword. If `module` goes away, so does `:import` and `:version` (for `package`, it would still be there for Corinna's `class` keyword).

Best,
Ovid
-- 
IT consulting, training, specializing in Perl, databases, and agile development
http://www.allaroundtheworld.fr/. 

Buy my book! - http://bit.ly/beginning_perl


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About