ahoy matey
stevan apter — 2004-10-23 22:16:13
easier to show the problem than explain it:
a list which contains nested occurrences of mated elements.
in this case, the list is a string and the mated elements
are '( and '):
"(abc(def)(ghi)(jk(lmn)(op)))rstuvw"
a list of the mates:
"()"
split the list into a pair of lists: the first of the pair
is everything up to the first right-mate which balances, and
the second is everything from there on:
"(abc(def)(ghi)(jk(lmn)(op)))rstuvw" "()" mated
["(abc(def)(ghi)(jk(lmn)(op)))" "rstuvw"]
"(ghi)(jk(lmn)(op)))rstuvw" "()" mated
["(ghi)" "(jk(lmn)(op)))rstuvw"]
"(abc(def)(ghi)(jk(" "()" mated
["(abc(def)(ghi)(jk(" ""]
in k:
mated:{(0,((#x)&1+(-/+\'x~'/:y)?0))_ x}
s:"(abc(def)(ghi)(jk(lmn)(op)))rstuvw"
mated[s;"()"]
("(abc(def)(ghi)(jk(lmn)(op)))"
"rstuvw")
transcribed into XY:
; mated [dup] dip mate 0 ,. _. ;
; mate [dup] dip [mate.] each/ i - 0 ? 1 + [#:] dip & ;
; mate. [~] each\ ,: 0 [+] under! ;
to construct the revised conditional i described to daniel,
one would say something like
queue [if: fi:] mated
to split the queue.