Howdy, Galt:

> Galt wrote: make-adder: func [x] [func [y] [+ x y]]
>
> I am guessing  that the problem is that  there is only  one
> copy  of the  block  [+ x  y]  and that  it has  a context,
> whatever  that is, and  that it can  only have one context,
> and that one  gets  changed  everytime you run   make-adder
> again with   a  new  parameter value  for   x.   So running
> make-adder a  2nd time messes up  the  value hidden  in the
> context of the first?

  There's only one context for make-adder where the value for
  x is looked up in your returned adder function.  You'd need
  to create a new context for each x.  You'll also need to
  keep those contexts around to be GC safe.  Here is one
  possible way of creating these functions based solely on
  contexts:

  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).

  -jeff

Reply via email to