.macro foreach :foreach.input1 :foreach.input2 [:foreach.input.rest]
catch "foreach.catchtag [
  op foreach.done runresult [
    foreach1
      butlast fput :foreach.input1 fput :foreach.input2 :foreach.input.rest
      last    fput :foreach.input1 fput :foreach.input2 :foreach.input.rest
      1
  ]
]
op []
end

to foreach1 :template.lists :foreach.template :template.number
if emptyp first :template.lists [throw "foreach.catchtag]
apply :foreach.template firsts :template.lists
.maybeoutput foreach1 bfs :template.lists :foreach.template :template.number+1
end

to foreach.done :foreach.result
if emptyp :foreach.result [op [stop]]
op list "output quoted first :foreach.result
end

bury [foreach foreach1 foreach.done]
