-
Notifications
You must be signed in to change notification settings - Fork 421
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
Future: feature idea: "use Module as M" #3900
Conversation
to allow fully-qualified references to Module's symbols through the name M. (e.g., reference Module.x as M.x)
I don't have a need, or even a use case, for this. I just thought it'd be neat. Feel free to reject the PR if it doesn't seem useful or worthwhile. |
👍 I really like this suggestion/approach |
I was originally intrigued by this proposal (in the "maybe this is what we've been seeking" sense), but thinking about it some more, I'm not sure that it's the right way to say "make me use fully qualified names" -- though I think it could still be a supported feature as a way of avoiding typing a long module name. Specifically, in the case where I prefer the original module name to creating a new alias to it, it seems like I should be able to type:
rather than being required to type:
Yet, 'use M as M' seems like just a roundabout way to write 'use M' and therefore seems like it should behave the same (i.e., should not suggest a requirement to use fully qualified names). By extension, 'use M as aliasForM' seems like it's saying "permit me to call 'M' 'aliasForM' but it doesn't actually suggest (to me) anything different about the names needing to be fully qualified. So for that, I still think that, given the current definition of 'use', the requirement to fully qualify should be specified differently than 'as'. E.g., perhaps:
or:
where 'qualified' is a keyword (and where the two other new-keyword-free approaches we've discussed are:
and:
Two other notes:
|
@bradcray - what about using the "require" keyword, since the dependency implied is very similar? In terms of the current suggestion - what should "use Foo as M;" imply? Should the symbols of Foo be accessible without any prefix as well as with "M." as a qualifier? If so, is there really much point in renaming the module? If not, is a use statement really appropriate for this operation? Should the symbols be also accessible via the old name, or should they only be accessible in this context through the shorter name? My preference is for the later, which is consistent with the current renaming strategy, but do others differ? |
I interpreted Paul's suggestion as meaning 'use Foo as M;' causes Foo's symbols to only be accessible via 'M.", not in an unqualified manner, and not via Foo. But maybe I read too much into it. I'm not sure what you're proposing w.r.t. the 'require' keyword (how it would be used). |
One other thought that occurred to me on the walk in, which is a bit crazy but I'll throw it out there anyway: Last week, there were some discussions of treating code within a 'module M { ... }' context more strictly as compared to code within a top-level ("sketch-oriented") file without a 'module' keyword. If that theme ended up sticking, we could potentially interpret a 'use' in the strict context as being "only nothing / except everything" by default and a 'use' in the loose context as being "only everything / except nothing" by default. This would probably keep current code working while forcing a lockdown of library code. |
(summarizing to be sure I'm thinking about the keyword correctly) The 'require' keyword is currently used to imply that the file named should be compiled at the same time as the source file. Couldn't we make it possible for any module within a Chapel file named to be accessible via explicit naming? Or does the 'require' keyword assume a specific location for the file named? As the creator of this keyword, does that seem like a strong departure from its intended purpose? The above strategy appeals to me because it feels like a logical extension of the 'require' keyword, avoids an extension of the 'use' keyword that feels like a bit of a stretch, and doesn't introduce an entirely new keyword for the functionality. But I'm not married to the concept - just throwing it out as an alternative idea. I should note that I'm not in favor of changing the behavior of code that significantly based on whether or not it is in an explicit module declaration - if you're writing a sketch of code that you'll flesh out more extensively as you go, wouldn't you want to know that the behavior you're testing is the behavior it will still have in its polished state? I do think that Paul's suggestion here is more along the lines of "only access these symbols with the new prefix", but that seems to me like utilizing the 'use' keyword because it's there rather than because what we're intending to accomplish is actually in step with a use of a module (which could arguably be applied to what I'm proposing with the 'require' keyword above - as I said, I was throwing that out there as an option, not saying it is definitely what I think we should do). I think I'd be more in favor of |
Eek. All I'd meant was to allow the syntax to create an alternate Analogously to use M only foo as bar creating an alternate name for M.foo,
a user could create a shorter (or for that matter, longer) name
I hadn't thought of it as conflicting at all with any other "use Moo;" But as I said, I don't have a need for it; I just thought it was a Alternate syntax for this thing I don't have a need for might include
or
|
@cassella, we're thinking we'll merge this PR but won't work on it right away. Would you mind inserting a link to this PR in the .future file so we can refer back to this discussion? |
The changes look good, thanks @cassella! |
to allow fully-qualified references to Module's symbols
through the name M. (e.g., reference Module.x as M.x)