I'm new to prolog; I'm coming from a structured programming background, as will become obvious :)

I am building up a prolog query that involves reversing a number; eg. `reverse_num(123,X)` results in `X = 321`. I came up with the following definition, but it only works when I provide a number as the first parameter.

```
reverse_num(Num, Revnum) :-
  number_chars(Num, Atoms),
  reverse(Revatoms, Atoms),
  number_chars(Reversed, Revatoms),
  Reversed = Revnum.

```

the `number_chars/2` predicate doesn't like an unsubstantiated variable if I do: `reverse_num(X,123)` (where I'm expecting `X` to be `321`).

Am I trying too hard to make reverse\_num do something it shouldn't (should it be understood to work only with a number as the first parameter and variable as the second)? 

Or is there an easy / straight-forward way to handle a variable as the first parameter?