[REBOL] Re: Executable code blocks as arguments
From: ryanc:iesco-dms at: 22-Aug-2001 10:27
The context of the block arg must be bound to the current context.
>> ob: make object! [
[ a: 1
[ f: func [v] [bind v 'a do v]
[ ]
>> ob/a
== 1
>> ob/f [a: 5]
== 5
>> ob/a
== 5
>>
have fun, --Ryan
Tim Johnson wrote:
> Hello All:
> Is it possible to pass a code block to a function member of an object
> which would perform adhoc operations on object members?
> Below is an example which I have set up:
> REBOL []
> o: make object![
> a: 1 b: 2 c: 3
> modify: func[arg[block!]][do arg]
> ]
> print mold o
> o/modify [a: "one" b: "two" c: "three"]
> print mold o
> ; now the output below
> make object! [
> a: 1
> b: 2
> c: 3
> modify: func [arg [block!]][do arg]
> ]
> make object! [
> a: 1
> b: 2
> c: 3
> modify: func [arg [block!]][do arg]
> ]
> ; as you can see, 'a, 'b, and 'c remain unmodified.
> ; The result that I would be looking for would be:
> make object! [
> a: "one"
> b: "two"
> c: "three"
> modify: func [arg [block!]][do arg]
> ]
>
> Can I do this at all? If so, thanks in advance for
> advice and comments, and feel free to point me to
> docs on this.
> regards
> Tim
> --
> To unsubscribe from this list, please send an email to
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Ryan Cole
Programmer Analyst
www.iesco-dms.com
707-468-5400