# Parametric Function

i'm struggling to implement the following parametric function:

I need to create a g function with two arguments (w and v). If w and v are not empty lists, then it will return a list containing two other lists: - one containing the elements of w that do not occur in v, - and the other containing the elements of v that do not occur in w, If one of w or v are empty lists, it should return a message "One of the lists is empty".

Hope anyone can help me out here, thanks in advance.

-
Seems quite straightforward. Check the docs for If[] and Complement[] – belisarius has settled Jan 9 at 17:37
Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – belisarius has settled Jan 9 at 17:40
Try g[w_, v_] := If[w == {} || v == {}, "D'oh!", {Complement[w, v], Complement[v, w]}]. – DumpsterDoofus Jan 9 at 17:43
I added my comment as an answer. If people think this question is trivial enough to be closed, I'll delete my answer and vote to close for "easily found in the documentation" and leave my answer as the comment above. – DumpsterDoofus Jan 9 at 18:00
Regardless, the title is unrelated to the question (which has nothing to do with parametric functions). If this question is to remain, the title should be changed to reflect the actual question. – David G. Stork Jan 9 at 20:16

Try the following:

g[w_, v_] := If[w == {} || v == {}, "D'oh!", {Complement[w, v], Complement[v, w]}]


Some tests:

g[{2, 3, 4}, {2, 5}]
g[{2}, {}]


producing

{{3, 4}, {5}}
"D'oh!"

-

Here is an alternative, using dispatch between multiple definitions:

g[{},_] = g[_,{}] = "One of the lists is empty";
g[a_,b_] := { a~Complement~b, b~Complement~a };


If you like syntactic sugar, you could also write the second line as

g[a_,b_] := Complement @@@ { {a,b}, {b,a} };

-