<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
On 02/04/2010 10:26 AM, Alessandro Dentella wrote:
<blockquote cite="mid:20100204092640.GA30574@ubuntu" type="cite">
<pre wrap="">Ciao,
(solo) oggi mi sono imbattuto in "0 in (False,)" che ha un comportamento
francamente controintuitivo:
In [1]: 0 in (False,)
Out[1]: True
che a sua volta dipende dal fatto che:
In [2]: 0 == False
Out[2]: True
</pre>
</blockquote>
<br>
Si', e' sempre stato cosi'. Anche prima che esistesse il tipo
"boolean", True e False erano interi.<br>
<br>
<br>
<blockquote cite="mid:20100204092640.GA30574@ubuntu" type="cite">
<pre wrap="">Mi viene qui di da chiedermi: ma che bisogno c'è che un booleano erediti da
un intero? piace a tutti che "0 == False" sia vero?
</pre>
</blockquote>
<br>
A me piace.<br>
<br>
Mi piace meno come si comporta javascript, dove <span
role="presentation" class="objectBox objectBox-text ">0 == false ma 0
!== false, quindi i tipi sono distinti, come preferisci tu.<br>
</span>Ma tutti gli oggetti sono true, anche l'oggetto false (*):<br>
<br>
<br>
<blockquote type="cite">
<div class="logRow logRow-command"><span role="presentation"
class="objectBox objectBox-text ">>>> 0</span></div>
<div class="logRow"><span role="presentation"
class="objectBox
objectBox-number ">0</span></div>
<div class="logRow logRow-command"><span role="presentation"
class="objectBox objectBox-text ">>>> Boolean(0)</span></div>
<div class="logRow"><span role="presentation"
class="objectBox objectBox-number ">false</span></div>
<div class="logRow
logRow-command"><span role="presentation"
class="objectBox
objectBox-text ">>>> Boolean(Boolean(0))</span></div>
<div class="logRow"><span role="presentation"
class="objectBox
objectBox-number ">false</span></div>
<div class="logRow logRow-command"><span role="presentation"
class="objectBox objectBox-text ">>>> new Boolean(0)</span></div>
<div class="logRow"><a
class="objectLink
objectLink-object a11yFocus "><span
class="objectTitle ">false </span><span role="presentation"
class="objectLeftBrace ">{</span><span class="objectRightBrace ">}</span></a></div>
<div class="logRow
logRow-command"><span role="presentation"
class="objectBox
objectBox-text ">>>> Boolean(new Boolean(0))</span></div>
<div class="logRow"><span role="presentation"
class="objectBox
objectBox-number ">true</span></div>
<div class="logRow logRow-command"><span role="presentation"
class="objectBox objectBox-text ">>>> new Boolean(new
Boolean(0))</span></div>
<div class="logRow"><a class="objectLink objectLink-object a11yFocus "><span
class="objectTitle
">true </span><span role="presentation"
class="objectLeftBrace ">{</span><span class="objectRightBrace ">}</span></a></div>
</blockquote>
<br>
<br>
<br>
<br>
<br>
(*) ovvero, l'oggetto che wrappa false. argh<br>
<br>
<pre class="moz-signature" cols="72">--
This e-mail (and any attachment(s)) is strictly confidential and for use only by intended recipient(s). Any use, distribution, reproduction or disclosure by any other person is strictly prohibited. The content of this e-mail does not constitute a commitment by the Company except where provided for in a written agreement between this e-mail addressee and the Company. If you are not an intended recipient(s), please notify the sender promptly and destroy this message and its attachments without reading or saving it in any manner. Any non authorized use of the content of this message constitutes a violation of the obligation to abstain from learning of the correspondence among other subjects, except for more serious offence, and exposes the person responsible to the relevant consequences.
</pre>
</body>
</html>