Computer programs that write or manipulate other programs (Metaprogramming)

Imagine a guy who builds cars. When he building a new car he’s always doing the same thing, more or less. So he builds factory to build cars, and it’s much better.
Now he wants to build new types of cars. Easiest way to do this is, creating new factory for each new type of cars. Now he decides to build factories that build factories that build cars. That’s metaprogramming.

In programming perspective,

Lets assume you wants to write shell script that will echo number one.

#!/bin/sh
# program
echo "1"

Then you wants a shell script that will echo number 2, and another shell script for echo number 3 and so on until 1000. You can write each shell script by manually or you can write shell script which will write a all those 1000 programs as following script (which is a meta program).

#!/bin/sh
# metaprogram
echo '#!/bin/sh' >program
for I in $(seq 1000)
do
echo "echo $I" >> program
done
chmod +x program

Advertisements

One thought on “Computer programs that write or manipulate other programs (Metaprogramming)

  1. Sinhe the admi of ths web site is working, no doubt vewry rapidly it will be famous, duue to its qulity contents.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s