Short reply:  Yes!  Nice!

Longer reply:  See below...

[EMAIL PROTECTED] wrote:
> 
> I think this is a better generalization:
> 
> >> source repoke
> repoke: func [
>     "sets value within nested blocks"
>     block [block! hash! function! object!]
>     indexes [block!]
>     value [any-type!]
> ][
>     indexes: reduce indexes
>     while [1 < length? indexes] [
>         block: pick :block first indexes
>         indexes: next indexes
>     ]
>     poke block first indexes value
> ]
> 
...
> 
> >> source repick
> repick: func [
>     "picks repeatedly"
>     block [any-block! any-function! object!]
>     indexes [block!]
> ][
>     foreach i reduce indexes [block: pick :block i]
>     :block
> ]
> 
...
> >Try the following...
> >
> >    >> set2d: func [b [block!] d1 [integer!] d2 [integer!] x] [
> >    [    poke pick b d1 d2 x
> >    [    ]
> >    >> set2d a 3 2 "Goodbye!"
> >
> >.... and to generalize ...
> >
> >    >> set3d: func [
> >    [    b [block!] d1 [integer!] d2 [integer!] d3 [integer!] x][
> >    [    poke pick pick b d1 d2 d3 x
> >    [    ]

There's no question that Eric's single (pair of) function(s) is
much more elegant than the special purpose hack I tossed off the
top of my head, and I certainly prefer it as a standard item in
my toolkt.

I would only add that if I were writing code which did LOTS of
flogging of 2-D arrays, I'd probably code and use the special-
case 'set2d and 'get2d versions purely for performance reasons.

-jn-

Reply via email to