Modulo Operator %%

Waldemar Horwat waldemar at google.com
Thu Aug 15 00:49:44 UTC 2019


On 8/13/19 8:32 PM, Michael Haufe wrote:
> On 8/13/19 7:27 AM, Michael Haufe wrote:
>> I would prefer the syntax be ‘a mod b’ consistent with my wishlist item:
> 
> On 8/13/19 9:12 PM, Waldemar Horwat wrote:
>> This can bring up various syntactic troubles.  What does the following do?
>>
>> let mod
>> +3
>>
>> Is it calling the mod operator on the variable named "let" and +3?  Or is it defining a variable named "mod" with no initializer, followed by an expression?
> 
> I can't declare 'let' or 'var' as variable names, but even if I could (Say non-strict mode or ES3) that form would be a VariableDeclaration followed by an ExpressionStatement.
> 
> The proposed grammar extension is:
> 
> MultiplicativeOperator: one of
>      * / % div mod

And I'm saying that's potentially problematic because it changes the meaning of existing programs that happen to use "mod" as a variable name.  The above is one example that would turn a let statement into a mod expression.  Here's another example:

x = 4
mod(foo)

     Waldemar


More information about the es-discuss mailing list