First Class Citizen

A first-class citizen definition found in a wiki article says:

An object is second to none if it

  • can be stored in variables and data structures
  • can be passed as a parameter to a subroutine
  • can be returned as a result of a subroutine
  • can build at runtime
  • has internal identity (regardless of any name)

Can someone explain / clarify the fifth requirement (in bold)? I believe that the article should have provided more detailed information on how “internal identity” captures it.

Perhaps we could use functions in Javascript and functions in C in our discussion to illustrate the 5th bullet.

I believe that functions in C are secondary, while functions are first-class in Javascript, because in Javascript we can do something like the following:

var foo = function () { console.log("Hello world"); }; 

which is unacceptable in C.

Again, my question is really on the 5th armor (requirement).

+4
source share
1 answer

Internal identity is quite simple, conceptually. If a thing has this, its personality does not depend on anything external. It may be a pseudonym, link, rename, something-you, but it still supports everything that is "identity." People (most of them, anyway) have an internal identity. You are you, regardless of your name or where you live, or what physical transformations you may have suffered in life.

On the other hand, an electron does not have its own identity. Perhaps introducing quantum mechanics here just confuses the problem, but I think this is a really fantastic example. There is no way to “tag” or “stick” an electron in such a way that we can separate it from a neighbor. If you replace one electron with another, there is no way to distinguish the old from the new.

Return to computers: an example of "internal identification" can be the value returned by Object#hashCode() in Java or some JavaScript engine uses a engine, which allows this statement to be false:

 {} === {} // false 

but this is true:

 function foo () {} var bar = foo; var baz = bar; baz === foo; // true 
+6
source

Source: https://habr.com/ru/post/1489603/


All Articles