(correction) pattern sequences
- To: mathgroup at smc.vnet.net
- Subject: [mg68139] (correction) pattern sequences
- From: "Chris Chiasson" <chris at chiasson.name>
- Date: Tue, 25 Jul 2006 04:01:48 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
I don't know how this happened, but AugmentedLagrangeMultiplier in the aLMMethodRule statement is supposed to be quoted, like this: aLMMethodRule = Method -> "AugmentedLagrangeMultiplier" | {"AugmentedLagrangeMultiplier", (_String -> _) ..} The example won't work otherwise. Sorry for the inconvenience. On 7/23/06, Chris Chiasson <chris at chiasson.name> wrote: > Context: > > The context for this email is that I am adding a new Method with > options to an existing Mathematica function (redefining the base > function is not an option). > > Issue: > > I have found a way to add the new Method and its options by using the > Trott-Strzebonski method. This was rather counter-intuitive. > > Suggestion: > > I think two much more clear ways would be to (1) have > Attributes[Pattern]={SequenceHold} (in addition to HoldFirst and > Protected) to allow matching on pattern objects that are Sequences OR > to (2) allow Pattern to match on more than two arguments. What do you > think of either of these features? Would you nominate either of them? > What are their possible drawbacks? > > Issue Example: > aLMMethodRule=Method\[Rule] > AugmentedLagrangeMultiplier|{AugmentedLagrangeMultiplier,(_String\[Rule]_)..} > > f[a_,opts___]:= > Module[{methodopt,methodoptions}, > CompoundExpression[methodoptions=Rest@methodopt[[1,2]];a/.methodoptions]/; > If[Length[ > methodopt= > Cases[{opts},Map[HoldPattern,aLMMethodRule,{0}]]]\[Equal]0, > False,True]] > > f["stuffed",1\[Rule]2, > Method\[Rule]{"AugmentedLagrangeMultiplier","stuffed"\[Rule]dog}, > afgan\[Rule]rug] > > (*the output is dog*) > > Suggestion (2) Example: > > rulePatternObject=Rule[_,_] > > sequenceRuleStringLhsPatternObject=(_String\[Rule]_).. > > f[a_,Pattern[opts,rulePatternObject..., > Method\[Rule] > "AugmentedLagrangeMultiplier"|{"AugmentedLagrangeMultiplier", > methodoptions:sequenceRuleStringLhsPatternObject}, > rulePatternObject...]]:=a/.methodoptions > > (*the output should be the same as above with the same function call, > but I obviously haven't tested it*) > > Let me know if I left anything out - this was part of a larger notebook. > > Regards, > > -- > http://chris.chiasson.name/ > -- http://chris.chiasson.name/