Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.7K Views
|
3 Replies
|
1 Total Like
View groups...
Share
Share this post:

[?] Define an option or an argument whose values are confined?

POSTED BY: Kui Chen
3 Replies

You might try the definition, like e.g.:

testFunction[x_, problemID_: 1] := (whatEverFunctionBody[x, problemID]) /; MemberQ[ {1, 2, 3, 4}, problemID]
POSTED BY: Henrik Schachner

That is one way of doing it, but that's not an option ;)

POSTED BY: Sander Huisman

This is kind of tricky for options what generally happens is that the function throws a message when the options are not correct (out of bound). See for example how it is done in the built-in Plot function, you can see how the arguments are parsed et cetera:

Needs["GeneralUtilities`"]
Plot[Sin[x], {x, 0, 1}];
PrintDefinitions@System`ProtoPlotDump`iPlotLayer1
PrintDefinitions@System`ProtoPlotDump`iPlot
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