MathGroup Archive 2009

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

Search the Archive

Add syntax highlighting to own command

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101539] Add syntax highlighting to own command
  • From: earthnut at web.de (Bastian Erdnuess)
  • Date: Thu, 9 Jul 2009 02:00:14 -0400 (EDT)

I was missing a scoping construct like 'With' but where the local
variables get assigned linearly.  E. g.

  In[1] := LinearWith[ {
               a = "Hi, ",
               b = a <> "there!" },
             Print[ b ] ]

  Out[1] = "Hi, there!"  .

I'm fairly new to Mathematica, but I know some Lisp, and somehow I got
it.  I called my new construct Let and defined it as:

  Let[ vars_, expr_ ] :=
    If[ Length[ Unevaluated[ vars ] ] == 1,
      With[ vars, expr ],
    (* else *)
      Unevaluated[ vars ] /.
        { a_, b__ } :>
          With[ { a },
            Let[ { b }, expr ] ] ]

  SetAttributes[ Let, HoldAll ]

It seems to work fine so far.

Now, I would like to have this construct load always when I start
Mathematica and I don't want to get it cleared when I use
'Clear["Global`*"]'.  So I put it in the System` context and also added
the attribute 'Protected'.  I wrote all in a file Let.m and now, I
wonder where to put it that it gets read automatically at each startup
of Mathematica.

However, my first question: Is it a bad idea to add things to the
System` context?  And if not, where to put my file?  And if, what would
be better?

Second, my main question: Is it somehow possible to add this nice syntax
highlighting to the Let construct like with the With construct, where
the local variables appear in green?

Third: Can I somehow add a help page?  I have already the Let::usage.

And last: Does anybody know how to make the construct better?  Is there
something like syntax transformation rules in Mathematica?

Thank you for your answers,
Bastian


  • Prev by Date: Re: Jens-Peer Kuska passed away
  • Next by Date: Re: Manipulating list
  • Previous by thread: Re: Problem with nested StringReplace[]
  • Next by thread: Re: Add syntax highlighting to own command