Advertisement

Macro System

Started by June 26, 2010 09:41 AM
1 comment, last by _orm_ 14 years, 5 months ago
One thing I have noticed with many other scripting languages is their built in support for either anonymous functions, macros, or both. Lisp is a perfect example of a language that includes a true macro system. However, for a language like lisp, a true macro system is easy since all forms evaluate into something, ie: the following code can be run in Lisp, (+ 2 2), and the REPL will spit out 4. I think something like this could be a great addition to the language as it will allow us to add to the languages already numerous features.

I was thinking of a syntax like this:

macro foo(int bar) // like macros in C, no return type specified, but the paramaters are type checked.{    2+2+bar // this code is inserted wherever foo is found}


The code inside the macros scope would, of course, have to be left unchecked, but the advantage this would have over C macros is that the engine knows about the macro, knows where it is called, and can tell you whether you used the macro wrong or the syntax of the macro itself could be wrong. Macros that are called recursively or are called by other macros could in effect lead to a code-that-writes-code scenario, much like is seen in Common Lisp.

As for anonymous functions and structures, something like is found in Lua and &#106avascript could be pretty cool.<br><br>I don't know, I'm just thinking out loud at this point. =p
Macros are cool, especially when part of the language itself rather than a preprocessing step as it is in C/C++. I'll add this topic to my to-do list, but it will definitely be a very low priority item.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
Yeah, I kinda figured it'd be low on the list. Still a good thing to think about though.

This topic is closed to new replies.

Advertisement