9
$\begingroup$

Lately I've been working quite a lot with Compile. I also started using Wolfram Workbench.

So a natural question arises: Is it possible to have syntax highlighting for local variable variables inside compile as well? Here is a screenshot demonstrating the problem. Notice the blue x's in the lower right hand side of the image? These should be green.

Screenshot

I didn't manage to find anything under the preferences. I'm using WB 2.0

$\endgroup$
4
  • 1
    $\begingroup$ Someone from WRI has to answer/fix this. In the meanwhile I would just use a simple trick and put a Block around, e.g.: cf = Block[ {x}, Compile[{{x, _Real}}, Sin[x] + x^2 - 1/(1 + x)] ] $\endgroup$ Jan 21, 2013 at 10:44
  • $\begingroup$ @RolfMertig That's actually not a bad idea. Does this have any performance or any other side effects? $\endgroup$
    – Ajasja
    Jan 21, 2013 at 12:34
  • $\begingroup$ no, it just evaluates to its body, so all is good. $\endgroup$ Jan 21, 2013 at 12:38
  • $\begingroup$ @RolfMertig Could you put that as an answer? I think this is what I'll end up doing. $\endgroup$
    – Ajasja
    Jan 21, 2013 at 12:45

2 Answers 2

6
+50
$\begingroup$

Until (when, WRI??) there will be an update of WWB (which certainly will also fix other shortcomings and bugs) just use Block to get the coloring right:

Mathematica graphics

$\endgroup$
4
$\begingroup$

As far as I know, you cannot change this. I cannot exactly say how it works in Eclipse, but usually the highlighting process consists of several steps. Basic highlighting can be provided after the lexical analysis. For a context sensitive highlighting like the one for local variables inside Module, Block, Function or in your case Compile, you need to parse the input.

If you are using the Workbench plugin for Eclipse, you can at least get an idea where and how this is implemented. In the plugins directory (in OSX) inside your Eclipse installation path you should find directories for the Wolfram plugin. If you dig a bit in the lib directory there, you'll find that an antlr parser was created to parse Mathematica code. With the help of this parser highlighting and error/warning features are implemented and provided for Eclipse inside the MEET.jar.

To change the behaviour for Compile, you would have to change it inside the MEET code which you don't have access to since the jar files contain (almost) only byte-code.

$\endgroup$
1
  • $\begingroup$ Yes, I did manage to get that far and even got a look inside using java.decompiler.free.fr/?q=jdgui, but then I got totally lost... $\endgroup$
    – Ajasja
    Jan 21, 2013 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.