Order of evaluation of function arguments From SICP:


  Exercise 3.8
  
  When we defined the
  evaluation model in section 1.1.3, we
  said that the first step in evaluating
  an expression is to evaluate its
  subexpressions. But we never specified
  the order in which the subexpressions
  should be evaluated (e.g., left to
  right or right to left). When we
  introduce assignment, the order in
  which the arguments to a procedure are
  evaluated can make a difference to the
  result. Define a simple procedure f
  such that evaluating (+ (f 0) (f 1))
  will return 0 if the arguments to +
  are evaluated from left to right but
  will return 1 if the arguments are
  evaluated from right to left.


I wrote this solution:

(define it false)
(define (f x)
  (if it
      it
      (begin (set! it (/ x 2)) it)))

(+ (f 1) (f 0))


Is there a better way?
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