[racket] Case with strings: normal behavior?

From: Jon Zeppieri (zeppieri at gmail.com)
Date: Tue Nov 20 11:54:34 EST 2012

The obvious way to handle strings is to turn the constants into
symbols at expansion time, and dispatch on (string->symbol <input>),
just like we handle chars by turning them into fixnums and using
fixnum dispatch. After that, it's a question of whether you want case
to work for lists, vectors, syntactic hash tables, whatever else. For
my own part, those are better handled by `match.' (Well, maybe not
hash tables.)

On Tue, Nov 20, 2012 at 9:15 AM, Hendrik Boom <hendrik at topoi.pooq.com> wrote:
> On Tue, Nov 20, 2012 at 07:42:46AM -0600, Robby Findler wrote:
>> On Tue, Nov 20, 2012 at 12:14 AM, David T. Pierson <dtp at mindstory.com> wrote:
>> > On Mon, Nov 19, 2012 at 06:13:09AM -0700, Matthew Flatt wrote:
>> >> Should we change `case' to use `equal?' instead of `eqv?'? I can't
>> >> think of a good reason to stick with `eqv?'.
>> >
>> > My first reaction to this was that such a change would eliminate one of
>> > the motivations for using `case': getting the (perhaps insignificant?)
>> > performance improvement of using `eqv?' in a conditional when you know
>> > the key type is suitable for it.
>> >
>> > However it occurs to me that since the datums in a `case' clause are
>> > always literals, couldn't the expansion of `case' be "smart" enough to
>> > use the appropriate comparison function (eq?/eqv?/equal?) given the type
>> > of the datum?
>>
>> I think that equal? will always terminate quickly when its input is a
>> symbol/number/boolean so the macro doesn't need to do anything special
>> in that case.
>
> It could do a binary tree search on the data and use some kind of
> ordering comnparison.
>
> By the way, it's a long time since I saw 'datums' as plural of 'datum'.
> I wonder if it will become correct one of these years, since 'data' is
> often misused as singular, as a substance noun instead of an object
> noun.
>
> -- hendrik
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.