localized func alternative...
[1/6] from: maximo:meteorstudios at: 27-Feb-2004 17:39
Hi all,
Has anyone programed an alternative to func (function, has, does) which declares every
set-word as local by default?
I find rebol's liberal use of global namespace to be the most limiting factor in scaling
rebol to large tools.
I'd rather have to define global words than local words (especially in api tools).
There is MUCH less chance that incidious errors will be generated or exposed.
A notable example is the recent S: variable useage in the sql tool which would not have
occured.
TIA!
-MAx
---
You can either be part of the problem or part of the solution, but in the end, being
part of the problem is much more fun.
[2/6] from: ammon:addept:ws at: 27-Feb-2004 20:35
The best way to achieve this (IMHO) is to simply use CONTEXT. This sets
everything within an object and you can set global words using SET. A note
about setting words this way though, they have the context of the CONTEXT
they are set in so while they are global, their values are relative to the
context.
Enjoy!!
~~Ammon ;~>
[3/6] from: tim:johnsons-web at: 27-Feb-2004 16:55
* Maxim Olivier-Adlhoch <[maximo--meteorstudios--com]> [040227 14:05]:
> Hi all,
>
> Has anyone programed an alternative to func (function, has, does) which declares every
set-word as local by default?
>
> I find rebol's liberal use of global namespace to be the most limiting factor in scaling
rebol to large tools.
No kidding. There much be a reason, but I dunno why.....
> I'd rather have to define global words than local words (especially in api tools).
; Below is code that I use. It is developed by Andrew Martin with the
; last mod by me. I believe that Ladislav has a 'fun also...
make object! [
Find-Locals: function [Locals [block!] Body [block!] Deep [none! logic!]] [Value] [
parse Body [
any [
set Value set-word! (
if not found? find Locals Value: to word! :Value [
insert tail Locals Value
]
)
| set Value block! (
if Deep [
Find-Locals Locals Value Deep
]
)
| skip
]
]
Locals
]
set 'Fun function [
"Automatic local word generation for a function."
Spec [block!] {Optional help info followed by arg words, optional type and string.}
Body [block!] "The body block of the function."
/Deep "Inspect block! values recursively for more local words."
][
Locals LocalRefinement
][
Locals: copy []
if found? LocalRefinement: find Spec /local [
insert Locals next LocalRefinement
Spec: copy/part Spec LocalRefinement
]
Find-Locals Locals Body Deep
Locals: exclude Locals Spec
function Spec Locals Body
]
set 'Sub :Fun
]
def: sub[Spec[block!] Body[block!]][sub/deep Spec Body] ; added by Tim
> There is MUCH less chance that incidious errors will be generated or exposed.
Enjoy! I sure have. Kudos to Andrew and Ladislav
> A notable example is the recent S: variable useage in the sql tool which would not
have occured.
> TIA!
<<quoted lines omitted: 4>>
> To unsubscribe from this list, just send an email to
> [rebol-request--rebol--com] with unsubscribe as the subject.
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.alaska-internet-solutions.com
[4/6] from: brett:codeconscious at: 28-Feb-2004 15:39
Ammon wrote:
> The best way to achieve this (IMHO) is to simply use CONTEXT. This sets
> everything within an object and you can set global words using SET. A
note
> about setting words this way though, they have the context of the CONTEXT
> they are set in so while they are global, their values are relative to the
> context.
Just a clarifcation for REBOL learners.
Set used this way normally does set global words but only because the word
you give to Set is global in the first place. Give Set a word from another
context (a non-global context) and it will happily set that word in that
context - Set is not limited to global words. For example:
ctx-1: context [
word-one: 1
ctx-2: context [
word-two: 2
set 'word-one "one"
]
]
>> print ctx-1/word-one
one
Regards,
Brett
[5/6] from: lmecir:mbox:vol:cz at: 28-Feb-2004 8:06
Maxim Olivier-Adlhoch napsal(a):
>Hi all,
>Has anyone programed an alternative to func (function, has, does) which declares every
set-word as local by default?
<<quoted lines omitted: 4>>
>TIA!
>-MAx
you can use http://www.fm.vslib.cz/~ladislav/rebol/lfunc.r (uses local
variables), or, if you want to have a function having *static* local
variables in addition, use http://www.fm.vslib.cz/~ladislav/rebol/sfunc.r
-L
[6/6] from: maximo:meteorstudios at: 1-Mar-2004 9:15
thanks everyone... I'll be checking all of this ASAP.
:-)
-MAx
---
You can either be part of the problem or part of the solution, but in the end, being
part of the problem is much more fun.
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted