

Try JavaScript macro expansion using Sweet.js in the browser - joubert
http://voila.github.com/sweet.js/

======
wging
I get a

    
    
        TypeError: Cannot call method 'getValue' of undefined
    

on the last example. Running Chrome on OS X.

~~~
tolmasky
The last couple of examples appear to be offset by one (with a middle example
apparently missing), and thus the last one tries to run nothing.

------
jonahkagan
Someone should implement CoffeeScript as macros. That would get everyone's
attention.

~~~
jlongster
No, that would get all the CoffeeScripters attention. I believe it is slated
though.

I much prefer raw javascript + macros. In my opinion it kind of negates some
of point of coffeescript since you can implement the few key syntax
improvements.

~~~
jonahkagan
Yeah, that's a good point, but if you got all the CoffeeScripters' attention
and then showed them that CoffeeScript is just one _possible_ improved
syntax...

------
joshguthrie
>> man sed

Here are the best macros the world's got to offer. Not as good as C macros,
but still nice.

------
dotborg
that's not the direction language and programmers should follow

~~~
tikhonj
What exactly do you mean? Macros seem like a good way to solve many of
JavaScript's syntactic shortcomings while maintaining backwards-compatibility.

Now, macros do have some shortcomings. I've used Racket (a variant of Scheme)
a fair bit, and I'm now very wary of using macros too much. However, when they
_are_ useful, I've found they're _very_ useful: writing the same program in a
language without macros would often be extremely awkward.

Of course, if you're willing to entertain radical changes to your language,
you can get many of the benefits of macros with a minimalist syntax, laziness
and a simple mechanism for controlling how statements get evaluated. Which
ultimately just amounts to Haskell. And I've even found good use cases for
macros in Haskell, albeit far less than in any other language.

~~~
dotborg
I see at least two problems:

\- debugging such code is a nightmare(node.js itself makes it hard enough)

\- static analysis of such code is not possible.. yet?

JS and programmers should target Java-like experience imo, static analysis,
code assist, dependency check - all of it performed on-the-fly. We won't get
it by creating yet another layer above main language, because IDE vendors
simply can't cope.

~~~
jlongster
Javascript is a dynamic language. And especially one that is difficult to do
static analysis on. We get much more out of macros than we would with some
attempts at static analysis, when it comes to programmer productivity in the
end.

~~~
dotborg
problem of static analysis in JS code is difficult, yet it's worth to solve,

coolness of JS and safety of static analysis, that would be great

macros are just lame workaround:)

