MathGroup Archive 2009

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

Search the Archive

Re: Add syntax highlighting to own command

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101826] Re: Add syntax highlighting to own command
  • From: earthnut at web.de (Bastian Erdnuess)
  • Date: Sat, 18 Jul 2009 04:51:45 -0400 (EDT)
  • References: <200907090600.CAA17547@smc.vnet.net> <h3766u$f9h$1@smc.vnet.net> <h3pem5$o48$1@smc.vnet.net>

Daniel <janzon at gmail.com> wrote:

> Hi Bastian,
> 
> I think the line
> 
> >   Let[ { head_ }, expr_ ] := With[ { head }, expr ]
> 
> is unnecessary since tail_

  tail___ ?

> can match the empty sequence in
>
> >   Let[ { head_, tail__ }, expr_ ] :=
> >     With[ { head }, Let[ { tail }, expr ] ]
> 
> Or did I miss something?

I don't know.

When I run

  Let[ { head, tail }, expr ]

then first

  Let[ { head_, tail__(_) }, expr_ ]

matches and gives

  With[ { head }, Let[ { tail }, expr ] ]

Now, in my case

  Let[ { head_ }, expr ]

matches and gives finaly

  With[ { head }, With[ { tail }, expr ] ]

after two steps.

In the other case

  Let[ { head_, tail___ }, expr_ ]

matches again and gives

  With[ { head }, With[ { tail }, Let[ { }, expr ] ]  .

Now,

  Let[ { }, expr_ ]

has to match, to transform this finally to

  With[ { head }, With[ { tail }, expr ] ]

after three steps.

In my case, I actually wouldn't need to have the rule for

  Let[ { }, expr_ ]

in.  I just put it as backup incase it would somehow actually occour in
an automated process.

I don't know how Mathematica internally works and if it is worth buying
one step less transformation by adding another rule (or to do it at
all).  However, when I understood this right, it shouldn't matter wether
the rule for

  Let[ { }, expr_ ]

is in or not, when it is on the last position, since the others get
checked before.

So, that's probably a good point to rearrange the rules to

  (l_ := Let[ v_, x_ /; c_ ]) ^:= Let[ v, l := x /; c ]
  Let[ { h_, t__ }, x_ ] := With[ { h }, Let[ { t }, x ]
  Let[ { h_ }, x_ ] := With[ { h }, x ]
  Let[ { }, x_ ] := x

then the less likely get checked less often (probably).

BTW: Has someone a clue why Mathematica tries UpRules always before
DownRules?  Does this make sense?  Or is it just a wrong impression of
mine?

Bastian


  • Prev by Date: Re: Questions about assumptions
  • Next by Date: Re: Determine if a parameter is a function
  • Previous by thread: Re: Add syntax highlighting to own command
  • Next by thread: Re: Add syntax highlighting to own command