3
$\begingroup$

I have some trouble to use the triple underscore notation to use definitions with or without a term. Consider the following toy example

f[a___ x]:=1
{f[x],f[2x]}

This returns

{f[x],1}

whereas I would like the $f[x]$ pattern to be matched. I guess it is not recognizing "1" as an empty element. How can I arrange this definition to get {1,1} as an output ?

$\endgroup$
1
  • $\begingroup$ Give "a" a default value: f[a__ : 1 x] := 1 $\endgroup$ Commented Mar 22 at 14:17

1 Answer 1

4
$\begingroup$
f[a_. x] := 1
{f[x], f[2 x]}

{1, 1}

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.