Re: [Scheme-reports] [r6rs-discuss] redefining eqv? Peter Kourzanov (22 Dec 2010 20:47 UTC)
Re: [Scheme-reports] [r6rs-discuss] redefining eqv? John Cowan (23 Dec 2010 01:49 UTC)
Re: [Scheme-reports] [r6rs-discuss] redefining eqv? Peter Kourzanov (23 Dec 2010 08:25 UTC)
Re: [r6rs-discuss] [Scheme-reports] redefining eqv? John Cowan (23 Dec 2010 09:13 UTC)
Re: [r6rs-discuss] [Scheme-reports] redefining eqv? Peter Kourzanov (23 Dec 2010 09:26 UTC)
(missing)
(missing)
(missing)
(missing)
(missing)
(missing)
(missing)
(missing)
(missing)
(missing)
(missing)
(missing)
(missing)
(missing)
(missing)
(missing)
(missing)
(missing)
Re: [r6rs-discuss] [Scheme-reports] redefining eqv? Peter Kourzanov (23 Dec 2010 09:28 UTC)
Re: [r6rs-discuss] [Scheme-reports] redefining eqv? Andre van Tonder (23 Dec 2010 15:11 UTC)
Re: [r6rs-discuss] [Scheme-reports] redefining eqv? John Cowan (24 Dec 2010 01:14 UTC)
Re: [r6rs-discuss] [Scheme-reports] redefining eqv? Eli Barzilay (24 Dec 2010 01:40 UTC)
Re: [Scheme-reports] [r6rs-discuss] redefining eqv? Peter Kourzanov (24 Dec 2010 08:55 UTC)
Re: [Scheme-reports] [r6rs-discuss] redefining eqv? John Cowan (24 Dec 2010 09:20 UTC)
Re: [Scheme-reports] [r6rs-discuss] redefining eqv? Peter Kourzanov (24 Dec 2010 09:26 UTC)
Re: [r6rs-discuss] [Scheme-reports] redefining eqv? John Cowan (25 Dec 2010 00:32 UTC)
Re: [r6rs-discuss] [Scheme-reports] redefining eqv? Adrien "Pied" Piérard (24 Dec 2010 11:51 UTC)
Re: [Scheme-reports] [r6rs-discuss] redefining eqv? Peter Kourzanov (24 Dec 2010 12:49 UTC)
Re: [Scheme-reports] [r6rs-discuss] redefining eqv? Eli Barzilay (24 Dec 2010 16:04 UTC)
Re: [Scheme-reports] [r6rs-discuss] redefining eqv? Andre van Tonder (24 Dec 2010 18:33 UTC)
Re: [r6rs-discuss] [Scheme-reports] redefining eqv? Adrien "Pied" Piérard (27 Dec 2010 01:59 UTC)
Re: [Scheme-reports] [r6rs-discuss] redefining eqv? John Cowan (27 Dec 2010 05:51 UTC)
Re: [r6rs-discuss] [Scheme-reports] redefining eqv? Adrien "Pied" Piérard (27 Dec 2010 06:22 UTC)
Re: [Scheme-reports] [r6rs-discuss] case reborn Peter Kourzanov (27 Dec 2010 09:55 UTC)
Re: [Scheme-reports] [r6rs-discuss] do we need to redefine eqv? Peter Kourzanov (29 Dec 2010 12:54 UTC)
Re: [Scheme-reports] [r6rs-discuss] redefining eqv? Peter Kourzanov (24 Dec 2010 12:24 UTC)
Re: [Scheme-reports] [r6rs-discuss] redefining eqv? Eli Barzilay (24 Dec 2010 16:02 UTC)
Re: [Scheme-reports] [r6rs-discuss] redefining eqv? Peter Kourzanov (24 Dec 2010 18:17 UTC)
Re: [Scheme-reports] [r6rs-discuss] redefining eqv? Andre van Tonder (24 Dec 2010 18:44 UTC)
Re: [Scheme-reports] [r6rs-discuss] redefining eqv? Andre van Tonder (24 Dec 2010 18:40 UTC)
Re: [r6rs-discuss] [Scheme-reports] redefining eqv? Peter Kourzanov (24 Dec 2010 20:07 UTC)
Re: [Scheme-reports] [r6rs-discuss] redefining eqv? John Cowan (24 Dec 2010 20:40 UTC)
Re: [Scheme-reports] [r6rs-discuss] redefining eqv? Peter Kourzanov (24 Dec 2010 22:11 UTC)
Re: [r6rs-discuss] [Scheme-reports] redefining eqv? Shiro Kawai (24 Dec 2010 22:27 UTC)
Re: [Scheme-reports] [r6rs-discuss] redefining eqv? Peter Kourzanov (25 Dec 2010 00:48 UTC)
Re: [r6rs-discuss] [Scheme-reports] redefining eqv? John Cowan (25 Dec 2010 00:29 UTC)

Re: [Scheme-reports] [r6rs-discuss] do we need to redefine eqv? Peter Kourzanov 29 Dec 2010 12:52 UTC

On Fri, 2010-12-24 at 13:32 -0500, Andre van Tonder wrote:

> I think one of the principal ways CASE was originally intended to be used
> was for fast dispatch on symbols or possibly numbers used as typetags in
> objects represented as lists, e.g.,
>
>    (case (car object)
>      ((node) .....)
>      ((leaf) .....))
>
> I believe there are some Schemes, like STALIN, that highly optimize such
> CASE expressions.  This would be harder to do in a higher-order CASE.

Well, my use-case was more like the following

(case object
(((node1 ,x ,y) (node2 ,x ,y)) (recur x y))
(((leaf ,x)) (recur x)))

(or, more readable)

(case object
| (node1 ,x ,y) | (node2 ,x ,y) => (recur x y)
| (leaf ,x) => (recur x))

(so, eqv? here being expanded to include user-specified semantics
and data-types)

which should translate, modulo destructuring bindings of course,
to exact same sequence of EQV? comparisons. Bindings would be moved
inside switch arms, and dispatch would reduce to trying EQV? on each
tag, just like with original CASE.

If STALIN could do a switch on a constant symbol value before, what
prevents it from doing the same here?

P.S. Actually, I have tried the following program with STALIN, but
couldn't find any switch on symbol value in the C output.
Defunctionalized for-each calls for 3 cases though do all look like
pretty well optimized, so I think the final assembly would look quite
similar...

(define foo1
   (lambda (x)
      (case x
((a b) 1000)
((c d) 2000)
(else 3000))))
(define foo2
   (lambda (x)
      (cond
((or (eqv? x 'a)
      (eqv? x 'b)) 1001)
((or (eqv? x 'c)
      (eqv? x 'd)) 2002)
(else 3003))))
(define foo3
   (lambda (x)
      (if (or (eqv? x 'a)
      (eqv? x 'b))
  1010
  (if (or (eqv? x 'c)
      (eqv? x 'd))
      2020
      3030))))

(for-each (lambda (x) (write (foo1 x))(newline)) '(a d e))
(for-each (lambda (x) (write (foo2 x))(newline)) '(a d e))
(for-each (lambda (x) (write (foo3 x))(newline)) '(a d e))

_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports