public inbox for
 help / color / mirror / Atom feed
From: Per Bothner <>
Subject: Re: behavior of CASE with strings PART 2
Date: Tue, 17 Jan 2017 13:24:00 -0000	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

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 i have this:
> |kawa:1|# (case "dog" (("cat" "dog" "mouse") "animal") (else "mineral or vegetable"))

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

  reply	other threads:[~2017-01-17 13:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-17 10:07 Damien MATTEI
2017-01-17 13:24 ` Per Bothner [this message]
2017-01-17 15:57   ` Jamison Hope
2017-01-18  6:37     ` Per Bothner
2017-01-19  4:53       ` Per Bothner
2017-01-19 10:04         ` Damien MATTEI
2017-01-19 16:00           ` Per Bothner
2017-01-21  9:47         ` Damien Mattei
2017-01-22  4:36           ` match form as a generalization of case Per Bothner
2017-01-23 22:12             ` Damien Mattei
2017-01-23 22:27               ` Per Bothner
2017-01-20 22:54 behavior of CASE with strings PART 2 Damien Mattei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).