Oops,

Cut and paste of wrong version led to omission of  /local. Should have been:

make-add: func [x /local saved][
      saved: []
      get in last append saved make object! [
          z: x
          f: func [y][+ z y]
      ] 'f
 ]

The original as given below is identical to Jeff's except that the stored
objects are shown when doing

>>source make-add

but 'saved is still a global word.  With /local as above, 'saved is known
only in the context of the function make-add.

Sorry for the confusion

-Larry

----- Original Message -----
From: Larry Palmiter <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, July 10, 2000 8:04 PM
Subject: [REBOL] func[func] Re:(6)


> Hi Jeff
>
> You wrote:
> >   save-em: copy []
> >   make-adder: func [x][
> >       get in last append save-em make object! [
> >           z: x f: func [y][+ z y]
> >       ] 'f
> >   ]
> >
> >   The above creates new contexts to hold the different values
> >   of X in your separate add functions.  (It also creates new
> >   functions that use those X values).
>
> Nice and it works.
>
> One can also tidy things up by encapsulating the block of saved items in
the
> function which also illustrates a practical use of the behavior of literal
> blocks contained in functions.
>
> make-add: func [x][
>      saved: []
>      get in last append saved make object! [
>          z: x
>          f: func [y][+ z y]
>      ] 'f
> ]
>
> Cheers
>
> -Larry
>

Reply via email to