For Programmers: Free Programming Magazines  


Home > Archive > Scheme > February 2005 > serialization - question ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author serialization - question ?
Surendra Singhi

2005-01-30, 8:57 pm

Hello,
I was reading the structure & interpretation of computer program book.
I have a doubt in exercise 3.42 question. What is the difference between
these two pieces of code?

(let ((protected (make-serializer)))
(define (dispatch m)
(cond ((eq? m 'withdraw) (protected withdraw))
(cond ((eq? m 'deposit) (protected deposit))
.......
vs.

(let ((protected (make-serializer))
(let ((protected-withdraw (protected withdraw))
(protected-deposit (protected deposit)))
(define (dispatch m)
(cond ((eq? m 'withdraw) (protected-withdraw))
(cond ((eq? m 'deposit) (protected-deposit))
......

N.P. - the brackets may not be properly matched but the indentation is
correct.

My first impression is that both the code will do the same thing as they
both are going to serialize calls to "withdraw" and "deposit"
But because it is asked as an exercise question there must be something
more interesting than that.
Can anyone help?

Thanks.

--
Surendra Singhi

www.public.asu.edu/~sksinghi/
Arne Ruhnau

2005-02-01, 8:58 pm

Surendra Singhi wrote:
> My first impression is that both the code will do the same thing as

they
> both are going to serialize calls to "withdraw" and "deposit"
> But because it is asked as an exercise question there must be something
> more interesting than that.
> Can anyone help?


If I am not completely mistaken, the difference is that in the first
case, each time you dispatch your message you apply protected. In the
second, however, this application is only done once inside the inner let.

hth,

Arne Ruhnau
Surendra Singhi

2005-02-03, 4:00 am

Arne Ruhnau wrote:
> Surendra Singhi wrote:
>
>
>
> If I am not completely mistaken, the difference is that in the first
> case, each time you dispatch your message you apply protected. In the
> second, however, this application is only done once inside the inner let.
>


In the second case isn't protected-withdraw/dispatch a function call and
so doesn't it applies protected?

I am putting the code snippet once again for easy reference.



(let ((protected (make-serializer)))
(define (dispatch m)
(cond ((eq? m 'withdraw) (protected withdraw))
(cond ((eq? m 'deposit) (protected deposit))
.......
vs.

(let ((protected (make-serializer))
(let ((protected-withdraw (protected withdraw))
(protected-deposit (protected deposit)))
(define (dispatch m)
(cond ((eq? m 'withdraw) (protected-withdraw))
(cond ((eq? m 'deposit) (protected-deposit))
......




--
Surendra Singhi

www.public.asu.edu/~sksinghi/
Arne Ruhnau

2005-02-03, 8:59 pm

Surendra Singhi wrote:
> Arne Ruhnau wrote:
>
> In the second case isn't protected-withdraw/dispatch a function call and
> so doesn't it applies protected?


Well, yes, protected-withdraw and protected-deposit are both function
calls, but the application of protected is achieved only once inside the
inner let. In the first case, protected is applied on every dispatch,
but in the second only once (inside let).

> (let ((protected (make-serializer)))
> (define (dispatch m)
> (cond ((eq? m 'withdraw) (protected withdraw))
> (cond ((eq? m 'deposit) (protected deposit))
> ......
> vs.
>
> (let ((protected (make-serializer))
> (let ((protected-withdraw (protected withdraw))
> (protected-deposit (protected deposit)))
> (define (dispatch m)
> (cond ((eq? m 'withdraw) (protected-withdraw))
> (cond ((eq? m 'deposit) (protected-deposit))
> .....

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com