- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
What it says in the title. Just trying to reconcile some strange behavior of some variables.
Solved! Go to Solution.
What it says in the title. Just trying to reconcile some strange behavior of some variables.
Solved! Go to Solution.
If you declare a variable as local then the lisp function you've defined will not consider the variable if defined from an outside source nor impact the value defined but will only use the variable as defined in the current lisp function.
For example:
(setq a "THEY" b "THEM" c "US")
(defun test (/ a b c)(setq a "1" b "2" c "3")(princ(strcat"\na is [" a "] and b is [" b "] and c is [" c "]"))(princ))
values a b c will only be used locally with (test) function and will not impact what they're defined as outside the function:
@oscar_mathieson hi,
to add what said @paullimapa
the 'game' here is Scope. every variable (or function) has it's life time depending on where it is declared.
if you do not declare it locally, then it is global and every other function can reset it.
if a variable is declare locally, it's initial value is nil and it vanish (totally not exist anymore) as the function ends. a local variables 'lives' in autolisp memory separately from global variables. that means if a function declare a variable 'a' which already exist as global, they are not override each other.
same rule is for function arguments, their scope is for the duration of the function even if their names is the same as the variables outside (global or other).
Moshe
Perfect. Thank you!