April 10 2014 Meeting Notes

C. Scott Ananian ecmascript at cscott.net
Wed Apr 30 07:33:45 PDT 2014


On Tue, Apr 29, 2014 at 7:47 PM, David Herman <dherman at mozilla.com> wrote:

> Promised you a reply to this one, sorry -- I'm not comfortable with this
> restriction. It violates my Schemer's intuition [1]. In particular it
> creates a number of refactoring hazards: (1) add some try/finally
>
[...]

> [1] "Programming languages should be designed not by piling feature on top
> of feature, but by removing the weaknesses and restrictions that make
> additional features appear necessary."
>

In support of your intuition, here is how you'd implement Domenic's `using`
construct (or `for-using`) using the improved `for-of` (pardon the
mostly-ES5 syntax):

```js
var using = function*(o) {
   try {
      yield o;
   } finally { o.close(); }
};

for (var file of using(open("filename"))) {
   process(file.read()); // or whatever
}
```

- All three of .next, .throw, and .return should take an optional argument.


Calling `.throw()` with no arguments is surprising, but the result
(presumably throwing `undefined`) is consistent with the rest of the
language.  I like the orthogonality of your proposal.
  --scott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140430/61a661de/attachment.html>


More information about the es-discuss mailing list