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: [mg101659] Re: Add syntax highlighting to own command
  • From: Simon <simonjtyler at gmail.com>
  • Date: Sun, 12 Jul 2009 06:58:47 -0400 (EDT)
  • References: <200907090600.CAA17547@smc.vnet.net> <h3766u$f9h$1@smc.vnet.net>

Hi everyone,

An interesting discussion!
I've also on occasion wanted a similar construct, although the replace
all inside the definition is, as Leonid says, clever, it just didn't
sit well with me.
Ultimately using a Fold construct would be the nicest, but passing
unevaluated arguments around isn't always so simple -- the following
code works, but is definitely not pretty.

ClearAll[Let]; SetAttributes[Let, HoldAll];
Let[sp : {a__Set}, expr_] := Quiet[ReleaseHold@Fold[With[{#2}, #1] &,
Hold@expr, Reverse[Hold /@ Unevaluated@sp]], With::"lvw"]

The simplest code I could come up with was the following:

ClearAll[Let]; SetAttributes[Let, HoldAll];
Let[{}, expr_] := expr
Let[{a_, b___}, expr_] := With[{a}, Let[{b}, expr]]

the nice thing about it is that all of the error handling is passed
through to With properly (just like Bastian's original code).

Thanks Peter for pointing out the SyntaxInformation command, that's a
handy one to know.  Do you have any ideas how to get the syntax
highlighting working properly as well?  (the constructions in the
documentation centre weren't very enlightening for this case).

Simon

PS
A quick google brought up this, very similar discussion
http://www.mathkb.com/Uwe/Forum.aspx/mathematica/15031/A-version-of-With-that-binds-variables-sequentially
(it's scary how close my Fold construct is to the one that rych
proposed...)


  • Prev by Date: Re: Add syntax highlighting to own command
  • Next by Date: Re: Add syntax highlighting to own command
  • Previous by thread: Re: Add syntax highlighting to own command
  • Next by thread: Re: Add syntax highlighting to own command