Raphael Collet wrote:
On Fri, Feb 27, 2009 at 3:07 PM, Oliver Mooney <[email protected]
<mailto:[email protected]>> wrote:
Sorry, in my original code the declared variables didn't match the
function names. I've fixed that below:
declare DiffListToList DiffListFromList
fun {DiffListFromList L}
case L
of Elem|nil then Hole in Elem|Hole#Hole
^^^^^^^^^^^^^^^
The operator '#' has higher priority than '|'! Therefore the expression
above does not return a pair, but an ill-defined list with a pair in one
of its tails. Try (Elem|Hole)#Hole instead.
That will not work because it will still put the pair with '#' at the end of
the list. The pair <list>#Hole has to be done at the beginning of the
recursion, as you did with the code below using Append.
Expanding the Append according to the code suggested by Oliver you'll get:
fun {DiffListFromList L}
fun {Loop L Hole}
case L
of Elem|nil then Elem|Hole
[] H|T then H|{Loop T Hole}
end
end
Hole
in
{Loop L Hole}#Hole
end
I find the Append version more elegant anyway, but this one is a solution if
you didn't now the existence of Append.
cheers
Boriss
[] H|T then H|{DListFromList T}
end
end
By the way, you can also define that function by reusing Append:
fun {DiffListFromList L}
T in {Append L T}#T
end
Cheers,
raph
------------------------------------------------------------------------
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users