[plt-scheme] RE: to define, or to let

From: ifconfig (nslookupifconfig at hotmail.com)
Date: Tue Apr 13 05:08:12 EDT 2004

I have seen in this thread talk about knowing which function has and which
doesn't have side effects, and prohibiting use of side effects in
non-sequencing constructs! This is not wanted behavior, because of the
following case:

Say we have these functions:

(define (a num)
  (display "a has been called\n")
  (/ num 1))
(define (b num)
  (display "b has been called\n")
  (- num 1))
(define (golden? num)
  (let ([x (a num)]
        [y (b num)])
    (if (= x y)
        (begin (display "Golden cut!\n")
        (begin (display "Not golden cut!\n")

This is a simple procedure that checks whether a number is the golden cut
(1.618033..., a special number that 1/x = x-1). Note the (intentional) bug
on the last line. So I added debugging displays, so I would know where the
bug is. If side effects were prohibited, the let would not have been legal
because of side effects. That is obviously unwanted behavior!

This is just to demonstrate that side effects should and must not be


Posted on the users mailing list.