I have a function f and its downvalues. I want to code an extra downvalue for arguments of the form "part1:part2"
I don't understand why
f[a__~~":"~~b__] := {a,b}
does not work. I can only think of
f[string_String] /; StringMatchQ[string,__~~":"~~__] := StringCases[string, a__~~":"~~b__ :> {a,b}][[1]]
but this doesn't seem very smart as the string structure is examined two times.
a__~~":"~~b__
is aStringExpression
, not aPattern
. TryHead[a__ ~~ ":" ~~ b__]
vsHead[a_]
– acl Feb 17 at 23:25f[s_?(StringMatchQ[#, __ ~~ ":" ~~ __] &)] := StringSplit[s, ":"]
– rm -rf♦ Feb 17 at 23:41