Oliver Mooney wrote:
Peter,

Thanks for pointing me in the right direction - I've derived a working solution but it looks a bit ungainly to me. I unrolled one iteration of the function to get the reversed list started and then had to short-circuit the final recursion on the far end to account for the list being reversed starting out one element shorter. Does that technically mean that I'm recursing n-1 times, so it isn't the envisaged solution?

fun {Convolute L1 L2}
   fun {ConvoluteAcc L1 L2 Acc}
      case L1 of H1|T1 then
case L2 of H2|T2 then
   local H3 in
      H3|_ = Acc
      H1#H3|{ConvoluteAcc T1 T2 H2|Acc}
   end
[] nil then local H3 in
      H3|_ = Acc
      H1#H3|nil
   end
end
      end
   end
   Elem
in
   case L2 of H|T then
      {ConvoluteAcc L1 T H|Elem}
   end
end
This code has a bug:
 {Browse {Convolute [1 2 3] [a b c]}}
gives [1#a 2#b 3#c] instead of [1#c 2#b 3#a].

Hint: you need two arguments for the reversed list,
one to build it and one to decompose it.  You can't
do both in one argument.

Peter
_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to