Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC0020: A builtin for Lexical Export #20

Merged
merged 1 commit into from Jul 8, 2022
Merged

Conversation

leonerd
Copy link
Contributor

@leonerd leonerd commented Jun 28, 2022

No description provided.

@leonerd leonerd changed the title Write RFC0020 - A builtin for Lexical Export RFC0020 - A builtin for Lexical Export Jun 28, 2022
@leonerd leonerd changed the title RFC0020 - A builtin for Lexical Export RFC0020: A builtin for Lexical Export Jun 29, 2022
@ivrntsv
Copy link

ivrntsv commented Jun 29, 2022

Why it is lexically_export and not export_lexically? I think verb should be first.

@leonerd
Copy link
Contributor Author

leonerd commented Jun 29, 2022

Why it is lexically_export and not export_lexically? I think verb should be first.

Hmm i hadn't thought about that. I'm not fussed either way. We should probably make it whatever seems more consistent with other things.

@haarg
Copy link
Contributor

haarg commented Jun 29, 2022

Could also be export_lexical. I'm not too bothered either way.

@ivrntsv
Copy link

ivrntsv commented Jun 29, 2022

I am not so fluent in English so I don't know whether some way is preffered from the language point of view. But from what I saw in programming languages without function overloading there is a naming pattern like action_some_concretization. For unrelated illustration: In Perl you can call sort function with package function: sort numerically @arr. So for me export_lexically sounds more naturally. But this is just a suggestion, food for thought.

@rwp0
Copy link
Contributor

rwp0 commented Jun 30, 2022

I'm for export or lexport to make things simpler

@leonerd
Copy link
Contributor Author

leonerd commented Jun 30, 2022

I'm for export or lexport to make things simpler

I think export is a bit too short for clarity. It doesn't express the lexical nature. I could imagine some sort of builtin function to tidy up the way we do symbolic package exports:

export_symbolically $caller, name => \&func, name2 => \&func2, ...; 

@rwp0
Copy link
Contributor

rwp0 commented Jun 30, 2022

I'm for export or lexport to make things simpler

I think export is a bit too short for clarity. It doesn't express the lexical nature. I could imagine some sort of builtin function to tidy up the way we do symbolic package exports:

export_symbolically $caller, name => \&func, name2 => \&func2, ...; 

Hmm, do you mean a function in addition to the proposed :export attribute?

I'll add l_export to my list of names.


## Motivation

"Traditional" Perl modules of the era around Perl 5.8 have always used symbolic aliasing into the caller's package to implement their export mechanism. This was the only mechanism available to them at the time, and served well in the era of procedural modules with functions in them. As more code became object-oriented, using packages to implement classes, the problems of making these exports visible as named symbols in the class's namespace became apparent, because each imported function would be visible as a named method on the class, whether it wanted that or not.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not just that era, that has true ever since 5.0


If no sigil is present on the name argument, it is presumed to be of the first kind, and the value must be a `CODE` reference.

As the only effect this function has is to add new things to the compiletime lexical scope, it shall be an error to call this function during regular runtime, when no code is currently being compiled. It shall also be an error to pass non-reference values, references to unsupported items (e.g. globs), or references whose type does not match the sigil of its name.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I like how the the compiletime lexical scope is implicit, are we sure that's good enough? (though OTOH hints and hints hash already have that issue and we survive fine)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would the alternative be?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to be a compiletime scope, because that's the only thing that can work. It's unlikely there are multiple nested ones, and in any case I think it would be weird if we were to try to allow some kind of "uplevel" ability to affect scopes beyond the immediate caller. I don't think there's any other way we could offer.

@leonerd
Copy link
Contributor Author

leonerd commented Jul 2, 2022

There seems various thoughts on the name of this. I'm not overly attached to any of them so I think lets propose a vote on the various ideas. Use the "+1" thumbs-up reaction for voting on the following ideas.

Besides the name, is there any other concern anyone has?

@leonerd
Copy link
Contributor Author

leonerd commented Jul 2, 2022

VOTE: lexically_export

@leonerd
Copy link
Contributor Author

leonerd commented Jul 2, 2022

VOTE: export_lexically

@leonerd
Copy link
Contributor Author

leonerd commented Jul 2, 2022

VOTE: export_lexical

rfcs/rfc0020.md Outdated
Comment on lines 40 to 44
+ If the name is a `SCALAR` reference, a new scalar variable will be created in the scope. The corresponding name argument must begin with a `$` sigil.

+ If the name is an `ARRAY` reference, a new array variable will be created in the scope. The corresponding name argument must begin with a `@` sigil.

+ If the name is a `HASH` reference, a new hash variable will be created in the scope. The corresponding name argument must begin with a `%` sigil.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these all be "If the value is a ... reference" rather than "If the name is a ... reference"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, absolutely right. Fix pushed.

@ivrntsv
Copy link

ivrntsv commented Jul 4, 2022

I'm sorry guys. I don't want to test your patience. But how about export_lex and hypothetical export_sym (which this RFC is not about)?

@leonerd
Copy link
Contributor Author

leonerd commented Jul 4, 2022

@ivrntsv

But how about export_lex and hypothetical export_sym

I'm not sure that lex is sufficiently meaningful to new/casual readers, to work out what the thing is (Same as lexport).

This is no longer the 1980s, with code stored on reels of tape or punched cards where every byte matters. We're allowed to spell words out in full now ;)

@leonerd
Copy link
Contributor Author

leonerd commented Jul 4, 2022

It seems export_lexical is currently the vote-winner. I'm not entirely sure how I feel about a function named as a singular noun ("lexical") having the ability to create multiple lexicals, but nevertheless I'll update the spec for that.

@ivrntsv
Copy link

ivrntsv commented Jul 4, 2022

As I see export_lexical is preffered by voters. But that mean mixing verb and adjective. Or maybe in that case export is noun. It should be written lexical_export then. I preffer to mix verb and adverb in export_lexically. Maybe the short variant is the winner so I suggested export_lex as variant. But I don't insist.

Addition: After some thought I see that lexical adjective plays well with exportable noun(s) that follow. Now I'm at peace. Thank you))

@ivrntsv
Copy link

ivrntsv commented Jul 4, 2022

I can't get this thing out of my head. So one final (I wish) thought. export_as_lexical (hypothetical export_as_symbol). This as part will give understanding that something exportable will become a lexical variable (or a package symbol) on the user side. export_lexical tells to export something lexical which is not true. Most of the time you export something global from a package.

@leonerd
Copy link
Contributor Author

leonerd commented Jul 4, 2022

Hmm.. that is true. It's not that the thing being exported is necessarily a lexical (indeed; most of the time for doing coderefs it probably won't be). It's that once exported, the new thing that is created is a lexical. So maybe the word as should be part of its name.

@iabyn
Copy link

iabyn commented Jul 5, 2022 via email

@leonerd
Copy link
Contributor Author

leonerd commented Jul 5, 2022

@iabyn

'export_lexically' would correctly describe how the thing is being exported rather than what is being exported.

Indeed - is why I voted for that one in particular; though it seems export_lexical currently has 7 votes to its 5. But perhaps this distinction is enough to sway it in favour anyway..?

@leonerd
Copy link
Contributor Author

leonerd commented Jul 8, 2022

Righty. Setlled on export_lexically

@leonerd leonerd merged commit 844eda1 into Perl:main Jul 8, 2022
@leonerd leonerd deleted the rfc0020 branch July 8, 2022 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants