Anders Borch wrote:
> Timon Christl wrote:
>> -- 
>> (defun f(p x)(If(Eq x nil)nil(If(p(Car x))(Cons(Car x)(f p(Cdr x)))(f p
>> (Cdr x)))))(defun q(x)(Q nil x))(defun Q(a x)(If(Eq x nil)a(Q(Cons(Car
>> x)(Q a(f(Lt(Car x))(Cdr x))))(f(Gt(Car x))(Cdr x)))))
> 
> 
> sorry I cannot help you ou there... also I cannot figure out your sig... 
>  what parameters am I supposed to give to f?

p is a predicate and thus itself a function. f takes the predicate and a 
list x and applies p to each element of x. Those elements where p 
returns true form the output of f. This means that f is nothing else 
than a filter function.

An example call would be

f Odd x

where Odd would be a function that takes one integer argument and 
returns 1 or 0, depending on wether the argument is odd or even.

To go back to the topic of this group, here is a 1:1 conversion of that 
function to ruby (working on arrays as lists and using a Proc object for 
the predicate):

def f(p,x)
   if x==[] then
     []
   else
     if p.call(x.first) then
       return [x.first]+f(p,x[1..-1])
     else
       return f(p,x[1..-1])
     end
   end
end

f(Proc.new { |x| (x%2)==1 },[1,2,3,4,5])

-- 
(defun f(p x)(If(Eq x nil)nil(If(p(Car x))(Cons(Car x)(f p(Cdr x)))(f p
(Cdr x)))))(defun q(x)(Q nil x))(defun Q(a x)(If(Eq x nil)a(Q(Cons(Car
x)(Q a(f(Lt(Car x))(Cdr x))))(f(Gt(Car x))(Cdr x)))))