4 ms·
#undef isn't impure. It isn't an assignment, but an unbinding; it asserts that in the remainder of the translation unit, the preprocessor symbol is not known. T
by kazinator 8y ago
#undef isn't impure. It isn't an assignment, but an unbinding; it asserts that in the remainder of the translation unit, the preprocessor symbol is not known. That symbol's status in the prior parts of the translation unit hasn't changed.
Consider that lambda or let will also unbind:
(let ((x 3)) ; #define x 3
) ; #undef x, effectively
- earenndil 8y agoNot really, because in your lisp example, there is proper scoping. Variables will always be unbound in the reverse order they were bound. You can do something like this in c: #define x 3 #define y 4 #undef x // more stuff #undef y Which is essentially equivalent to [(])
- deleted 8y ago[deleted]
- kazinator 8y ago> there is proper scoping Rather, there is nesting. Nesting isn't the same thing as scoping. > Variables will always be unbound in the reverse order they were bound. Counterexample: (let* ((x 1) (y (* 2 x)) (z (+ x y))) ;; bound in sequence ) ;; unbound in parallel We could have an unlet operator which introduces a new scope that explicitly removes a binding: (let (x) ; #define x (let (y) ; #define y (unlet (x) ; #undef x ;; y bound, x free ))) ; #undef y, #undef x Basically, #define and #undef can be regarded as having proper nesting: each one creates a new scope that lasts unti the end of the translation unit, nested relative to the previous scope.