Original Post
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:
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 javascript could be pretty cool.<br><br>I don't know, I'm just thinking out loud at this point. =p
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 javascript could be pretty cool.<br><br>I don't know, I'm just thinking out loud at this point. =p