Ticket #283 (closed defect: deferred)

Opened 1 year ago

Last modified 8 months ago

(Resolved) Kill aliasing import

Reported by: lth Assigned to: lth
Type: defect Priority: trivial
Milestone: Component: Spec
Version: 4 Keywords:
Cc: graydon,brendan,jeffdyer

Description

(Result of email discussion and discussion with Jeff.)

The semantics for import pkg.x and import pkg.* are clear, they open pkg's public namespace in references to x and references to all names, respectively, for the duration of the block. An x defined in an intermediate scope will take priority; pkg.x is always a global name.

The semantics of import y = pkg.x are not compatible. Instead, that form introduces an alias binding in the local block s.t. a reference to y goes directly to pkg.x even if there are other xs in intermediate scopes.

First of all, I wonder if we need this form. On the one hand it's part of the "evolutionary programming toolbox". On the other hand, there is no implementation or usability experience from AS3, and I know I don't use renaming when I program.

Second, since the aliasing form introduces a new block-scoped binding it is as much like "let" as it is like "import". I think that if we keep it, we should change the syntax to this:

   let import y = pkg.x

to emphasize just that. (There is also the issue that y is bound in the block object and that references to y in the block before it is introduced ought to be run-time errors, just as we've discussed for normal let-bound variables. So it is really very let-like.)

Attachments

Change History

Changed 1 year ago by brendan

If we can lose the renaming form, let's simplify ES4's grammar and do so. IIRC you could always use full package qualification to resolve ambiguities due to collisions of leaf name among packages, and you can abstract those via let into short-name refs. That should be enough.

/be

Changed 1 year ago by jeffdyer

Agreed. The user can use an import and a let to do aliasing

The problem case is where a binding shadows a package name like this:

import x = p.y
{
  var p
  print (x) // no way to refer to p.y here
}

These cases are rare and they can be easily, and maybe more clearly expressed like this:

var p
{
  import p.y
  print (p.y)
}

Changed 1 year ago by lth

  • priority changed from major to trivial
  • summary changed from Cleanup: Do we really need aliasing import? And if we do, is the syntax right? to (Resolved) Kill aliasing import

Changed 8 months ago by graydon

  • status changed from new to closed
  • resolution set to deferred

packages (and thus import) have been removed from the feature-set of ES4

Note: See TracTickets for help on using tickets.