[REBOL] Trying to compose a block out of global and local bindings Re:(2)
From: lmecir:geocities at: 8-Sep-2000 22:08
Hi,
<SS> wrote:
> I'll point out quickly that what you're trying to do is generally
> considered a bad programming practice, i.e. referencing a variable
> internal to a function from its argument. A caller shouldn't need to know
> about and shouldn't really have direct access to variables local to a
> function.
>
> I will however provide an example of how to do what I think you're trying
> to do and recommend that you rethink your approach in any case because
> this is almost as bad but I think it demonstrates that your problem was
> perhaps not one as much of scope but more of tokenization:
>
> >> letter2: func [b][foreach n ["sally" "sue"][print replace (copy b)
'name n]]
> >> greeting: ["hi" name "welcome back"]
> == ["hi" name "welcome back"]
> >> {I prefer not to overwrite REBOL words, like "form" from your example}
> == {I prefer not to overwrite REBOL words, like "form" from your example}
> >> name: "bob"
> == "bob"
> >> letter2 greeting
> hi sally welcome back
> hi sue welcome back
> >>
>
> FWIW,
>
> <SS>
>
The self-modifying Bind-, or its non-self-modifying Bind/copy- variant
approach really doesn't look preferrably to me. Here is an approach that
looks different IMHO:
letter2: func [b /local subst][
subst: func [name] reduce [:print b]
foreach n ["sally" "sue"][subst n]
]
greeting: ["hi" name "welcome back"]
name: "bob"
letter2 greeting
What do you think?
Ladislav
>
> On Thu, 7 Sep 2000 [princepawn--lycos--com] wrote:
>
> > >> letter2: func [b /local name] [foreach n ["sally" "sue"][ name: n
print reform reduce b] ]
> >
> > >> form
> > == ["hi" name "welcome back"]
> >
> > >> name
> > == "bob"
> >
> > >> letter2 form
> > hi bob welcome back
> > hi bob welcome back
> >
> > ... the only problem is I was hoping that the loop values in letter2
would take precedence over the globally bound value of name and allow me to
create a form letter of sorts.