Replies: 4 comments 9 replies
-
An alternative would be a postfix operation as seen in some other languages. Eg
|
Beta Was this translation helpful? Give feedback.
This comment has been minimized.
This comment has been minimized.
-
Regarding phase levels, I strongly prefer the approach of grouping imports by phase because it makes it much easier to know what bindings are available at which phase. Therefore, I really like having |
Beta Was this translation helpful? Give feedback.
-
How about this? The following could all be equivalent ways to import
While verbose, the term The path is built up out of operators. In addition to the module-or-collection-forming operator The Since the local alias for an import would oftentimes resemble an unqualified version of the external name, the default local alias would be inferred based on the last component of the imported path. So the above examples all import Depending on the path, the last component could be a top-level collection (in which case the collection's name is used, not "main.rkt"), a subcollection, a module, a filename-named module (in which case the file extension is dropped), a submodule, or an export. The following would all be equivalent ways to import the
Imports of all the exports of a module could be specified using
As discussed here, code that uses this kind of import can be unstable. However, I believe it can be justified in cases where the author of this client code is in control of the library's exports or in cases where the library promises not to add arbitrary exports in future versions. In particular, I think
is correct. If the person importing the modules is the same person who's maintaining them, there's no need for them to worry that there'll be unanticipated exports in the future. (Hopefully they're testing their code well enough to catch import conflicts they create in their own files.) It's only imports of other packages' modules that are in particular need of explicit prefixes or import lists, and even many of those cases can be factored out to be uncommon:
I'm going to take a detour back to to the idea of importing prefixes. If we're using the exports of a module according to a prefix, what about using that module's submodules? If the module is I propose adding another path operator,
In this case, by defining an alias Perhaps the more obvious design would be to allow this kind of prefixing even without the
However, I think that would lead to surprises in common situations:
Besides sidestepping these surprises, an explicit And that brings me back to the idea of importing bundles of imports all at once. I mentioned the potential of importing just the v1 exports of Now we can consider using operations
These would be in some ways similar to the aliases we get from importing a module with a prefix, except that these could be used somewhere other than the beginning of a module path. As shown in one case ( In the case of In the case of All right. One last aspect to account for is phase-shifting (
If you prefer putting everything in one import, I guess I'd go with:
With all these ideas in place, the example at the start of the thread would become:
|
Beta Was this translation helpful? Give feedback.
-
The current syntax for
import
isThis is simple and regular, but it means that
no_prefix
(orprefix
) is relegated to theimport_modifier
part, which feels verbose and backwards. Afor_meta
orfor_label
similarly feels too buried in theimport_modifier
part.Here's a real example from
"rhombus.rhm"
as part of the current implementation ofscribble/rhombus
:The
rhombus/macro: no_prefix
part is especially common. Also, a typical ".scrbl" file implementing the current documentation hasimport: "common.rhm": no_prefix
; using a prefix would not work right for"common.rhm"
, because it's meant to providefor_label
bindings ofrhombus
and other exports for typesetting. In other cases, I find that using a prefix for my own local modules (like"typeset_meta.rhm"
) feels like overkill, but maybe that's just my Racket habits misleading me.I'm tempted to go back to the old
=
-based syntax for import prefixes, especially if we avoid using=
as a comparison or assignment operator and reserve as a kind of delimiter within a form likefun
orimport
. Also, I'm tempted to havefor_meta
andfor_label
work to group a set ofmodule_path
s. With those changes, the example above would look like this:The leading
=
does a better job of highlighting namespace dumping, and typingimport: = rhombus/maco
is nicer thanimport: rhombus/macro: no_prefix
(which I have to type all the time).Here's the current
"common.rhm"
:Possible revision:
Any opinions or other ideas?
Beta Was this translation helpful? Give feedback.
All reactions