Message Boards Message Boards

0
|
1903 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Make an option like f[v:{__Real}]:=2v work for f[{1.} and f[{1}]?

I want

f[{1,2.}]

to give

{2,4.}

These don't work:

f[v:{__Integer}]


f[v:{__Number}], f[v:{__Real || Integer}]

Sometimes "__" doesn't print in the Post Preview

POSTED BY: William Marks
2 Replies

I think this is what you want:

f[v : {(_Real | _Integer) ..}] := 2 v

Note the use of Repeated (..), and a single | (called Alternative).

this will accept a list of integers/reals

POSTED BY: Sander Huisman

Forgot to add:

triple period (...) will also except an empty list: { }

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract