Raul, That is extremely helpful. The main thing I get out of both of your solutions, but most clearly out of the insert solution is that the argument to be altered should be on the right side. For some reason, I have wanted to reverse that. But your insert solution demonstrates that strongly.
When I was trying this I had tried your Fold solution, but using *move*, not *move~* , and was getting a domain error, which I could not understand to correct. I still don't see why move~ is correct in that context because move's x is state and move's y is moves; the ~ reverses those, I think. Btw, I was struggling to get the email version to work when I checked it before sending it, too. That's why I sent the attachment, believing that the errors would be avoided. On Tue, Dec 6, 2022 at 3:29 PM Raul Miller <rauldmil...@gmail.com> wrote: > I've not fully digested all of the fold rules yet, so I'll first focus > on building an insert version. > > The key to using insert is building representing the expression which > would result from insert. > > In other words, instead of > state tomove moves > +-+-+----+ > |C|M|PDNZ| > +-+-+----+ > > We could look at moves: > > moves > 1 2 1 > 3 1 3 > 2 2 1 > 1 1 2 > > and construct a corresponding expression. > > 1 1 2 move~ 2 2 1 move~ 3 1 3 move~ 1 2 1 move~ state > +-+-+----+ > |C|M|PDNZ| > +-+-+----+ > > There's a type mismatch between the left and right arguments to move, > so instead of move~/ we would need to box the arguments maintain that > in our intermediate results. > > That gives us |.state;<"1 moves as a starting point, move~&.>/ to > operate on them and ; to clean up at the end. > > ;move~&.>/|.state;<"1 moves > +-+-+----+ > |C|M|PDNZ| > +-+-+----+ > > Fold would let us dispense with this boxing mechanism, and ]F..v is > roughly equivalent to v/ and, testing, this works: > > state ]F..(move~) moves > +-+-+----+ > |C|M|PDNZ| > +-+-+----+ > > And, I guess a rule here is that X ]F..V Y can be tested beforehand by > using V between items of Y with X as the rightmost such item. > > I hope this makes sense, > > -- > Raul > > > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm