<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div style="font-size: 34px;">Hi. Just to respond to some peoples’ points…</div><div style="font-size: 34px;">Bernardo asked <i class="">'This would be "constant" as in Java constants right? Referential </i></div><i class=""><span style="font-size: 34px;" class="">constants, so that if an object were mutable you would still be able to</span><span style="font-size: 34px;" class=""> </span><br style="font-size: 34px;" class=""></i><div><span style="font-size: 34px;" class=""><i class="">change its internal state.’</i></span></div><div><span style="font-size: 34px;" class="">Um, I’m not entirely sure what you mean, since I’ve never used Java. But if it means what I think it means, I would be INCLINED to say no. If, for example, I saw code like this:</span></div><div><span style="font-size: 34px;" class=""><br class=""></span></div><div><div><span style="font-size: 34px;" class="">x = [9, 5, 7, 1]</span></div><div><span style="font-size: 34px;" class="">let y = x</span></div><div><span style="font-size: 34px;" class="">y[0] = 42</span></div><div><span style="font-size: 34px;" class="">print(y)</span></div><div><span style="font-size: 34px;" class=""><br class=""></span></div><div><span style="font-size: 34px;" class="">… I would expect that code to raise an error, not print “[42, 5, 7, 1]”, since you’re trying to modify the “constant” y in place, which… well, would kind of go against the idea of y being a constant, I thought (unless I’m misunderstanding what you meant by “object", since everything in Python’s an object).</span></div><div><span style="font-size: 34px;" class=""><br class=""></span></div><div><span style="font-size: 34px;" class="">However, I might change my opinion if I heard a good reason why Java-like constants would be better.</span></div><div><span style="font-size: 34px;" class=""><br class=""></span></div><div><span style="font-size: 34px;" class="">Serhiy asked, in relation to constants, “To do what? What problem do you need to solve?”. No problem in particular, to be honest. I just thought they’d be nice since they’d increase confidence that my variables-intended-to-be-constants wouldn’t get reassigned, and just to increase readability/explicitness to other programmers.</span></div><div><br class=""></div><blockquote type="cite" class=""><div class="">On 21 Nov 2017, at 20:08, <a href="mailto:python-ideas-request@python.org" class="">python-ideas-request@python.org</a> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Send Python-ideas mailing list submissions to<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span><a href="mailto:python-ideas@python.org" class="">python-ideas@python.org</a><br class=""><br class="">To subscribe or unsubscribe via the World Wide Web, visit<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span>https://mail.python.org/mailman/listinfo/python-ideas<br class="">or, via email, send a message with subject or body 'help' to<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span>python-ideas-request@python.org<br class=""><br class="">You can reach the person managing the list at<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span>python-ideas-owner@python.org<br class=""><br class="">When replying, please edit your Subject line so it is more specific<br class="">than "Re: Contents of Python-ideas digest..."<br class=""><br class=""><br class="">Today's Topics:<br class=""><br class=""> 1. Re: Should Python have user-defined constants? (Steven D'Aprano)<br class=""> 2. Re: Should Python have user-defined constants? (St?fane Fermigier)<br class=""> 3. Re: Should Python have user-defined constants? (Bernardo Sulzbach)<br class=""> 4. Star assignment in iterator way? (Kirill Balunov)<br class=""> 5. Re: Star assignment in iterator way? (Serhiy Storchaka)<br class=""><br class=""><br class="">----------------------------------------------------------------------<br class=""><br class="">Message: 1<br class="">Date: Tue, 21 Nov 2017 19:13:42 +1100<br class="">From: Steven D'Aprano <steve@pearwood.info><br class="">To: python-ideas@python.org<br class="">Subject: Re: [Python-ideas] Should Python have user-defined constants?<br class="">Message-ID: <20171121081342.GK19802@ando.pearwood.info><br class="">Content-Type: text/plain; charset=us-ascii<br class=""><br class="">On Tue, Nov 21, 2017 at 02:38:45AM -0500, Joseph Jevnik wrote:<br class=""><br class=""><blockquote type="cite" class="">How is that different from "pi = 3.14"?<br class=""></blockquote><br class="">pi = 3.14<br class="">pi = 5<br class="">print(pi)<br class=""># prints 5<br class=""><br class="">let pi = 3.14<br class="">pi = 5<br class=""># raises an exception<br class=""><br class=""><br class=""><br class="">-- <br class="">Steve<br class=""><br class=""><br class="">------------------------------<br class=""><br class="">Message: 2<br class="">Date: Tue, 21 Nov 2017 09:26:17 +0100<br class="">From: St?fane Fermigier <sf@fermigier.com><br class="">To: Python-Ideas <python-ideas@python.org><br class="">Subject: Re: [Python-ideas] Should Python have user-defined constants?<br class="">Message-ID:<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span><CABuJJj5-ZhuWTBns8rm8jVWPaOGq08MM+X0ryQp1z7ogQFsHvw@mail.gmail.com><br class="">Content-Type: text/plain; charset="utf-8"<br class=""><br class="">Javascript (ES6) has 'let' and 'const' for mutable and constant variables,<br class="">respectively.<br class=""><br class="">When programming in JS, I find myself aggressively aiming for as little<br class="">'let' and as much 'const' as reasonably possible, since reasoning about<br class="">constants is much easier than about variables. In this context, 'const' is<br class="">used as a marker, a runtime checker, and, with proper tooling (IDE or<br class="">linter), a coding-time reminder to differentiate between these two<br class="">fundamental behaviours.<br class=""><br class="">I'm not +1 on introducing this idea to Python yet, but not -1 either - this<br class="">deserves some discussion, if this has not been discussed already.<br class=""><br class="">Cheers,<br class=""><br class=""> S.<br class=""><br class="">On Tue, Nov 21, 2017 at 9:13 AM, Steven D'Aprano <steve@pearwood.info><br class="">wrote:<br class=""><br class=""><blockquote type="cite" class="">On Tue, Nov 21, 2017 at 02:38:45AM -0500, Joseph Jevnik wrote:<br class=""><br class=""><blockquote type="cite" class="">How is that different from "pi = 3.14"?<br class=""></blockquote><br class="">pi = 3.14<br class="">pi = 5<br class="">print(pi)<br class=""># prints 5<br class=""><br class="">let pi = 3.14<br class="">pi = 5<br class=""># raises an exception<br class=""><br class=""><br class=""><br class="">--<br class="">Steve<br class="">_______________________________________________<br class="">Python-ideas mailing list<br class="">Python-ideas@python.org<br class="">https://mail.python.org/mailman/listinfo/python-ideas<br class="">Code of Conduct: http://python.org/psf/codeofconduct/<br class=""><br class=""></blockquote><br class=""><br class=""><br class="">-- <br class="">Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier -<br class="">http://linkedin.com/in/sfermigier<br class="">Founder & CEO, Abilian - Enterprise Social Software -<br class="">http://www.abilian.com/<br class="">Chairman, Free&OSS Group / Systematic Cluster -<br class="">http://www.gt-logiciel-libre.org/<br class="">Co-Chairman, National Council for Free & Open Source Software (CNLL) -<br class="">http://cnll.fr/<br class="">Founder & Organiser, PyData Paris - http://pydata.fr/<br class="">---<br class="">?You never change things by ?ghting the existing reality. To change<br class="">something, build a new model that makes the existing model obsolete.? ? R.<br class="">Buckminster Fuller<br class="">-------------- next part --------------<br class="">An HTML attachment was scrubbed...<br class="">URL: <http://mail.python.org/pipermail/python-ideas/attachments/20171121/b26ce033/attachment-0001.html><br class=""><br class="">------------------------------<br class=""><br class="">Message: 3<br class="">Date: Tue, 21 Nov 2017 06:36:47 -0200<br class="">From: Bernardo Sulzbach <mafagafogigante@gmail.com><br class="">To: python-ideas@python.org<br class="">Subject: Re: [Python-ideas] Should Python have user-defined constants?<br class="">Message-ID: <0028cb32-78e6-783e-e5d1-fc266e24e9fd@gmail.com><br class="">Content-Type: text/plain; charset=utf-8; format=flowed<br class=""><br class="">This could also be useful if one eventually wanted to implement constant <br class="">optimizations in the interpreter as it would be possible to detect <br class="">constants when they are declared without any code analysis.<br class=""><br class="">This would be "constant" as in Java constants right? Referential <br class="">constants, so that if an object were mutable you would still be able to <br class="">change its internal state.<br class=""><br class="">-- <br class="">Bernardo Sulzbach<br class="">http://www.mafagafogigante.org/<br class="">mafagafogigante@gmail.com<br class=""><br class=""><br class="">------------------------------<br class=""><br class="">Message: 4<br class="">Date: Tue, 21 Nov 2017 11:54:37 +0300<br class="">From: Kirill Balunov <kirillbalunov@gmail.com><br class="">To: python-ideas@python.org<br class="">Subject: [Python-ideas] Star assignment in iterator way?<br class="">Message-ID:<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span><CABwCVQCODpAqkVR6DgvOD+dOP-YMUyqDmkXSc2NUG2ypgn2mKA@mail.gmail.com><br class="">Content-Type: text/plain; charset="utf-8"<br class=""><br class="">Hello. Currently during star assignement the new list is created.<br class="">What was the idea to produce new list instead of returning an iterator?<br class="">It seems to me that returning an iterator more suited to the spirit of<br class="">Python 3.<br class="">There are three cases:<br class=""><br class="">1. a,b,c,*d = something_iterable<br class="">2. *a,b,c,d = something_iterable<br class="">3. a,*b,c,d = something_iterable<br class=""><br class="">The first one is obvious. For the rest two we always need to iterate<br class="">through<br class="">entire iterable to achieve values for b,c,d (or c,d) binding. But this can<br class="">be done<br class="">more memory effiecient than currently (may be I'm wrong). And we can<br class="">iterate in<br class="">space of last three (or two) variables. Some rough (simplified) Python code:<br class=""><br class="">from itertools import islice, chain<br class="">from collections import deque<br class=""><br class="">def good_star_exp(signature, seq):<br class=""><br class=""> if signature.count('*') > 1:<br class=""> raise SyntaxError('two starred expressions in assignment')<br class=""><br class=""> vrs = signature.split(',')<br class=""> idx_max = len(vrs) - 1<br class=""> star_pos, = (i for i,v in enumerate(vrs) if '*' in v)<br class=""><br class=""> #First case<br class=""> if star_pos == idx_max:<br class=""> head = islice(seq, idx_max)<br class=""> tail = islice(seq, idx_max, None)<br class=""> return chain(head, (tail,))<br class=""><br class=""> #Second case<br class=""> elif star_pos == 0:<br class=""> tail = deque(maxlen=idx_max)<br class=""> for seq_idx_max, v in enumerate(seq):<br class=""> tail.append(v)<br class=""> head = islice(seq, 0, seq_idx_max-(idx_max-1))<br class=""> return chain([head], tail)<br class=""><br class=""> #Third case<br class=""> else:<br class=""> head = islice(seq, star_pos)<br class=""> tail = deque(maxlen=(idx_max-star_pos))<br class=""> for seq_idx_max, v in enumerate(seq):<br class=""> tail.append(v)<br class=""> mid = islice(seq, star_pos, seq_idx_max-(idx_max-2))<br class=""> return chain(head, [mid], tail)<br class=""><br class="">ls = range(100000)<br class="">a,b,c,d = good_star_exp('a,b,c,*d', ls)<br class="">a,b,c,d = good_star_exp('*a,b,c,d', ls)<br class="">a,b,c,d = good_star_exp('a,*b,c,d', ls)<br class=""><br class="">Of course this version has drawbacks (the first that come to mind):<br class="">1. Will *b see change if rhs is some muttable sequence?<br class="">2. Will *b one way iterator or somethong like range?<br class=""><br class="">But still it seems to me that the "iterator way" has more useful<br class="">applications.<br class=""><br class="">With best regards, -gdg<br class="">-------------- next part --------------<br class="">An HTML attachment was scrubbed...<br class="">URL: <http://mail.python.org/pipermail/python-ideas/attachments/20171121/f2819697/attachment-0001.html><br class=""><br class="">------------------------------<br class=""><br class="">Message: 5<br class="">Date: Tue, 21 Nov 2017 11:07:58 +0200<br class="">From: Serhiy Storchaka <storchaka@gmail.com><br class="">To: python-ideas@python.org<br class="">Subject: Re: [Python-ideas] Star assignment in iterator way?<br class="">Message-ID: <ov0qd6$v12$1@blaine.gmane.org><br class="">Content-Type: text/plain; charset=utf-8; format=flowed<br class=""><br class="">21.11.17 10:54, Kirill Balunov ????:<br class=""><blockquote type="cite" class="">Of course this version has drawbacks (the first that come to mind):<br class="">1. Will *b see change if rhs is some muttable sequence?<br class="">2. Will *b one way iterator or somethong like range?<br class=""><br class="">But still it seems to me that the "iterator way" has more useful <br class="">applications.<br class=""></blockquote><br class="">Your implementation iterates seq multiple times. But iterable unpacking <br class="">syntax works with an arbitrary iterable, and iterates it only once.<br class=""><br class="">Changing the result of iterable unpacking will break existing code that <br class="">depends on the result been a list.<br class=""><br class="">And you already have mentioned a question about mutable sequence.<br class=""><br class="">If these conditions and restrictions suit you, you can use your <br class="">good_star_exp() in your code or share it with others. But the semantic <br class="">of iterable unpacking can't be changed.<br class=""><br class=""><br class=""><br class="">------------------------------<br class=""><br class="">Subject: Digest Footer<br class=""><br class="">_______________________________________________<br class="">Python-ideas mailing list<br class="">Python-ideas@python.org<br class="">https://mail.python.org/mailman/listinfo/python-ideas<br class=""><br class=""><br class="">------------------------------<br class=""><br class="">End of Python-ideas Digest, Vol 132, Issue 112<br class="">**********************************************<br class=""></div></div></blockquote></div><br class=""></body></html>