MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

pattern sequences (what do you think of this feature reqest?)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68110] pattern sequences (what do you think of this feature reqest?)
  • From: "Chris Chiasson" <chris at chiasson.name>
  • Date: Mon, 24 Jul 2006 00:55:55 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

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/


  • Prev by Date: Re: HoldForm
  • Next by Date: Re: HoldForm
  • Previous by thread: Mathlink: Passing functions to C++
  • Next by thread: Multinomial coefficients evaluation