On Mon, 26 Nov 2001, Ocie Mitchell wrote:
> I have a question about the operation of the equal
> predicate. It seems to treat symbols and strings of
> the same name as equal:
>
> "+" dup intern equal .
Alternatively:
"+" [+] first equal .
"+" [+] first = .
> I.E. the operator + is equal to the string "+". Is
> this the intended behavior? Is there some sort of
> type coercion going on here?
The behaviour is not due to the equal predicate but
the = predicate. It comes about as follows:
To sort a list of items using (implicitly) the < ordering
predicate, that predicate has to be defined for all kinds
of items: numbers, strings and symbols.
[ 5 3 7 ] qsort => [ 3 5 7 ]
["peter" "paul" "mary"] qsort => ["mary" "paul" "peter"]
[ peter paul mary ] qsort => [ mary paul peter ]
That is fine for homogeneous lists, but what about
[ peter "paul" mary ] qsort => [ mary "paul" peter ]
Seems reasonable, too.
Now what about repetitions?
Solution 1 (the current one, string = symbol):
["peter" paul peter ] qsort => [ paul "peter" peter ]
[ peter paul "peter"] qsort => [ paul peter "peter"]
Solution 2 (any string < any symbol):
["peter" "paul" mary ] qsort => ["paul" "peter" mary ]
Solution 3 (any symbol < any string):
[ peter paul "mary"] qsort => [ paul peter "mary"]
Solution 4 (string < symbol):
[ peter "peter" peter ] qsort => [ "peter" peter peter]
Solution 5 (symbol < string):
["peter" peter "peter"] qsort => [ peter "peter" "peter"]
Maybe one of solutions 2..5 is better than solution 1, but
I don't know which. Any opinions?
Until this is settled, we can't really say how < and > should
behave in these circumstances. And clearly, whatever answer we
give, it also affects the <= and >= predicates, then the =
predicate and hence indirectly the equal predicate.
But thank you for pointing it out.
I have already seen your proposed patch, but I'll wait for
some discussion first.
- Manfred