Hi! Does this fold implementation try to do what in Smalltalk is usually done using the inject:into: selector? An example for that would be:
{ 'a'. 'b'. 'c' . 'd' } inject: 'foo' into: [ :x :y | '(' + x + ',' + y + ')' ] would evaluate to: '(((foo,a), b), c), d)' (or something similar, depending on whether you do a fold-right or fold-left. If this is the idea behind that patch, using Smalltalk or ObjC2 blocks would probably give a more elegant solution... Best regards, Günther On 13 Jun 2009, at 11:35, David Chisnall wrote: > On 13 Jun 2009, at 09:15, Niels Grewe wrote: > >> Hi again, >> >> This really is fun! I never thought that implementing fold would be >> that much >> easier. I have attached a patch and sample code on which I would >> like to >> get some feedback. I know that there is quite some duplicated code >> that >> should be refactored into a more generic implementation for arbitrary >> collections and HOM-variations. What else is there that could be done >> to improve this? > > Good catch on the nil test in map. > > I don't really understand your code. What is the selfArgs array for? > You seem to be trying to implement something like NSIndexSet, but I > can't really work out why. > > Did you try running your test program? It references a variable > 'lower' which doesn't exist, so it shouldn't even compile... > > I expect to use a fold method like this: > > id input = A(@"a", @"b", @"c"); > [ETTranscript show: [[input fold] stringByAppendingString: @"letters: > "]]; > > I would then get the output: > > letters: abc > > To do this, you need to set arg 2 of the invocation to last value > returned (initially to the original arg 2 value) and then invoke with > the target set to the next element in the array (or the other way > around, for folding the other way). This doesn't require any of the > selfArgs-related stuff, so I don't see what it is trying to > accomplish. > > David > > _______________________________________________ > Etoile-dev mailing list > Etoile-dev@gna.org > https://mail.gna.org/listinfo/etoile-dev _______________________________________________ Etoile-dev mailing list Etoile-dev@gna.org https://mail.gna.org/listinfo/etoile-dev