Arc Forumnew | comments | leaders | submitlogin
Javascript scope context coloring for CodeMirror (github.com)
3 points by akkartik 4542 days ago | 4 comments


2 points by rocketnia 4542 days ago | link

Wow, this makes a lot of sense, and I don't think I've ever heard of it before. I wonder how the pursuit this feature could impact the design of a language's macro system.

Less optimistically, I wonder whether it'll distract too much from meaningful patterns that span across nesting levels (e.g. imperative code in continuation-passing style).

-----

2 points by akkartik 4542 days ago | link

"I wonder how the pursuit of this feature could impact the design of a language's macro system."

Whoa, how do you mean?

One idea I've been thinking about a lot is to attach metadata to code. We can do a lot to code (pretty-print, optimize, ...) besides just eval it, and metadata might help with those without affecting eval.

My favorite use for this idea is to give functions levels:

  def (foo x y) :(level 3)
    34
(This is the 'other idea' for colons I referred to at http://www.arclanguage.org/item?id=17358, but I suck at surprises ^_^)

This can be used in a variety of ways by different tools. You could flag as errors any calls from a lower to a higher level, so that level 3 functions could only call functions in levels 1-3. You could tell tracers to trace everything until level x, not below. You could tell debuggers to automatically step past calls below level x and step _into_ calls above that level. In gdb I often accidentally hit 'next' when I meant 'step', and now I have to restart and laboriously try again from scratch.

You could syntax-highlight calls within a level to be more salient to calls to lower levels. We've all seen open source projects with this structure.

  void main() {into 
    ...  // lots of option parsing crap
    if (doSomething()) { // the actual app code
       ... // more crap
    }
    ... // more crap
    return -1;
  }
Here wouldn't it be cool to be able to highlight the doSomething() compared to all the other calls?

In general, syntax highlighting sucks[1] because we simply highlight the things it's easiest to infer. Metadata might help reduce the inference burden and open up new uses for color.

[1] http://arclanguage.org/item?id=16488

-----

3 points by rocketnia 4542 days ago | link

"Whoa, how do you mean?"

If we syntax-highlight (withs ...) this way, since it expands into several (fn ...) forms it'll give a different color to each of its variables. But that's assuming we're able to perform some amount of macroexpansion frequently enough to be useful as the programmer edits, and it also assumes we can relate the original syntax to the transformed version returned by the macro.

It would be interesting to see a macro system tailor-made for purposes like these. Some hygienic macro systems might already apply, but I wonder what the options are here. I think Reactive Demand Programming would be an effective ingredient for this kind of incremental program visualization, but that's not a complete plan on its own.

-----

2 points by Pauan 4541 days ago | link

Fun fact: if you used boxes, it would be really easy to associate the "withs" form with its expanded form, since the boxes would be the same.

The Nulan IDE already incrementally macroexpands as you're typing, and syntax-highlights boxes different colors depending on their scope. So this would be fairly trivial to add in.

-----