Re: Fwd: Re: behavior of CASE with strings PART 2

Bent Phillipsen <[email protected]>
Newsgroups gmane.lisp.scheme.bigloo
Message-ID <CAD1yAUQFD0oXTGTOa59vzsgqHQBZ2nm9pkG4g+8anM1ZOgYb5g@mail.gmail.com>
Hi Damien

Your macro might work on some implementations, but is not R5RS compliant.
Ellipses ("...") must always be the last item of a list or vector before
the closing ")", (unless the last item is a pair).

If you want a general solution, I think you should go for this:

(define-syntax case*
        (syntax-rules (else)
                ((case* (key ...)
                        clauses ...)
                 (let ((atom-key (key ...)))
                        (case* atom-key clauses ...)))
                ((case* key
                        (else result1 result2 ...))
                 (begin result1 result2 ...))
                ((case* key
                        ((atoms ...) result1 result2 ...))
                 (if (member key '(atoms ...))
                        (begin result1 result2 ...)))
                ((case* key
                        ((atoms ...) result1 result2 ...) clause clauses
...)
                 (if (member key '(atoms ...))
                        (begin result1 result2 ...)
                        (case* key clause clauses ...)))))


Best regards


Bent

2017-01-20 16:24 GMT+01:00 <[email protected]>:

> Hi Marc,
>
> Nice to see you here ;-)
>
> > Note that you can use symbols with the case construct.  In other words,
> these two expressions are equivalent if str is a string:
> >
> >  (cond ((string=? str "foo") 111)
> >        ((string=? str "bar") 222)
> >        (else                 333))
> >
> > and
> >
> >  (case (string->symbol str)
> >    ((foo) 111)
> >    ((bar) 222)
> >    (else  333))
> Agree with a minor warning. Although its probably not a problem in that
> particular situation but in my own programs I try to limit the use of
> symbols
> as much as possible as these objects are never collected.
>
> --
> 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.