[plt-scheme] Use and abuse of contracts

From: David Herman (dherman at ccs.neu.edu)
Date: Wed Sep 29 00:04:56 EDT 2004

If you're interested in the connection between contracts and AOP, you 
might want to contact Theo Skottiniotis. I'm pretty sure he's currently 
working on that very topic. I'll send you his address privately.


On Tuesday, September 28, 2004, at 01:32 PM, Gordon Weakliem wrote:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> I saw a presentation last night that touched on the use of contracts 
> in PLT Scheme.  It occurred to me that you could use a contract to do 
> some AOP - like things, for example, to log method calls or to access 
> checking on a method (where only designated callers can call a 
> method).  For example, here's a definition of a silly function with a 
> contract that prints the value of its argument:
> (define/contract
>     ; fact is a function taking a number >= 0 and returning a number 
> >= 0
>     fact (-> (and/c (>=/c 1)
>                     (lambda (x)
>                       (printf "Fact called with ~A" 10)))
>                     (>=/c 1))
>     (lambda (n)
>       (let loop ((i n)
>                  (r 1))
>         (if (= i 0)
>             r
>             (loop (- i 1) (* r i))))))
> This seems like a potentially useful feature of contracts, but I'm 
> wondering if this amounts to abuse of a contract, or if this is within 
> the valid uses of this feature.  In production code that I've worked 
> on, there's generally a way to switch on logging of things like 
> parameter values, return types, SQL statements to be executed, etc.  
> It's nice to have a way to have that functionality without cluttering 
> up the code with logging statements.
> -- 
> Gordon Weakliem
> http://www.eighty-twenty.net

Posted on the users mailing list.