From: Brian Harvey
Subject: Re: How does one return a value in Scheme/LISP...???
Date: 
Message-ID: <1mltud$8gf@agate.berkeley.edu>
I tried to send this response by mail, but:
<<< 550 <·······@cs.uiuc.edu>... User unknown


The simple answer is that the value returned by a procedure is the
value of the last expression in its body.  So you could say

(define (foo ...)
  ...
  (set! n ...)
  ...
  n)

But the more profound answer is that if you want to learn to program
in Lisp, you can't do it by translating from C in your head.  This
idea of carrying out a sequence of actions is anathema to a Lisp programmer.
Instead of saying

(define (foo ...)
  (if ... (set! n 1))
  (if ... (set! n 3))
  n)

the natural way to express this in Lisp would be

(define (foo ...)
  (cond (... 1)
        (... 3)))

without assigning any values to variables.  Whenever you use SET! the odds
are 99.5% that you're taking the wrong approach to the problem.


About your other question, a=(b==0), again, you could say (set! a (= b 0)) but
the odds are you wouldn't assign that value to a variable at all.