Quasis: assignable substitutions?

Mike Samuel mikesamuel at gmail.com
Thu Jun 16 16:23:57 PDT 2011


2011/6/16 Axel Rauschmayer <axel at rauschma.de>:
> http://wiki.ecmascript.org/doku.php?id=harmony:quasis
>
> re_match`foo (${=x}\d+) bar`
>
> How do these work? Are the changes that re_match makes written back to x? I can image a solution if substitutions were given to the handler as an array, but not if they are given as trailing parameters.
>
> Thanks!

These were somewhat controversial when I first presented.  So the
proposal as written does not include them, but the semantics are
specified as an optional extra that the committee could consider.

You may have noticed this somewhat strange production.

    //SubstitutionModifier// ::
        ε

The alternative syntax and desugaring detailed at
http://wiki.ecmascript.org/doku.php?id=strawman:quasis-substitutions-slot
redefines

    //SubstitutionModifier// ::

        ε
        =

and redefines the SVE of ${=x.y} to be

     function () { return arguments.length ? (x.y = arguments[0]) : x.y }

so instead of passing substitution values, for read-only substitutions
(those without the = modifier) you get a thunk, and for writable
substitutions you get a function that returns the value when called
with 0 arguments or assigns the first parameter if passed one.


More information about the es-discuss mailing list