Hello Raul;
How about an 'rfold' adverb so that
finalState =: FSM rfold initialState,transitions
I could use such special code in lots of places.
Raul Miller wrote:
On Nov 18, 2007 10:10 AM, Ralph G Selfridge <[EMAIL PROTECTED]> wrote:
Just what is the definition of 'right fold' and 'left fold'? There would
seem to be several in this forum.
Right fold is basically u/@,&x y
In other words, it is reduce with an independently specified initial value.
However, note that in the general case, m can be a different type from the
rest of the list (but m typically would be of the same type as the result of
the dyad u). If you want to mix types like this in J, you might instead use
u/@,&(<x) <"_1 y
This general case version can be a bit slow, because J currently includes
no special code to support this case. (No one has presented any really
convincing cases about why something this obscure should be made really
fast.)
Left fold works basically the same way, but evaluates from left to right
instead of from right to left. In other words u~/@|.@,&x y
--
------------------------------------------------------------------------
|\/| Randy A MacDonald | APL: If you can say it, it's done.. (ram)
|/\| ramacd <at> nbnet.nb.ca |
|\ | | The only real problem with APL is that
BSc(Math) UNBF'83 | it is "still ahead of its time."
Sapere Aude | - Morten Kromberg
Natural Born APL'er |
-----------------------------------------------------(INTP)----{ gnat }-
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm