FYI: Import namespaces

53 views
Skip to first unread message

Tako Schotanus

unread,
Jul 12, 2016, 4:51:24 AM7/12/16
to ceylon-dev
Hi people,

I just merged my first change to the syntax of the language! \o/

Anyway, this is about the import namespaces I added some time ago which worked like this:

    import "[namespace:]some-import" "version";

But Gavin suggested that it would be nicer to make the namespace part of the syntax of the language. So I decided on the following:

    import [namespace:]some.import "version";
    import [namespace:]"some-import" "version";

The immediate recognizable difference is that the namespace can now be used in both forms of the import, the quoted and unquoted ones, but also that the typechecker knows about the prefix and can validate that the namespace is just a plain identifier (no spaces, special characters, etc).

But a very nice advantage of this change is that no old-style Maven imports can be ambiguous anymore! Before an import like:

    import "junit:junit" "1.2.3";

could be misinterpreted as an import of module "junit" for the namespace "junit" requiring you to fix the import by adding the "maven:" prefix, but not anymore! The prefix is still preferred though, so if you use the above import you'll get a warning telling you to change it to:

    import maven:"junit:junit" "1.2.3";

Have a nice day,
-Tako

Bastien Jansen

unread,
Jul 12, 2016, 4:54:15 AM7/12/16
to ceylo...@googlegroups.com
👍

--
You received this message because you are subscribed to the Google Groups "ceylon-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceylon-dev+...@googlegroups.com.
To post to this group, send email to ceylo...@googlegroups.com.
Visit this group at https://groups.google.com/group/ceylon-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceylon-dev/CAOJRyvr8%3D7vMFB2GR_yrAMJL%3D8SZyncdibZC_DedcfnNqqOpxw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Enrique

unread,
Jul 12, 2016, 4:31:29 PM7/12/16
to ceylon-dev, ta...@codejive.org
Looks much better that way.

Were annotations not an option? Maybe

maven import "foo:bar" "version";

and

npm import "foo-bar" "version";

Tako Schotanus

unread,
Jul 12, 2016, 6:15:51 PM7/12/16
to ceylon-dev

On Tue, Jul 12, 2016 at 10:31 PM, Enrique <alte...@gmail.com> wrote:
Were annotations not an option?

Technically yes, although not like you suggest because that would mean having to create a new annotation for each new repository which a) is not very pluggable and b) only gives more possibilities of name clashes. So we would have needed something like:

   from("maven") import "foo.bar" "version";

So technically that is completely possible, except for the fact that for me the namespace is really part of the import, just as its name and its version are. I mean theoretically we could put everything in annotations:

   name("foo:bar) version("1.0") import;

;)

But I feel that annotations are better suited for "adjustments" to the core behaviour. "optional" and "shared" are important annotations but the module they refer to stays the same. The fact that a module comes from the Herd or Maven or NPM on the other hand is essential.

At least that's the way how I "explain" it to myself ^^

-Tako

Enrique

unread,
Jul 13, 2016, 9:49:16 PM7/13/16
to ceylon-dev, ta...@codejive.org
Right, makes sense.
Reply all
Reply to author
Forward
0 new messages