2 fixed grammar, improved formating

I have defined a function as follows:

fDistance[pointA_, pointB_: {0, 0}, metric_: "taxi"] :=
Module[{interval},
If[metric == "taxi",
interval =
Abs[pointB[] - pointA[]] + Abs[pointB[] - pointA[]],
interval =
Sqrt[(pointB[] - pointA[])^2 + (pointB[] -
pointA[])^2]]; interval]


Then

fDistance[{3, 4}]
(*7; ok*)

fDistance[{3, 4}, {1, 2}, "euclid"]
(*2 Sqrt; 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*)


Is isAnd as a second question: Is it possible to call the function as followsin 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.

I have defined a function as follows:

fDistance[pointA_, pointB_: {0, 0}, metric_: "taxi"] :=
Module[{interval},
If[metric == "taxi",
interval =
Abs[pointB[] - pointA[]] + Abs[pointB[] - pointA[]],
interval =
Sqrt[(pointB[] - pointA[])^2 + (pointB[] -
pointA[])^2]]; interval]


Then

fDistance[{3, 4}]
(*7; ok*)

fDistance[{3, 4}, {1, 2}, "euclid"]
(*2 Sqrt; 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*)


Is is possible to call the function as follows

fDistance[pointB={1, 2}, metric='normal', pointA={3, 4}]


that is, its arguments are paired with a keyword?

I have defined a function as follows:

fDistance[pointA_, pointB_: {0, 0}, metric_: "taxi"] :=
Module[{interval},
If[metric == "taxi",
interval =
Abs[pointB[] - pointA[]] + Abs[pointB[] - pointA[]],
interval =
Sqrt[(pointB[] - pointA[])^2 + (pointB[] -
pointA[])^2]]; interval]


Then

fDistance[{3, 4}]
(*7; ok*)

fDistance[{3, 4}, {1, 2}, "euclid"]
(*2 Sqrt; 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.

1

# define a function with optional arguments

I have defined a function as follows:

fDistance[pointA_, pointB_: {0, 0}, metric_: "taxi"] :=
Module[{interval},
If[metric == "taxi",
interval =
Abs[pointB[] - pointA[]] + Abs[pointB[] - pointA[]],
interval =
Sqrt[(pointB[] - pointA[])^2 + (pointB[] -
pointA[])^2]]; interval]


Then

fDistance[{3, 4}]
(*7; ok*)

fDistance[{3, 4}, {1, 2}, "euclid"]
(*2 Sqrt; 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*)


Is is possible to call the function as follows

fDistance[pointB={1, 2}, metric='normal', pointA={3, 4}]


that is, its arguments are paired with a keyword?