let-in if do-expr is problematic? (was: Re: proposal: let in if parentheses)
Isiah Meadows
isiahmeadows at gmail.com
Tue Aug 21 19:30:04 UTC 2018
Just as a heads up, something semantically identical to this is what
prompted this big shutdown from Mark Miller, and is why the bar raised
pretty high since for new features:
https://esdiscuss.org/topic/the-tragedy-of-the-common-lisp-or-why-large-languages-explode-was-revive-let-blocks
On Tue, Aug 21, 2018 at 12:20 Herbert Vojčík <herby at mailbox.sk> wrote:
> Hi!
>
> It would be nice to know if do expressions have some a chance, otherwise
> some other syntax for let-in would be really helpful, especially now
> that we have arrow functions.
>
> I would propose to use different variant of let (maybe also const):
>
> OP 1:
>
> let in a = b(), if (a) a.c();
>
> OP 2:
>
> let in a = b(), if (a) c(a);
>
> Instead of
> const big = raw => {
> let cooked = cook(raw);
> return consumer => {
> // do things with consumer and cooked
> };
> };
>
> const big = raw =>
> let in cooked = cook(raw), consume => {
> // do things with consumer and cooked
> };
>
> In short,
>
> let in binding = expr, stmt|expr
>
> It may work for `const in` as well.
>
> Herby
>
> P.S.: Alternative syntax is "let a=3, b=4, ..., in foo(a,b,c,d)" but
> this can only tell late if it is plain let-up-to-end-of-scope or
> local-scope-let, so not sure if that may be a problem; OTOH you can
> chain more of them and resembles classical let-in better.
>
> Isiah Meadows wrote on 21. 8. 2018 20:17:
> > It's possible, but the ability to optionally destructure is what would
> > make this feature worth it - I feel this should wait for pattern
> > matching to be added first, though.
> >
> > On Tue, Aug 21, 2018 at 11:10 Jordan Harband <ljharb at gmail.com
> > <mailto:ljharb at gmail.com>> wrote:
> >
> > ```
> > {
> > let a = b();
> > if (a) {
> > c(a);
> > }
> > }
> > ```
> >
> > On Tue, Aug 21, 2018 at 10:54 AM, Ali Rahbari <rahbari at gmail.com
> > <mailto:rahbari at gmail.com>> wrote:
> >
> > while it's possible to use let keyword in for loop parentheses,
> > it's not possible to use it in if parentheses.
> >
> > There are two use cases for this:
> >
> > *1- if (let a = b()) a.c();*
> > this can be done using optional chaining which is proposed:
> > b()?.c();
> >
> > *2- if (let a = b()) c(a);*
> > this or more sophisticated patterns can't be done in any way
> > other than this:
> > let a = b();
> > if (a) c(a);
> >
> > the problem here beside more line of codes, is *a *is defined
> > outside of if scope.
> >
> >
> > _______________________________________________
> > es-discuss mailing list
> > es-discuss at mozilla.org <mailto:es-discuss at mozilla.org>
> > https://mail.mozilla.org/listinfo/es-discuss
> >
> >
> > _______________________________________________
> > es-discuss mailing list
> > es-discuss at mozilla.org <mailto:es-discuss at mozilla.org>
> > https://mail.mozilla.org/listinfo/es-discuss
> >
> > _______________________________________________
> > es-discuss mailing list
> > es-discuss at mozilla.org
> > https://mail.mozilla.org/listinfo/es-discuss
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180821/d2bb569c/attachment-0001.html>
More information about the es-discuss
mailing list