Arc Forumnew | comments | leaders | submitlogin
1 point by evanrmurphy 5068 days ago | link | parent

How about id for is and is for iso? :)

Update: After reading over the ancestor comments more carefully, I guess this wouldn't address akkartik's concern. Nonetheless, I kind of like id.

> "Isomorphic," "equivalent," "similar," and maybe even "congruent" could work

Also keep in mind the words "alike", "same" and "exact".



4 points by akkartik 5068 days ago | link

id could also mean the mathematical identity function, which arc calls idfn probably because it's a lisp-1 and we want to be able to create locals called id.

Hmm, how about if id was a low-level beast that converted any object into a say ptr type that contained its address. Now instead of (is a b) you'd say:

  (iso id.a id.b)
That seems to me about the right level of verbosity for doing the things is does that iso can't do.

-----

2 points by rocketnia 5068 days ago | link

I agree with that! :)

In Java, everything uses equals() where it can, but then it's not easy to get == behavior when it matters. Technically you can use a wrapper:

  public final class Id
  {
      private Object x;
      public Id( Object x ) { this.x = x; }
      
      public int hashCode() { return System.identityHashCode( x ); }
      public boolean equals( Object obj )
          { return obj instanceof Id && ((Id)obj).x == x; }
  }
I'm digressing, but it would be so much nicer if every object kept a hard reference to its Id wrapper. That way the Id could be used as a WeakHashMap key.[1] Weak tables are one place where comparing keys for anything but reference identity makes no sense. XD

Back in terms of (iso id.a id.b), this would have the observable effect that (iso id.id.a id.id.a) would be true for all a.

[1] Thanks to the hard reference to the Id from its x, the Id itself wouldn't be collected until its x was unreachable too. A Id without such an anchor would potentially be garbage-collected much earlier than its x, and the WeakHashMap entry would be lost. ...Anyway, some of this could be solved by changing the design of WeakHashMap. :)

-----

1 point by evanrmurphy 5068 days ago | link

I like this! Would the id of a primitive just return itself?

  id.4 ; evaluates to 4 or the address where this 4 is stored?

-----

3 points by akkartik 5068 days ago | link

I think all we need is that it be a stable value when literal objects are interned. So id.4 would probably never change, and (id "a") would change in common lisp because it creates new strings each time.

-----

1 point by rocketnia 5068 days ago | link

The name "is" is just so perfect though. What we're talking about is the difference between "the same regardless of who and why you ask" and "the same if you ask the type designer." When I see something like "is" that plainly communicates sameness, I assume it's the no-matter-what version. On the other hand, saying things are "similar" doesn't entail they're identical; they might only be identical enough.

I do like "alike." It's short, and it suggests it has something to say about non-identical arguments. It's better than "like," because (like x y) could be interpreted as "x likes y" or "cause x to like y."

-----

1 point by akkartik 5068 days ago | link

"The name 'is' is just so perfect though."

To stretch my analogy to breaking point, that's like saying I wish we could build a hundred yards into the ocean, it would make such fine waterfront property :) Some things are 'prime' but not real estate.

Ok that is probably not clear. I think I'd use is or iso, but not both.[1] iso is perfect because it is short and precise and conjures up the right image. I'll probably never find a use for is. That's ok. Good names minimize cognitive overhead, but there's still some overhead. The best name is the one you don't need, and there's enough good names that we don't have to microoptimize.

---

I'm not sure which variant is "the same regardless of who and why you ask". In common lisp there's 30 years of rationalizations why this is 'intuitive':

  * (eq "a" "a")
  nil
Yet arc chose otherwise:

  arc> (is "a" "a")
  t
So clearly it's not "the same regardless of who you ask".

If you created syntax for hash-table literals you may want this to be true:

  (is {a: 0} {a: 0})
So the semantics of is are actually quite fungible. If pointer equality is a low level beast that requires knowing internal details let's not put it on a pedestal and give it a prime name.

(Again I'm less certain than I seem.)

[1] I think isa is fine though it's so similar in form because it's different enough from iso in behavior.

-----

1 point by rocketnia 5068 days ago | link

I'm not sure which variant is "the same regardless of who and why you ask".

By "the same regardless of who and why you ask," I mean something at least as picky as "the same regardless of what algorithm you try to use to distinguish them." Notice that the pickiest equality operator in a language is the only one that can satisfy that description; any pickier one would be an algorithm (well, a black-box algorithm) that acted as a counterexample.

I think 'eqv? is this operator in standard Scheme and 'eq? is this operator in any given Scheme implementation (but I dunno, maybe it's more hackish than that in practice). Meanwhile, I think 'is acts as this operator in a "standard" subset of Arc in which strings are considered immutable. (A destructive algorithm can distinguish nonempty mutable strings.) I avoid string mutation in Arc for exactly this reason.

---

So the semantics of is are actually quite fungible.

Yeah, especially once you get down to a certain point where nothing but 'is itself would allow you to compare things, then 'is is free to be however picky it wants to be. A minimally picky 'is would solve the halting problem when applied to closures, so something has to give. :)

The least arbitrary choice is to leave out 'is altogether for certain types, like Haskell does, but I dunno, for some reason I'm willing to sacrifice things like string mutation to keep 'is around. I mean, I think it's for the sake of things like cyclic data structures, uninterned symbols, and weak references, but I don't think those things need every type to have 'is.... Interesting. I might be changing my mind on this. ^_^

-----