[plt-scheme] puzzled about multiple value return

From: John Clements (clements at brinckerhoff.org)
Date: Fri Feb 3 14:12:51 EST 2006

On Feb 3, 2006, at 11:07 AM, John Clements wrote:

>
> On Feb 3, 2006, at 10:56 AM, pedro pinto wrote:
>
>> hi there,
>>
>> I have a little helper function that does something like this:
>>
>> (define (helper thunk)
>>   (setup)
>>   (let ((result (thunk))
>>      (teardown)
>>       result))
>>
>> Meaning my helper wraps a call to a thunk with some setup/teardown  
>> actions and returns whatever thunk returned. If thunk raises an  
>> error however, I do not want for teardown to be called.
>

> Urk.  How about something like this:
>
> (define (setup) 3)
> (define (teardown) 4)
>
> (define (helper thunk)
>   (setup)
>   (let ([results (call-with-values thunk list)])
>     (teardown)
>     (apply values results)))
>
> (helper (lambda () (values 1 2 3)))

P.S.: Note that my code does not explicitly refer to exceptions or  
errors, but it naturally has the behavior you want.  That is, if an  
error occurs, then teardown will not be called.

John

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2430 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20060203/3dd31368/attachment.p7s>

Posted on the users mailing list.