Arc Forumnew | comments | leaders | submitlogin
Is, lists, and strings
8 points by eekee 5954 days ago | 6 comments
Hi all, I just 'discovered' Arc today & have been reading up on it; I'm quite surprised with how closely it aligns with my way of thinking, given my lack of experience. :)

Anyway, I got the impression that pretty-much anything you could do to a list, you could also do to a string. I was puzzled, then, when I came across this in tut.txt:

+------------ The standard comparison operator is is, which returns true if its arguments are identical or, if strings, have the same characters.

[snip examples]

Note that is returns false for two lists with the same elements. There's another operator for that, iso (from isomorphic). +------------

Why the difference?



6 points by drcode 5954 days ago | link

No good reason I know of... The "is" roughly maps to comparators in other Lisps that are designed for "near constant time" comparisons, which is possible for symbols and numbers.

Strings may have gotten grandfathered into this behavior because they were thought of as similar to symbols.

Another possibility is that a Lisp string implementations could, in theory, use pre-computed hashes for comparisons, which WOULD allow near-constant comparisons, while slowing other operations.

-----

6 points by skenney26 5954 days ago | link

Great question. According to the comments in ac.scm PG is wondering the same thing:

  "do we really want is to ret t for distinct strings?"

-----

1 point by bOR_ 5953 days ago | link

Ah.. but here PG is wondering into the opposite direction of what eekee is, if I understand correctly.. PG seems to be favoring the following distinction:

is .. checks if a is the same thing as b (like pointers referring to the same address in memory).

iso .. checks if the content at whatever a is pointing at is the same as whatever b is pointing at.

which is now violated by strings. I am not sure how numbers fit into this. In general I would favor the more commonly used 'has the same content as' to be is, and 'refers to the same entity' to be iso for brevity reasons.

-----

2 points by oconnor0 5948 days ago | link

But isn't iso short for isomorphic which, as I understand it, is the same as "these two things are equivalent" - which maps much more closely to "has the same content as," not "refers to the same entity"?

-----

1 point by fallintothis 5953 days ago | link

Because it's the common case. http://arclanguage.org/item?id=334

Views differ, but personally I don't like to think of strings as aggregate collections of characters (but then, I also don't really like the character as a data-type), so using 'is seems conceptually simpler. It makes sense to me, as often as I bandy about strings and compare them, that 'is treats them as a simply-compared type. Granted, they are not. It's something I guess I've gotten used to by using symbols, as drcode points out (yay, link to a post in the same thread!): http://arclanguage.org/item?id=7965. To each their own.

-----

3 points by eekee 5953 days ago | link

Ah, I guess my bit-twiddling background is showing, because I don't like to think of strings as single entities. Symbols exist for that and are more efficient all-round, if I understand right.

-----