I have defined a function as follows:
fDistance[pointA_, pointB_: {0, 0}, metric_: "taxi"] :=
Module[{interval},
If[metric == "taxi",
interval =
Abs[pointB[[1]] - pointA[[1]]] + Abs[pointB[[2]] - pointA[[2]]],
interval =
Sqrt[(pointB[[1]] - pointA[[1]])^2 + (pointB[[2]] -
pointA[[2]])^2]]; interval]
Then
fDistance[{3, 4}]
(*7; ok*)
fDistance[{3, 4}, {1, 2}, "euclid"]
(*2 Sqrt[2]; ok*)
But
fDistance[{3, 4}, "euclid"]
(*error message*)
How can I avoid that Mathematica assign the string literal 'euclid' to the variable pointB? It should have returned 5 as the output below shows
fDistance[{3, 4}, {0, 0}, "euclid"]
(*5*)
And as a second question: Is it possible to call the function in the following manner
fDistance[pointB={1, 2}, metric='normal', pointA={3, 4}]
that is, its arguments are paired with a keyword instead of being in the correct order according to the function denition?
Thank you very much.