[plt-scheme] Teaching Scheme

From: Eli Barzilay (eli at barzilay.org)
Date: Mon May 3 11:47:51 EDT 2010

On May  4, Samuel Williams wrote:
> Dear Eli,
> 
> Thanks for your insightful response and the encoded examples.
> 
> I'm starting to get the feeling that it isn't possible to print to
> stdout in Scheme? Is this the case?

No, you can use the `printf' function.  In the C-like version of my
code, the last expression

    (for/list ([(door i) (in-indexed (in-vector doors))] #:when door)
      (+ i 1))

collects the list of open doors -- and if you *really* want to make
that part be identical to the C code too, use this instead:

    (for ([(door i) (in-indexed (in-vector doors))])
      (printf "Door #~a is ~a.\n" (+ i 1) (if door "open" "closed" )))

But as several people said -- code that prints a list is much less
useful than code that returns a list.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!


Posted on the users mailing list.