bill lam-2 wrote: > > On Fri, 28 Nov 2008, Viktor Cerovski wrote: >> But the truth is that the Graham's accumulator-generator problem can >> be solved without any resort to lexical closures. One such solution, >> based on the Burke's solution from the link above but without >> cocreate is: >> >> G =: 1 : 0 >> n=.'n',":?10000000000x >> (n)=:m >> 3 : (n,'=:',n,'+y') >> ) > > This is not a good example, it use base locale or the current locale > when G is called. Value of n can be changed apart from by G, and G > will fail. Whether it is called lexical closure or cocreate or > otherwise, some physical location of ram/harddisk/paper/neuron is used > to store its state. > I don't know whether this is a good or a bad example, but G does solve the problem without resort to locales, simply by inventing a new global secretly named variable, in which the state of the generator is physically stored.
As long as no one but the generator knows the name of the created variable, everything works. That's also true for solutions involving cocreate: as long as there are no outside changes of, for example, n_8_, generator works as expected. > If there is a difference between non-deterministic and random, I would > say random has to satisfy certain statistical properties to be > qualified as random. On the other hand non-deterministic means > undefined so that I can use any algorithm but just don't tell you. > I agreee. Lexical closures are non-deterministic, because n to which one refers within a closure may refer to any of any number of physically stored values, and we can't tell to which one each particular n refers to. It's the same as in the example above, except that the language takes care of names by limiting of the scoping of names within an expression. As long as we have a generator that generates unique secret names, all we need is a single locale, the global locale, as well as the non-knowledge of what the true names of variables where generators keep their states really are, to keep generators going. -- View this message in context: http://www.nabble.com/Rosetta-Codes%3A-Amb-operator-tp20682749s24193p20745385.html Sent from the J Programming mailing list archive at Nabble.com. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
