Tilde Duck Typing

34 views
Skip to first unread message

Brother Bill

unread,
Jun 10, 2024, 6:57:14 PMJun 10
to Eiffel Users
It appears that ~ operator does duck typing.
a ~ b
If a and b are conforming in either direction, and have same shallow content, they are considered equivalent.
Please examine attachment and see if I am reading this correctly.
If so, ~ is a lot looser than = operator, which is subject to CATCALLs.
The = operator demands that a and b be of same type.
operators.zip

rfo amalasoft.com

unread,
Jun 10, 2024, 7:30:28 PMJun 10
to eiffel...@googlegroups.com
The '=' sign requires that they refer to the same object.

From: eiffel...@googlegroups.com <eiffel...@googlegroups.com> on behalf of Brother Bill <brother...@gmail.com>
Sent: Monday, June 10, 2024 6:57 PM
To: Eiffel Users <eiffel...@googlegroups.com>
Subject: [eiffel-users] Tilde Duck Typing
 
--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/9944a16c-1e4c-4b22-a27c-f3e2798e9aa2n%40googlegroups.com.

Brother Bill

unread,
Jun 10, 2024, 9:54:28 PMJun 10
to Eiffel Users
My bad.  I meant that "a.is_equal (b)" requires that a and b be of the same runtime type.

Ulrich Windl

unread,
Jun 11, 2024, 4:02:30 AMJun 11
to eiffel...@googlegroups.com
You mean = being true means that both objects are the same (not just equal)? Your wording is confusing.

javier...@gmail.com

unread,
Jun 11, 2024, 9:22:24 AMJun 11
to Eiffel Users

* 8.21.2 Syntax: Equality expressions 

Equality = Δ Expression Comparison Expression 
Comparison = Δ "=" | "/=" | "~" | "/~" 

* 8.21.3 Semantics: Equality Expression Semantics 

The Boolean_expression e ~ f has value true if and only if the values of e and f are both attached and such that e.is_equal (f) holds.
 The Boolean_expression e = f has value true if and only if the values of e and f are one of: 
            1 . Both void. 
            2 . Both attached to the same object with reference semantics.
            3. Both attached to objects with copy semantics, and such that e ~ f holds. 

Informative text 

The form with ~ always denotes object equality. 
The form with = denotes reference equality if applicable, otherwise object equality. Both rely, for object equality, on function is_equal — the version that can be redefined locally in any class to account for a programmer-defined notion of object equality adapted to the specific semantics of the class.  


-- Javier

Brother Bill

unread,
Jun 13, 2024, 10:46:32 AMJun 13
to Eiffel Users
Checking out ECMA standard 2006.  I'll nibble at it day by day.  The definitive reference.  I might learn something...
Reply all
Reply to author
Forward
0 new messages