Order of evaluation of function arguments
Your code returns 1/2 if the (f 0) is evaluated first, not 0. A better way would be to return the last argument to f, with a default of 0.

(define last 0)
(define (f x)
  (define temporary last)
  (set! last x)
  temporary
)


When (+ (f 0) (f 1)) is evaluated with (f 0) first, execution is as follows:


f is called with 0
temporary is set to 0 (the default last)  
last is set to 0 (the argument to f)  
temporary (0) is returned
f is called with 1
temporary is set to 0
last is set to 1
temporary (0) is returned
0+0=0


If (f 1) is evaluated first, then execution is as follows:


f is called with 1
temporary is set to 0 (the default last)  
last is set to 1 (the argument to f)  
temporary (0) is returned
f is called with 0
temporary is set to 1
last is set to 0
temporary (1) is returned
0+1=1