[erlang-questions] lists:all/2 unexpected result for the empty list

James Aimonetti james@REDACTED
Wed Jul 20 06:30:02 CEST 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thanks for the lesson. Both this reply and your other one in another
part of the thread were illuminating.

James

On 07/19/2011 07:44 PM, Richard O'Keefe wrote:
> 
> On 20/07/2011, at 10:16 AM, James Aimonetti wrote:
> 
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Was wondering the reasoning for lists:all/2 returning true when passed
>> an empty list as the second parameter?
>>
>> lists:all(some_fun/1, []) => 'true'
> 
> Because that's the way universal quantifiers are *SUPPOSED* to work.
> 
> lists:all(F, L) is true [assuming the types are right]
>  precisely when there is no element X of L such that F(X) is false.
> 
> Since [] has no elements, it cannot have any that would falsify some_fun.
> 
> It's just the same in Lisp:
> (EVERY predicate list...) returns false as soon as any invocation of predicate
> returns false. If the end of a sequence is reached, every returns true.
> Thus, every returns true if and only if every invocation of predicate returns true.
> 
> It's just the same in Smalltalk:
> 
> aSequence allSatisfy: [:x | some test on x]
> answers false if aSequence has some element falsifying the test,
> true otherwise, so #() allSatisfy: anything is true.
> 
> It's just the same in Haskell.
> 
> It's also just the same in mathematics, where
> 	(∀x∈∅) p(x)
> is required to be true.
> 
>> The definition in lists.erl for all/2 shows why it returns true:
> 
> No, the definition shows HOW it returns true, but not WHY.
> WHY is because all/2 is an iterated "and", and the identity
> for "and" is "true".
> 
> One of the major weaknesses in the Aristotelian syllogisms was
> the assumption that "all Xs are Ys" entailed there being at
> least one X.  The convention used in Erlang is that of modern
> logic.
> 
> In just the same way, existential quantifiers are supposed to return
> false if you quantify over an empty set, sums to return 0,
> products to return 1, and other such operations to return their
> identities.
> 
> 


- -- 
James Aimonetti
Distributed Systems Engineer / DJ MC_

2600hz | http://2600hz.com
sip:james@REDACTED
tel: 415.886.7905
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJOJlnJAAoJENc77s1OYoGgSdMH/iThr8LBQ0hf77tSusTDQXwS
J15GU8Om0DAEGAN5RzJ6rYHi6nfj0DQBh0X6a5B9I8qcsVqCIDrtcA8MAfhuj+Yw
Uis6hV+7GVQOuaCwAq5IjM+0XfjDXjXQjTbqPs+LDIBlodjLimP04oZ0uDyGExEo
YosMof99IAE6+EjMdgsqeCzQEoZHmWiKPS8y8nTRU6UnF4ucY8E/vM6mAZuSh+VY
DML6EC3YqDsWo+1aSxeVk122JBx+6zPEjPUTGvMQcJLbve5JmSLDLMvdmLZfsecy
oUsRW0JuckxaH0gVMVGtCy8Wz4GjZf/2TuOLyGudj2JwHCDutAbXbXd12qgbiZo=
=zo1J
-----END PGP SIGNATURE-----



More information about the erlang-questions mailing list