Meta-programming

Meta-programming is a technique that allows computer programs to consider other programs as their input data. So, a program can be designed to read/write/modify other programs, or even itself. If a program simply reports on itself, this is known as introspection, while if the program modifies itself, this is known as reflection. A lot of languages support meta-programming PHP, Python, Apache Groovy, and compilers are some examples.

Let's try to further our understanding with an example:

#!/bin/sh
echo '#!/bin/sh' > program1

for i in $(sequence 500)

do

echo "echo $i" >> program1

done

chmod +x program

As you can see, the preceding program creates another program, programs, which prints numbers 1-500.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.45.92