Stack Exchange network consists of 182 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
$\begingroup$Thank you for the comment. Some more questions. When I tried g3[5, 6, 7] it gave me {5,6,7} which is what I expected from the general pattern. However, g2[5, 6, 7] also gives the same result, so I am not sure what's the difference. Also g1[], g2[], just give back the same while g3[] gives back {}. Could you explain a bit more thoroughly? Am I missing something?$\endgroup$
$\begingroup$Konstantinos, see Blank (_), BlankSequence (__) and BlankNullSequence (___) in the docs for more details. g1 requires a single argument; so g1[] and g1[2,3] both return unevaluated. g2 requires 1 or more arguments so g2[] returns g2[]; and ...$\endgroup$
$\begingroup$... g3 expects 0 or more arguments so g3[] evaluates to {}, g3[1,2,3] gives {1,2,3}and g3[{1,2,3}] (one argument which is the list {1,2,3}) gives {{1,2,3}} etc.$\endgroup$
$\begingroup$Thanks a lot once more. I did not know how to find these online. I was trying something like f[__] Mathematica and nothing was popping up.$\endgroup$
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
g1[x_]:= {x}
,g2[x__]:= {x}
, andg3[x___]:={x}
and compareg1[]
,g1[5]
andg1[5,6]
(similarly forg2
andg3
). $\endgroup$Blank (_)
,BlankSequence (__)
andBlankNullSequence (___)
in the docs for more details.g1
requires a single argument; sog1[]
andg1[2,3]
both return unevaluated.g2
requires 1 or more arguments sog2[]
returnsg2[]
; and ... $\endgroup$g3
expects 0 or more arguments sog3[]
evaluates to{}
,g3[1,2,3]
gives{1,2,3}
andg3[{1,2,3}]
(one argument which is the list{1,2,3}
) gives{{1,2,3}}
etc. $\endgroup$