May 2020
Intermediate to advanced
544 pages
12h 57m
English
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/shecho '#!/bin/sh' > program1for i in $(sequence 500)doecho "echo $i" >> program1donechmod +x program
As you can see, the preceding program creates another program, programs, which prints numbers 1-500.
Read now
Unlock full access