"Like" types

Brendan Eich brendan at mozilla.org
Fri Oct 26 17:53:39 PDT 2007

On Oct 26, 2007, at 5:11 PM, James Clark wrote:

> Calling the second relationship "like" seems strange to me.  An  
> object that stands in the strong relationship to a type is just as  
> like the type as an object that stands in the weak relationship.

The canonical term (both in theory and in real programming languages,  
e.g. C#) for the strong relation is "is", not "like".

See the overview generator example for a pretty combination of the two:

function fringe(tree) {
     if (tree is like {left:*, right:*}) {
         for (let leaf in fringe(tree.left))
             yield leaf
         for (let leaf in fringe(tree.right))
             yield leaf
         yield tree

Try it:

let tree = { left: { left: 37, right: 42 }, right: "foo" }
for ( let x in fringe(tree) )

It prints 37, 42, and "foo".

In Firefox 2, you can do exactly this example minus the is like test.  
Instead some ad-hoc property-detection is required. See attached.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20071026/e037f417/attachment-0002.html 

More information about the Es4-discuss mailing list