<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small;color:#000000">If `def(if=3)...` works implicitly, then why not make `if = 3`, <span style="color:rgb(0,0,0);font-family:verdana,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">`x.if = 3`, </span>`import if`, `def if` and `class if` implicit too?</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small;color:#000000">Another issue is what happens here:</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small;color:#000000">keyword if</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small;color:#000000">import if</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small;color:#000000">f(if=3)</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small;color:#000000">f.if = 3</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small;color:#000000">The keyword will be a valid name in old code, so you need to be able to reference it as a name in code that uses it as a keyword.</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small;color:#000000"><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><span style="color:rgb(115,115,115);font-style:italic;line-height:18px"><font size="1" face="monospace, monospace">-- Carl Smith</font></span><br></div></div><div><span style="color:rgb(115,115,115);font-style:italic;line-height:18px"><font size="1" face="monospace, monospace"><a href="mailto:carl.input@gmail.com" target="_blank">carl.input@gmail.com</a></font></span></div></div></div></div></div></div>
<br><div class="gmail_quote">On 16 May 2018 at 18:24, Adam Bartoš <span dir="ltr"><<a href="mailto:drekin@gmail.com" target="_blank">drekin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hello,<br><br></div>I have yet another idea regarding the the clashes between new keywords and already used names. How about introducing two new keywords *wink* that would serve as lexical keyword/nonkeyword declarations, similarly to nonlocal and global declarations?<br><br></div><div>def f():<br></div><div>    nonkeyword if<br></div><div>    if = 2 # we use 'if' as an identifier<br></div><div>    def g():<br></div><div>        keyword if<br></div><div>        if x > 0: pass # now 'if' again introduces a conditional statement<br><br></div><div>This allows to have a name as both identifier and keyword in a single module, and since it's lexical, it could be in principle syntax-highlighted correctly.<br></div><div><br></div><div>When a new keyword is added to the list of standard keywords like 'given' or 'where', a module that uses the name as identifier could be easily fixed by a global declaration 'nonkeyword given'. Maybe even exception messages pointing to this could be added. If 'nonkeyword keyword' is allowed, we can also fix code using the name 'keyword' as an identifier, but doing so in the global scope couldn't be undone.<br><br></div><div>On the other hand, new language features depending on new keywords could be made provisionary by not adding the keywords to the standard list, so people who would like to use them would need to opt in by e.g. 'keyword given'. Surely, this provisional mechanism isn't robust at all since new features may just extend the usage of current keywords.<br><br></div><div>Declaring a keyword that has no meaning in the language would result in an exception:<br><br></div><div>keyword foo # SyntaxError: undefined keyword 'foo'<br></div><div><br></div><div>It should be possible to use a keyword as a parameter name without need to declare it in the surrounding scope, the local declaration would suffice:<br><br></div><div># nonkeyword if # not needed<br></div><div>def f(if=3): # ok<br></div><div>    nonkeyword if<br><br></div><div>Other option is to interpret parameters always as nonkeywords or to raise a special syntax error when a keyword occurs at a place of a formal parameter (similarly to 'def f(x): nonlocal x').<br><br></div><div>Clearly, even if this proposal diminished the cost of adding new keywords, the cost would still be high.<br><br><br></div><div>Best regards,<br></div><div>Adam Bartoš<br><br></div></div>
<br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
<br></blockquote></div><br></div>