[plt-scheme] macros, special forms, and lazy functions

From: Nadeem Abdul Hamid (nadeem at acm.org)
Date: Sat Dec 12 11:06:44 EST 2009

On Dec 11, 2009, at 11:40 PM, Stephen Bloch wrote:

> The classroom use-case I'm thinking of is "I assign a bunch of  
> functions on lists, which can be written from scratch using  
> recursion, or more briefly using standard higher-order functions  
> like map, filter, foldr and foldl, etc."
> The following problems would fit naturally into this use-case, and  
> they have obvious definitions, but the fact that "and" and "or" are  
> special forms means that the obvious definitions don't pass a syntax  
> check.
> 1) "any-true? : list-of-Boolean -> Boolean": the obvious definition  
> is "(foldr false or ...)".
> 2) "all-true? : list-of-Boolean -> Boolean": the obvious definition  
> is "(foldr true and ...)".
> 3) "bitwise-and : list-of-Boolean list-of-Boolean -> list-of- 
> Boolean": the obvious definition is "(map and ...)"
> In all these cases, short-circuit evaluation is irrelevant because  
> the assigned function takes in a list, and "list" is a true function  
> so all the Booleans must obviously be evaluated before there is even  
> an argument to give to the assigned function.

Isn't this why there are "ormap" and "andmap" -- essentially  
specializations of foldr for and and or? Maybe students wouldn't  
realize why they are provided separately, but I think they easily  
recognize when to use them.

--- nadeem

Posted on the users mailing list.