[plt-scheme] Use and abuse of contracts

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

I forgot to mention: for a discussion of AOP in the context of  
higher-order languages, you should check out David Tucker and Shriram  
Krishnamurthi's paper, "A Semantics for Pointcuts and Advice in  
Higher-Order Languages," which you can find here:

      
http://www.cs.brown.edu/~sk/Publications/Papers/Published/tk-ptcts-adv- 
ho-lang/

Dave

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.