[plt-scheme] define-union

From: Stephen Bloch (sbloch at adelphi.edu)
Date: Sat Apr 19 08:22:20 EDT 2003

>On Fri, 18 Apr 2003, Anton van Straaten wrote:
>>  How about modifying your spec slightly to allow this:
>>	(define-union snark? (foo? bar? number?))
>>  ...which would allow you to use this:
>>	(define-syntax define-union
>>	  (syntax-rules ()
>>	    ((_ name (pred ...))
>>	     (define (name x) (or (pred x) ...)))))
>  > ...which has the virtue of being very simple to implement and understand.

At 9:43 PM -0500 4/18/03, Jacob Matthews wrote:
>If you modify the spec just a little more, you don't need a macro at all.
>You just need to be willing to use regular define rather than introducing
>the new keyword define-union.
>(define (union . predicates)
>   (lambda (item) (ormap (lambda (f) (f item)) predicates)))
>(define snark? (union foo? bar? number?))

Yes, I could easily have written either of those.  But the goal is to 
give students with six weeks of programming experience something as 
closely analogous as possible to define-struct.  The fact that it 
defines snark? as the disjunction of foo?, bar?, and number? is 
almost incidental; that's just the only useful task I could think of 
it doing, analogous to define-struct defining a constructor, access 
functions, and a type predicate.

At 8:59 PM -0500 4/18/03, Robby Findler wrote:
>FWIW, Matthew, Shriram, Matthias and I've been tossing around ideas
>like that in private and I believe that we now know how to turn data
>definitions and contracts of into checkable artifacts (Ie, the computer
>understands and enforces them rather than just being commented out
>stuff), without having to introduce any new cognative barriers (types
>systems or static analyses or anything like that). Of course, this kind
>of a change requires massive changes to the book to support it so we've
>not yet really started to talk about it too seriously. (plus, there are
>two competing proposals that we will have to meet and talk about).

I'd be interested in being included in these discussions.

				Steve Bloch

Posted on the users mailing list.