Mozilla JavaScript sweetened


JavaScript developers to work with macros by Mozilla sweet.js be facilitated. To prevent the interaction between macro and normal code, the project expanded to include so-called JavaScript Hygienic macros, as they already exist in languages ​​like Scheme and Rust are. In this way, from C languages ​​are known problems can be prevented, for example, the use of variables is already programmed with macros.

In general, JavaScript can also customize your own needs through macros as an example on the project page shows:

macro def {
   case $ name: ident $ params $ body => {
     function $ name $ params $ body
   }
}
Here the function identifier function is replaced by the shorter def, so the compiler supplied sweet.js the following call

def sweet (a) {
   console.log ("Macros are sweet!");
}
to convert an ordinary function and so could make it readable for JavaScript runtime environments.

The source code of the compiler is available on Github; sweet.js uses Node.js. Since the project is still in its infancy, is likely to bugs.

No comments:

Post a Comment