Re: behavior of CASE with strings

[email protected]
Newsgroups gmane.lisp.scheme.bigloo
Organization Inria
Message-ID <2017116143211.587ccb5b__15854.7248029665$1484573831$gmane$org@redrock.inria.fr>
Hi Damien,

Bigloo complies with the R5RS specification (see section 4.2) that says:

-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----
case <key> <clause1> <clause2> ...,	library syntax
Syntax: <Key> may be any expression. Each <clause> should have the form

((<datum1> ...,) <expression1> <expression2> ...,),

where each <datum> is an external representation of some object. All the <datum>s must be distinct. The last <clause> may be an ``else clause,'' which has the form

(else <expression1> <expression2> ...,).

Semantics: A case expression is evaluated as follows. <Key> is evaluated and its result is compared against each <datum>. If the result of evaluating <key> is equivalent (in the sense of eqv?; see section Equivalence predicates) to a <datum>, then the expressions in the corresponding <clause> are evaluated from left to right and the result(s) of the last expression in the <clause> is(are) returned as the result(s) of the case expression. If the result of evaluating <key> is different from every <datum>, then if there is an else clause its expressions are evaluated and the result(s) of the last is(are) the result(s) of the case expression; otherwise the result of the case expression is unspecified.

(case (* 2 3)
  ((2 3 5 7) 'prime)
  ((1 4 6 8 9) 'composite))            =>  composite
(case (car '(c d))
  ((a) 'a)
  ((b) 'b))                            =>  unspecified
(case (car '(c d))
  ((a e i o u) 'vowel)
  ((w y) 'semivowel)
  (else 'consonant))                   =>  consonant
-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----

You can observe that with:

(pp (expand '(case x (("foo") 1) (("bar" ) 2))))
=>
(let ((case-value x))
  (if (eqv? case-value '"foo")
    1
    (if (eqv? case-value '"bar") 2 #unspecified)))

Cheers,

-- 
Manuel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.