|
|
|
|
|
by such_a_casual
3788 days ago
|
|
I did not know C had static variables at the function level (thank you for pointing this out), but static variables are not the same thing as what I'm thinking of when I say "explicit scoping". It would basically be like writing curly braces for variable declarations the same way one does with function definitions. Because lisp has this it's trivial to extend the scope of the variable to cover multiple functions: (let ((x))
(defun func1 ())
(defun func2 ()))
This is what I mean when I say explicit scoping. And it means that the reader/debugger/maintainer knows that this variable only exists for these functions. A static variable's scope is implied by the scope of whatever it's defined in (not sure if that's limited to functions in C), in this case X exists outside of C and has it's own scope, not just it's own extent. |
|
Yes, I mentioned that static variables in a function would not extend to multiple functions.
You can share a variable between a restricted set of top level functions by grouping those functions in a single object file that does not expose the variable in question.
I think my only objection is that your phrasing implied what's different is the explicitness of the scoping, when it's actually the flexibility of how functions can be defined (unsurprising, from a lisp).