I'm trying to define a function f which takes a list of reals. My purpose is to build a function which I can give a list of reals, integers or strings and have it build an appropriate probability distribution for.
So I'd like to do something like
f[{samples_Real}]:=makeRealDist[samples];
f[{samples_Integer}]:=makeInteger[samples];
f[{samples_String}]:=makeCategoricalDist[samples];
I can easily match on Real/Integer/Strings.
The part I can't figure out is how to match on a list of Real/Integer/String.
f[{samples__Real}]orf[samples:{__Real}]– mfvonh Jun 24 '14 at 04:02Repeated(..), but hereBlankSequence(__) is simpler. – mfvonh Jun 24 '14 at 04:203will be rejected, but3.will be accepted. Why not check for NumericQ? but may be you really want Real. – Nasser Jun 24 '14 at 04:26:=is a pattern (not technically aPatternbut no matter), so it's just a question of what parts of that pattern you want to attach a definition to for use on the RHS. Sosamples__Realmeans you are capturing the sequence itself, whereassamples:{__Real}means you are capturing the list (which is just the headListwrapped around a sequence). – mfvonh Jun 24 '14 at 04:28Reals. You'd implement it like this:f[samples:{__?NumericQ}]– mfvonh Jun 24 '14 at 04:33