Path: utzoo!mnetor!uunet!husc6!hao!ames!rutgers!sdcsvax!ucbvax!IUVAX.CS.INDIANA.EDU!dyb From: dyb@IUVAX.CS.INDIANA.EDU (R. Kent Dybvig) Newsgroups: comp.lang.scheme Subject: Re: Why are case implementations so slow? Message-ID: <8712241957.AA11112@ucbvax.Berkeley.EDU> Date: 24 Dec 87 19:00:52 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The ARPA Internet Lines: 25 One reason is that the "natural" expansion of (case e0 ((k1 k2 ...) e1 e2 ...) ...) is (let ([tag e0]) (cond ((memv? tag '(k1 k2 ...)) e1 e2 ...) ...)) where "tag" does not occur free in e1 e2 .... This is surely slower than using the "equivalent" eq? tests when there is only one key per clause and that key is a symbol. The Chez Scheme expander looks for these special cases and expands them "appropriately", so you should find case as fast as cond. You could write your own case macro that does the same thing. However, it is not practical to turn case into a computed goto unless there are several keys within a relatively small range of fixnums or characters. It could be beneficial, certainly, but Chez Scheme doesn't bother, and I suspect that most other implementations don't either. R. Kent Dybvig | arpa: dyb@iuvax.cs.indiana.edu Computer Science Department | csnet: dyb@indiana Indiana University | usenet: ...!ihnp4!iuvax!dyb Bloomington, IN 47405 | phone: 812/335-6486