Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #2318
| From | Leonid Shifrin <lshifr@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: OptionsPattern[...] |
| Date | 2011-05-12 11:27 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <iqgg69$f19$1@smc.vnet.net> (permalink) |
I'd do the same, but use SlotSequence (##) in place of a single slot (#), in
funcBeta. Otherwise, when there is more than one option in the filtered
list, only the first one will be passed.
Regards,
Leonid
On Thu, May 12, 2011 at 12:33 PM, Wolfgang Windsteiger <
Wolfgang.Windsteiger@risc.jku.at> wrote:
> I would use
>
> funcAlpha[x:_, opts:OptionsPattern[]]:=
> With[{ appropriateOptions = FilterRules[{opts},Options[funcBeta]] },
> Apply[funcBeta[x,#]&, appropriateOptions]]
>
> WW.
>
> On 05/11/2011 10:27 AM, Scot T. Martin wrote:
> > This is a question about elegance.
> >
> > For the setups below for funcOne and funcAlpha, you will see the
> difference in the use of Sequence[...].
> >
> > funcOne can potentially pass "{ }" to funcTwo, which is undesirable for
> funcTwo. That is, a call of funcOne[value] without options will pass "{ }"
> to funcTwo.
> >
> > For funcAlpha[value], an empty pattern will be passed instead of "{ }" to
> funcBeta but requires the non-elegant formulation of Sequence[...]. This for
> mulation has the advantage of passing cascading options from one function to
> the next without progressively deeper "{ }", i.e., becoming "{{ }}" on next
> nested function call.
> >
> > Does anyone know how to use options better (i.e., in a more elegant
> fashion) than represented in my examples, i.e., to get the functionality of
> funcAlpha without the use of Sequence[..]?
> >
> > funcOne[x:_, opts:OptionsPattern[]]:=
> > With[{ appropriateOptions = FilterRules[{opts},Options[funcTwo]] },
> > funcTwo[x,appropriateOptions]]
> >
> >
> > funcAlpha[x:_, opts:OptionsPattern[]]:=
> > With[{ appropriateOptions = Sequence@@FilterRules[{opts},Options[funcBeta]]
> },
> > funcBeta[x,appropriateOptions]]
> >
>
>
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: OptionsPattern[...] Leonid Shifrin <lshifr@gmail.com> - 2011-05-12 11:27 +0000
csiph-web