I wrote:
> On Sun, Nov 30, 2008 at 7:40 AM, Viktor Cerovski
> <[EMAIL PROTECTED]> wrote:
>> Your code then should also have the Closure produce unique
>> instances of generators: each produced generator should have
>> a unique internal state.
>
> It does.
To illustrate:
Adder=: ] Closure +
Sequencer=: (({.;@;' and';[EMAIL PROTECTED])~ i:&',') Closure ([,', ',])
a0=: 0 Adder
a2=: (0 0,:0 0) Adder
s0=: '0' Sequencer
sz=: 'zero' Sequencer
a0 2
2
a0 3
5
a2 10
10 10
10 10
a2 2 3
12 12
13 13
s0 '1'
0 and 1
s0 '2'
0, 1 and 2
sz&> ;:'one two three'
zero and one
zero, one and two
zero, one, two and three
If you have some example of your proposed ]: which
is useful (not contrived), which my implementation
of Closure does not support, I would be interested.
That said, on re-reading, I think I might see what
point you were getting at: you wanted the initialized
generator to be produced from Closure. And, I
could do that with a minor bit of rearranging, but
that would be less modular than my current proposal.
Or, you might be saying that you wanted the encapsulation
benefits of having the internal state of the generator being
different from the initial state provided to the
generator instance creator. But I think the notational
benefits of using a consistent treatment for state
take precedence over any performance benefits from
using some different internal representation for the state.
Or, you might be saying that you wanted to be able
to re-initialize the generator (along the lines of
re-initializing the seed of a random number
generator). If so, I have an idea of how this could
be done, but I suspect that you would not like it.
Or maybe this was just a solution looking for a problem,
and your objections were entirely theoretical?
Thanks,
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm