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: [mg101665] Re: Add syntax highlighting to own command
  • From: earthnut at web.de (Bastian Erdnuess)
  • Date: Tue, 14 Jul 2009 05:32:44 -0400 (EDT)
  • References: <200907090600.CAA17547@smc.vnet.net> <h3766u$f9h$1@smc.vnet.net> <h3cfbl$ick$1@smc.vnet.net>

Simon <simonjtyler at gmail.com> wrote:

> 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.

Yes, I also like Daniels and your second solution better.

> 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"]

I understand that using the Fold construct should be the prefered way,
but this seems indeed to be a little bit to ugly for me.

> 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]]

I like this best.  It's also Daniels solution.  I think, I'm going to
use this code in MyToolBox.  Thank you.

> 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).

Dito.

> 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...)

That's what I found because of

"Is there a way to get syntax highlighting for WithMany?  I found the
SyntaxInformation stuff, but it doesn't seem to expose the
highlighting that's used for With, Module, or Block."

Bastian


  • Prev by Date: Re: ColorFunction and question about how to use it
  • Next by Date: (Updated) Mathematica Special Interest Group (Washington DC Area)
  • Previous by thread: Re: Add syntax highlighting to own command
  • Next by thread: Re: Add syntax highlighting to own command