chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] types.db incorrect


From: Jörg F . Wittenberger
Subject: Re: [Chicken-users] types.db incorrect
Date: 08 Sep 2011 13:01:23 +0200

On Sep 6 2011, Felix wrote:


What I would really have a use for was,
if
the assertions from types.db or whatever I pass with additional -types
parameters would be turned into runtime assertions (before call and
before
return) if, and only if, I pass a certain switch to the compiler.

Can you give an example of this? (a piece of code and how you would
like it to be transformed in the mode you are describing)

Easy enough:

(define (my-work-load a b) (values a 1 b))

And in types.db (that would be one private to the corresponding project):

(my-work-load (#(procedure #:clean #:enforce) my-work-load (fixnum fixnum) fixnum fixnum fixnum))

Now with the magic turned on the could expand to

(define (my-work-load a b)
; asserts come in by magic
(assert (fixnum? a))
(assert (fixnum b))
(receive (a b c)

  (values a 1 b)  ;  This is the only code I originally wrote!

 (assert (fixnum? a))
 (assert (fixnum? b))
 (assert (fixnum? c))
 (values a b c)))

So, the code would be wrapped by "contract verification" wrt. the types.db

The same could apply to the calling site.  With "types-enforces" instead
of simply compiling a call to my-work-load something like this could be
expanded:

(receive (a b c)
  (my-work-load
   (begin (assert (fixnum? p1)) p1)
   (begin (assert (fixnum? p2)) p2))
  (assert (fixnum? a))
  (assert (fixnum? b))
  (assert (fixnum? c))
  (values a b c))

Thus I could switch either site into debug mode.  When in this mode
I could be sure that successfully invoking a procedure means all parameters
have been checked.

/Jerry
........



reply via email to

[Prev in Thread] Current Thread [Next in Thread]