Question: I'm writing a program which remove first element which fit to predicate eg.

```
remove' (fun x -> x = 2) [1;3;2;4;2] => [1;3;4;2]

```

and the problem is: how to write it with foward recursion? Is it possible? With tail recursion it is not a problem. I just add next elements to acc if they are not fit to predicate.

I was thinking about

```
List.fold_right,

```

but maybe is there different way to do this?

Answer: 
There is no such thing as "forward recursion". Tail recursion defines a special kind of recursion, that occurs in a tail position. When you want to refer to a recursion that is not in a tail position, you call it "non tail recursive"

In the code you've specified there is no recursion at all. So, I would suggest you first of all to try to write `remove_if` function and try to figure out whether it is tail or non-tail. 

Update
------

I usually try no to solve homework for others, but at this case I will give a little kick start, by providing you with the most common definition of `remove_if` function:

```
 let rec remove matches = function
    | [] -> []
    | x :: xs when matches x -> remove matches xs
    | x :: xs -> x :: remove matches xs

```

There are two occurrences of recursion in this function:

```
| x :: xs when matches x -> remove matches xs
                            ^^^^^^^^^^^^^^^^^
                            last expression - 
                            tail recursion

| x :: xs -> x :: remove matches xs
                  ^^^^^^^^^^^^^^^^^
                  not the last - 
                  non tail recursive

```

So, last case needs some clarification: before the `x` can be prepended to the result of `remove matches xs` the latter expression needs to be evaluated. That means that computer needs to store `x` somewhere, to wait until `remove matches xs` is evaluatd. 

So, no the fun part, you have a non-tail recursive version. Now, try to implement it tail recursively. Have `fun`!
**ivg** solution helps me a lot, but I needed to upgrade it a little. My answer is:

```
 let remove' p xs =
   let rec remove_guard p xs g =
      match xs with 
        [] -> []
      | hd::tl -> if (p hd && g = 1) then remove_guard p tl 0 
                  else  hd::remove_guard p tl g
 in remove_guard p xs 1

```

Maybe not the best, but it removes only one element. 

Thanks guys for help. I really appreciate it.