[plt-scheme] case-statement in mzscheme 3.99 and drscheme interaction

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Wed Nov 28 18:40:24 EST 2007

Hi everyone,


Minor issue: the following snippet:

;;;;;;;;;;;;;;
#lang scheme
(case 42
   [else #f])
;;;;;;;;;;;;;;

produces the following output in DrScheme 3.99:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Welcome to DrScheme, version 3.99.0.3-svn28nov2007 [3m].
Language: Module; memory limit: 128 megabytes.
42
#f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

We're seeing '42' because the case macro is force evaluation of the thing 
we're casing against by putting it in a BEGIN.  This looks a little weird 
when we run in the DrScheme interaction window since DrScheme tries to 
show the multiple expression values when there's a toplevel BEGIN.


Here's a proposed fix that uses LET instead to avoid the weirdness with 
the Interaction window:

#####################################################################

dyoo at kfisler-ra1:~/local/plt-svn-2$ svn diff collects/scheme/private/more-scheme.ss

Index: collects/scheme/private/more-scheme.ss
===================================================================
--- collects/scheme/private/more-scheme.ss	(revision 7852)
+++ collects/scheme/private/more-scheme.ss	(working copy)
@@ -23,7 +23,7 @@
  	((_ v)
  	 (syntax (begin v (void))))
  	((_ v (else e1 e2 ...))
-	 (syntax/loc x (begin v e1 e2 ...)))
+	 (syntax/loc x (let ([x v]) e1 e2 ...)))
  	((_ v ((k ...) e1 e2 ...))
  	 (syntax/loc x (if (case-test v (k ...)) (begin e1 e2 ...) 
(void))))
  	((_ v ((k ...) e1 e2 ...) c1 c2 ...)


#####################################################################

I hope this helps!


Posted on the users mailing list.