<div dir="ltr"><div>Actually if anything reminds me of Haskell it's a 'Maybe' type. :-(<br><br></div><div>But I do side with those who find '?' too ugly to consider.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 20, 2015 at 2:47 PM, David Mertz <span dir="ltr"><<a href="mailto:mertz@gnosis.cx" target="_blank">mertz@gnosis.cx</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">Paul Moore's idea is WAAYY better than the ugly ? pseudo-operator.  `maybe()` reads just like a regular function (because it is), and we don't need to go looking for Perl (nor Haskell) in some weird extra syntax that will confuse beginners.<div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Sun, Sep 20, 2015 at 4:05 AM, Paul Moore <span dir="ltr"><<a href="mailto:p.f.moore@gmail.com" target="_blank">p.f.moore@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>On 20 September 2015 at 08:31, Steven D'Aprano <<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>> wrote:<br>
> I'm not convinced that we should generalise this beyond the three<br>
> original examples of attribute access, item lookup and function call. I<br>
> think that applying ? to arbitrary operators is a case of "YAGNI". Or<br>
> perhaps, "You Shouldn't Need It".<br>
<br>
</span>Agreed.<br>
<br>
Does this need to be an operator? How about the following:<br>
<br>
    class Maybe:<br>
        def __getattr__(self, attr): return None<br>
        def __getitem__(self, idx): return None<br>
        def __call__(self, *args, **kw): return None<br>
<br>
    def maybe(obj):<br>
        return Maybe() if obj is None else obj<br>
<br>
    attr = maybe(obj).spam<br>
    elt = maybe(obj)[n]<br>
    result = maybe(callback)(args)<br>
<br>
The Maybe class could be hidden, and the Maybe() object a singleton<br>
(making my poor naming a non-issue :-)) and if it's felt sufficiently<br>
useful, the maybe() function could be a builtin.<br>
<br>
Usage of the result of maybe() outside of the above 3 contexts should<br>
simply be "not supported" - don't worry about trying to stop people<br>
doing weird things, just make it clear that the intent is only to<br>
support the 3 given idiomatic usages.<br>
<span><font color="#888888"><br>
Paul.<br>
</font></span><div><div>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div>Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons.  Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</font></span></div></div>
<br>_______________________________________________<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/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>