help: outputing a function depending on a function parameter



Hi

I am trying to write a function that takes an ordering on sequences
as a parameter and output the corresponding (total) degree
compatible ordering.
So, the output should be again a boolean function.
I thought that one way to do it could be through 
lambda expressions but what I do is wrong.

I would like to do something like:
makeDegreeCompatible : /* or makeDegreeCompatible(order) := ... */
  lambda([order],
    lambda([x,y],
      (sum(x[i],i,1,length(x))<sum(y[i],i,1,length(y))) or
      (sum(x[i],i,1,length(x))=sum(y[i],i,1,length(y))) and
      order(x,y))
    );

but it does not work because the parameter order is within
a lambda expression and it is not substituted with the
value passed as a parameter.

Could someone please help me?

  Fabrizio