This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: behavior of CASE with strings PART 2




On 01/17/2017 02:07 AM, Damien MATTEI wrote:
testing with eqv? predicate (that seems to be used in kawa CASE if it follow R5RS) and according to https://www.gnu.org/software/kawa/Conditionals.html i have this:

|kawa:1|# (case "dog" (("cat" "dog" "mouse") "animal") (else "mineral or vegetable"))
animal

CASE *cannot* meaningfully be used with strings.

#|kawa:2|# (case (string-copy "dog") (("cat" "dog" "mouse") "animal") (else "mineral or vegetable"))
mineral or vegetable

The reason is that case tests use eqv?, and "The eqv? procedure returns #f if" ...
"obj 1 and obj 2 are pairs, vectors, bytevectors, records,
or strings that denote distinct locations. (quoting directly from R7RS).
R5RS is the same in this respect.

Thus (eqv? (string-copy "dog") "dog") is #f, as is (eqv? (string #\d #\o #\g) "dog").
Even (eqv? "dog" "dog") is *unspecified* according to R7RS, because it does not
require that the two "dog" literals are the same location.

It might be reasonable to add a warning, like Kawa does with lists:

#|kawa:8|# (case "dog" ((("cat") "dog" "mouse") "animal") (else "mineral or vegetable"))
/dev/stdin:8:15: warning - List and vectors will never be matched in a case clause
/dev/stdin:8:15: warning - datum type incompatible with the key

--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]