We could use a constructed pattern that when executed does something
like this. This one would work if unevaluated expressions could be
generators, something not currently supported.
procedure greedy(p)
local L := [], startpos := &pos
write("s is ",&subject)
write(" ",repl("-",startpos-1),"^")
every x := =p do {
put(L, [x, &pos])
}
while pair := pull(L) do {
&pos := pair[2]
suspend &subject[startpos : &pos]
}
&pos := startpos
end
A more primitive "longest match" formulation would be something like
(tmplen:=0,(every tmplen <:= *(tmps:= =p)|1,tmps)
What about
procedure greedy(p)
if s := =p then suspend s||greedy(p) else suspend ""
end