Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #11818 > unrolled thread
| Started by | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| First post | 2012-09-19 08:58 +0000 |
| Last post | 2012-09-19 08:58 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: set option flag in function definition Bob Hanlon <hanlonr357@gmail.com> - 2012-09-19 08:58 +0000
| From | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| Date | 2012-09-19 08:58 +0000 |
| Subject | Re: set option flag in function definition |
| Message-ID | <k3c1fv$f0r$1@smc.vnet.net> |
ClearAll[f]
f::opt =
"The argument `1` is not an appropriate option flag. " <>
"Please indicate correct option flag (i.e., optionX or optionY).";
f[arg1_, arg2_, arg3_, optionX] = arg1/arg2 + arg3;
f[arg1_, arg2_, arg3_, something_] /; If[
TrueQ[something == optionY], True,
Message[f::opt, something]; False] := arg1*arg2 - arg3;
f[x, y, z, optionX]
x/y + z
f[x, y, z, optionY]
x y - z
f[x, y, z, t]
f::opt: The argument t is not an appropriate option flag. Please
indicate correct option flag (i.e., optionX or optionY).
f[x, y, z, t]
Bob Hanlon
On Tue, Sep 18, 2012 at 3:41 AM, Joug Raw <jougraw@gmail.com> wrote:
>
> Dear Experts,
>
> I had one question regarding to the function definition.
>
> I want to have a function that executes certain operation when I chose the
> corresponding option flag.
>
> For example,
>
> a function called "f"
>
> when I call it like f[arg1,arg2,arg3, optionX]
> it executes command
> arg1/arg2+arg3
>
> If I call it like f[arg1,arg2,arg3,optionY]
> it executes command
> arg1*arg2-arg3
>
> If I call it like f[arg1,arg2,arg3,optionSomethingElse]
> it returns me
> "No appropriate option flag was found. Please indicate correct options"
>
> This looks a bit like scripts running in UNIX. I am wondering if I can do
> the same in Mathematica easily?
>
> Thank you so much for your kind help!
>
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web