1
$\begingroup$

Normally one only sees patterns as function parameters:

fun1[x_]:=x^2

Is there any point to using a variable in a function definition:

fun2[y]:=x^2

I suppose to make this work I have to define y as a pattern:

y=x_

Is there any useful application where this occurs?

$\endgroup$
  • $\begingroup$ fun2 will only give a result for argument y, and will remain unevaluated otherwise. The point of using a pattern is that it's a "dummy" (satisfying the appropriate conditions) that can be replaced. $\endgroup$ – J. M. is in limbo May 16 '16 at 18:22
  • $\begingroup$ @J.M. I know why patterns are used. I am asking if there is an application for using a non-pattern parameter. $\endgroup$ – Tyler Durden May 16 '16 at 18:23
  • 1
    $\begingroup$ To make the first sentence in my previous comment more explicit: it can happen that you want your function to evaluate only for literal arguments. Special cases, or what have you. $\endgroup$ – J. M. is in limbo May 16 '16 at 18:25
  • 1
    $\begingroup$ You can use a variable in a function definition as an index. Here is a Wolfram Language Tutorial example. $\endgroup$ – Karsten 7. May 16 '16 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.