On Thu, Mar 28, 2024 at 12:14:45AM -0400, Liam R. E. Quin scripsit:
On Wed, 2024-03-27 at 23:57 -0400, Graydon Saunders wrote:
What's the appropriate pattern for "process a sequence, toggling an action on or off based on the last member of the sequence we looked at?"
One approach might be to use fold-left on (1 to count($input)), with $input in scope, so that you can write in the function argument to fold-left things like
if (. eq 1) then $input[.] else if (starts-with($input[. - 1], 'stab') then...
etc
Yeah, I phrased that badly.
The cases are "I've seen A", "I've seen B (so forget I've seen A)", and "I haven't seen A". There can be multiple instances of A and B and most things are C and what happens to C depends on whether or not we've seen A some time previously in the sequence.
So the approach I want to take is to have a toggle that lets me set "Have seen A" as a boolean and pass it to the subsequent evaluations. This used to be something I could do with hof:until by passing a map as the parameter, but that's not looking like what the current hof functions support.
(I'm using hof:until in other places in this particular task so I'm worried that I'm going to have to replace that code when 11 comes out, too.)
Thanks! Graydon