[racket] HtDP, andmap & ormap

From: David Van Horn (dvanhorn at ccs.neu.edu)
Date: Wed Oct 6 14:51:35 EDT 2010

On 10/4/10 9:59 PM, Bill Richter wrote:
> David, I didn't understand what your code was supposed to show.
> Why do you think that HtDP's ormap is different from Racket's ormap?

I think it's different because I can write a program that distinguishes 
the two:

    (ormap add1 (cons 0 empty))

This works fine in Racket: ormap returns the first non-false value 
produced by the function when applied to the elements of the list, if 
such an element exists; false otherwise.

In the student languages: ormap returns true if applying the predicate 
to some element produces true and false if applying the predicate to all 
elements produces false.

So in the student languages, this example blows up because the function 
add1 doesn't produce a boolean when applied to 0 -- it is not a predicate.

You wrote:
> My son's Racket Sudoku Solver extensively uses ormap to search a list,
> and if it finds a match, return something good, else return false
> http://schemecookbook.org/Cookbook/SudokuSolver.  I'm interested in
> know how HtDP recommends designing such programs.

The student language ormap won't help you here.  However, Racket's ormap 
will.  But that doesn't mean you should just give up, or import Racket's 
ormap -- you can design your own ormap that works like Racket's, and I 
told you how.


Posted on the users mailing list.