2010年11月1日 星期一

Work Note and Metaprogramming

Work note
XML Profile Manager
Parameter Manager
to use hashing instead the sequential search

突然想到 LiuKen之前說過的 language sugar 的議題,
c++ 與 c 本身的限制讓需要做些手腳才能夠有類似 javascript 與 c# 等
metaprogramming 的能力.
Metaprogramming
http://en.wikipedia.org/wiki/Metaprogramming
Metaprogramming is the writing of computer programs that write or manipulate other programs (or themselves) as their data.

"generative programming"
#!/bin/bash
# metaprogram
echo '#!/bin/bash' >program
for ((I=1; I<=992; I++)) do echo "echo $I" >>program
done
chmod +x program

Not all metaprogramming involves generative programming. If programs are modifiable at runtime or if an incremental compilation is available (such as in C#, Forth, Frink, Groovy, JavaScript, Lisp, Lua, Perl, PHP, Python, REBOL,Ruby, Smalltalk, and Tcl), then techniques can be used to perform metaprogramming without actually generating source code.

網路上找到的範例: 用 c++ 去產生一個 source 然後編譯.

沒有留言: