[REBOL] Re: local vars in functions
From: lmecir:mbox:vol:cz at: 25-Apr-2002 9:50
Hi,
just a note: you would have to define print & func as global too for your
code to work (that is why this isn't a good alternative). I once suggested
another possibility: what if every set-word automatically declared the word
as local, while other word would be local by default (which is usual in
objects currently)? (See http://www.rebolforces.com/~ladislav/rep.html which
contains some other ideas how to enhance the detectability of global vs.
local variable errors)
<rishi>
here is another possible brainstorming idea for
int/adv users without changing things for beginners.
REBOL []
globvar1: $1000
globvar2: $9999
myfunc: func [/global globvar1] [
localvar: $25
print globvar1
print globvar2 ; error
myinnerfunc: func [/global globvar2] [
innerlocal: $10
print localvar
print globvar1
print globvar2
]
print globvar2 ; error
print innerlocal ; error
]
print localvar ; error
and if you do this, it makes no difference (backwards
compatibility):
REBOL []
globvar1: $1000
globvar2: $9999
myfunc: func [
/local localvar myinnerfunc
/global globvar1
] [
localvar: $25
print globvar1
print globvar2 ; error
myinnerfunc: func [
/local innerlocal
/global globvar2
] [
innerlocal: $10
print localvar
print globvar1
print globvar2
]
print innerlocal ; error
print globvar2 ; error
]
print localvar ; error
but i lean towards the "::" thing.
- rishi