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

Clarification on import name alias #3

Open
mguetschow opened this issue Feb 27, 2024 · 3 comments
Open

Clarification on import name alias #3

mguetschow opened this issue Feb 27, 2024 · 3 comments

Comments

@mguetschow
Copy link

Section 2.6 states that

The import statement can also request an alias for an imported name

giving the following example

$ cddlc -2tcddl -
mydata = {Fritz: cose.empty_or_serialized_map}
;# import empty_or_serialized_map from rfc9052 as cose

First of all, I would suggest changing the mydata definition to actually use that alias instead of the namespaced version.

But it is also not completely clear to me how this alias definition is supposed to work - does it barely mean that for a given name, an additional rule is added without namespace (and the name needs to match the name in the imported module)? If so, the wording is a bit confusing to me.

Reading the sentence above, I would have expected syntax along the lines of

;# import empty_or_serialized_map as my_map from rfc9052 as cose

which would define my_map (without namespace) as an alias for cose.empty_or_serialized_map.

@cabo
Copy link
Contributor

cabo commented Mar 9, 2024

Right. The only "automatic" alias you can get is the one for "unpacking" single items from an import that uses a namespace that the imports are otherwise mapped into:

;# import empty_or_serialized_map from rfc9052 as cose

;# import cose.empty_or_serialized_map from rfc9052 as cose
empty_or_serialized_map = cose.empty_or_serialized_map

For any other alias, you need to add your own rule

;# import cose.empty_or_serialized_map from rfc9052 as cose
my_map = cose.empty_or_serialized_map

We could add syntax to allow creating these, or we could let the spec writer simply write that additional rule.

@mguetschow
Copy link
Author

We could add syntax to allow creating these, or we could let the spec writer simply write that additional rule.

Since adding the alias yourself is that easy, I would rather not complicate the syntax further for this. On the contrary, I would actually reconsider having the "automatic" alias as well, with the same argument.

Getting rid of the automatic alias would also allow for simplified syntax for namespaced includes/imports as in:

;# include label, values from rfc9052 as cose

instead of repeating the namespace name verbally for every rule:

;# include cose.label, cose.values from rfc9052 as cose

That way, the only difference between including/importing a module with or without namespacing is the as <namespace>.

As mentioned above, the different semantics for include/import, with/without explicit rule selection and with/without namespaces got me slightly confused and I think dropping the automatic alias feature and unifying explicit rule selection would ease understanding.

Or is there any good reason why this kind of automatic alias creation is especially useful / used that much that it justifies the added complexity?

@cabo
Copy link
Contributor

cabo commented Mar 11, 2024 via email

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

No branches or pull requests

2 participants