I’m going through the Structure and Interpretation of Computer Programs MIT video lecture series, and I had a quick question about returning side-effects from functions.
In video 3A, the professor writes a quick equation for for-each similar to this:
(define (for-each p l)
(if (null? l)
"done"
(p (car l)
(for-each p (cdr l)))))
Is there a specific convention for returning a side-effect from a function in Scheme, or was the "done" an arbitrary choice?
That’s not really a side effect, but rather that every Scheme function must return something. The string
"done"is something. Normally, when you callfor-eachyou might do something like:and ignore the return value from
for-each. The author could have just as easily chosen any other value to return from the base case.