Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Not 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 [(])


> 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: