How to define a function reminding of names of the independent variables?

You can get the behavior you ask for if you define your function to work with an association. The key-value paradigm provides syntax close but not exactly as you describe.

Simple approach

f[a_Association] := a[x]^2 + a[y]^3
f[<|x -> 5, y -> 7|>]

368

Argument keys are not affected by global assignments. Changing the order of the key-value pairs has no effect.

x = 42; f[<|y -> 7, x -> 5|>]

368

Behavior when given bad keys is a little messy.

f[<|a -> 5, b -> 7|>]

Missing["KeyAbsent",x]^2+Missing["KeyAbsent",y]^3

Strict approach

Clear[x,y]
g[a : <|x -> _, y -> _|>] := a[x]^2 + a[y]^3
g[<|x -> 5, y -> 7|>]

368

Order matters.

g[<|y -> 7, x -> 5|>]
g[<|y -> 7, x -> 5|>]

Bad keys simply prevent evaluation.

g[<|a -> 5, b -> 7|>]
g[<|a -> 5, b -> 7|>]

Keys are not protected from global assignments, but evaluation doesn't occur. You could fix this by making the keys strings (e.g., "x" in place of x), but typing strings is more time comsuming.

x = 42; g[<|x -> 5, y -> 7|>]
g[<|42 -> 5, y -> 7|>]

If this is just to help entering values in the correct order (and not to be permanently visible), you can possibly use a Placeholder. Reevaluating phf below will produce the template again: just type phf, select it, right-click and choose Evaluate in Place.

f[x_, y_] := x^2 + y^2
phf = Defer[f[Placeholder[x], Placeholder[y]]]

enter image description here


Here’s a couple of interesting methods:

f1[x_,y_]:=With[
{
$x=x/.Equal[$arg_,$val_]:>$val,
$y=y/.Equal[$arg_,$val_]:>$val
},
$x^2+$y^3
]
f2[X_,Y_]:=With[
{
$x=X/.Equal[$arg_,$val_]:>Rule[$arg,$val],
$y=Y/.Equal[$arg_,$val_]:>Rule[$arg,$val]
},
ClearAll[$assoc];
$a=Association[{$x,$y}];
$a[x]^2+$a[y]^3
]

Both carry the same syntax:

f1[x==5,y==3]
f2[x==5,y==3]

(*52*)
(*52*)

While neither do exactly what you might want to do, each offers a unique aspect that you might be able to pull from!

These methods do fall apart if one or more of the variables has already been assigned globally. Inspired by the answer from user @m_goldberg, find this method:

f3[X_,Y_]:=With[
{
$a=Association[{X,Y}]
},
$a[x]^2+$a[y]^3
]
x=4;
y=7;
f3[x->5,y->3]

(*52*)

Which is robust against globally assigned values of the arguments used.

This also does work:

f[__]:=x^2+y^3;
f[x=5,y=3]

(*52*)

As pointed out by @G.Shults, this method, unlike the one above it, is only robust against incoming globally assigned values of the arguments. Due to the use of Set, this method has a direct impact on outgoing globally assigned values of the arguments.

Depending upon your use-case, any of these methods may be found to be the most ideal.