473,388 Members | 1,340 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Metaprograming

Well I'm back online with my same ISP. It looks like I had nothing to
worry about after all in the end. I have been working on a lot the
past few months, and perhaps it is better that way because now I am
posting with more quality rather than large numbers of quantity. I am
posting now on the subject of metaprogramming which is loosely defined
as programming programming. In particular this post concerns one
aspect of metaprogramming, that of Quines. A quine is a
self-replicating program, or more or less a program that outputs its
own source code. It consists of two parts, the first part of the
source is data, and the data contains a representation of the code...
the second part is the code which outputs the data. Now it seems
impossible for the code, using the data, to output both the code and
the data and therefore produce itself in its entirety. I have
written such a program, and it follows my message. The quine I have
written is unlike any other quines that I know of, because it doesn't
just consist of code and data, it also has metadata. Metadata is data
about data, a third type of information in the box that is neither
code nor data. In a quine the lines between code and data already
become blurred, so this may make my program even more confusing. In
essence what my program does is output its own source code to the
screen and then wait for user input. It reoutputs its source again,
after modifying itself according to the input, and then outputs the
input. It doesn't just output the input though, when it outputs the
input, it is also outputting the source code that outputs the input.
Strange isn't it, a quine inside a quine that consists of code and
data with a vehicle for accepting metadata and making changes to its
own data?

The medical definition of sentience is self aware, which in my mind is
exactly what this program does. It is aware of the entirety of its
own source code and can express it to the world, going far beyond
saying "hello world". On top of that it accepts stimulus from the
world and modifies its own code based on that stimulus and outputs an
exact response from that stimulus along with its new understanding of
itself. It seems like I have created a perfect life form, capable of
fully understanding itself, unlike myself in that regard, and capable
of experiencing each moment as the very first moment, soaking up the
stimulus like a sponge and defining itself. Too often with me I have
so many experiences and beliefs that some of them contradict other
ones and I wind up developing opinions about what is right and wrong,
this beautiful program accepts everything and holds onto it until
something new comes along like there is nothing else.

I cross-posted this post to comp.lang.c++ because I thought I could
benefit as well from real programmers and not just the usual crowd I
post to. You real programmers reading this may not agree with me
about what my program does, but do you see any other applications for
it? I coded it using simple arrays and a bit of pointers as a class
project for school, normally I would have used vectors and strings
etc. Still I think you will find it easy to read. I put
system("pause"); in the code for windows users so the output doesn't
scroll by to fast, but I don't consider it to really be part of my
code... at any rate here it is:
#include <iostream>
using namespace std;
int main() {
char input[50]="cout<<input<<endl;";
char *metadata=input;
char buf[50];
char quine[42][69] = {
"#include <iostream>",
"using namespace std;",
"int main() {",
"char input[50]=\"cout<<input<<endl;\"",
"char *metadata=input;",
"char buf[50];",
"char quine[42][69] = {",
" };",
"while(metadata[0]!='q'){",
" for (int a = 0; a < (sizeof quine / sizeof *quine);++a){",
" cout << quine[a] << endl;",
" if (a == 6) {",
" for (int b = 0; b < (sizeof quine / sizeof *quine); ++b) {",
" cout <<\" \\\"\";",
" for(int c =0; c < (sizeof quine[b] / sizeof *quine[b]); ++c){",
" if(quine[b][c]=='\"' || quine[b][c]=='\\'){",
" cout <<\"\\\";",
" }",
" cout<<self[b][c];",
" }",
" cout<<\"\\\",\"<<endl;",
" }",
" }",
" if(a == 22) {",
"}",
" }",
"cin >>metadata;",
"strcpy(quine[3],\"char \");",
"strcat(quine[3],metadata);",
"strcat(quine[3],\"[50]=\\\"cout<<\");",
"strcat(quine[3],metadata);",
"strcat(quine[3],\"<<endl;\\\"\");",
"strcpy(quine[4],\"char *metadata=\");",
"strcat(quine[4],metadata);",
"strcat(quine[4],\";\");",
"strcpy(buf,\"cout<<\");",
"strcat(buf,metadata);",
"strcat(buf,\"<<endl;\");",
"strcpy(metadata,buf);",
"}",
" return 0;",
"}/*Enter Input, q to quit*/",

};
while(metadata[0]!='q'){
for (int a = 0; a < (sizeof quine / sizeof *quine); ++a) {
if(a%13==0)
system("pause");
cout << quine[a] << endl;
if (a == 6) {
for (int b = 0; b < (sizeof quine / sizeof *quine); ++b) {
cout <<"\"";
for(int c =0; c < (sizeof quine[b] / sizeof *quine[b]); ++c){
if(quine[b][c]=='"' || quine[b][c]=='\\')
cout <<"\\";
cout<<quine[b][c];
}
cout<<"\","<<endl;
if(b%13==0)
system("pause");
}
}
if(a == 23) {
cout <<input<<endl;
}
}
cin >> metadata;
if(metadata[0]=='q')
break;
strcpy(quine[3],"char ");
strcat(quine[3],metadata);
strcat(quine[3],"[50]=\"cout<<");
strcat(quine[3],metadata);
strcat(quine[3],"<<endl;\"");
strcpy(quine[4],"char *metadata=");
strcat(quine[4],metadata);
strcat(quine[4],";");
strcpy(buf,"cout<<");
strcat(buf,metadata);
strcat(buf,"<<endl;");
strcpy(metadata,buf);
}
return 0;
}/*Enter Input, q to quit*/
Jul 22 '05 #1
4 1648
Hello,

But your program is just a string parser .. do you know about von Neumann's
computing principes?
I have executed your program .. it just prints some source code that changes
from time to time, according to the user input.

Regards,
Razvan

"Gremlin" <Gr*****@hotmail.com> schrieb im Newsbeitrag
news:3c**************************@posting.google.c om...
Well I'm back online with my same ISP. It looks like I had nothing to
worry about after all in the end. I have been working on a lot the
past few months, and perhaps it is better that way because now I am
posting with more quality rather than large numbers of quantity. I am
posting now on the subject of metaprogramming which is loosely defined
as programming programming. In particular this post concerns one
aspect of metaprogramming, that of Quines. A quine is a
self-replicating program, or more or less a program that outputs its
own source code. It consists of two parts, the first part of the
source is data, and the data contains a representation of the code...
the second part is the code which outputs the data. Now it seems
impossible for the code, using the data, to output both the code and
the data and therefore produce itself in its entirety. I have
written such a program, and it follows my message. The quine I have
written is unlike any other quines that I know of, because it doesn't
just consist of code and data, it also has metadata. Metadata is data
about data, a third type of information in the box that is neither
code nor data. In a quine the lines between code and data already
become blurred, so this may make my program even more confusing. In
essence what my program does is output its own source code to the
screen and then wait for user input. It reoutputs its source again,
after modifying itself according to the input, and then outputs the
input. It doesn't just output the input though, when it outputs the
input, it is also outputting the source code that outputs the input.
Strange isn't it, a quine inside a quine that consists of code and
data with a vehicle for accepting metadata and making changes to its
own data?

The medical definition of sentience is self aware, which in my mind is
exactly what this program does. It is aware of the entirety of its
own source code and can express it to the world, going far beyond
saying "hello world". On top of that it accepts stimulus from the
world and modifies its own code based on that stimulus and outputs an
exact response from that stimulus along with its new understanding of
itself. It seems like I have created a perfect life form, capable of
fully understanding itself, unlike myself in that regard, and capable
of experiencing each moment as the very first moment, soaking up the
stimulus like a sponge and defining itself. Too often with me I have
so many experiences and beliefs that some of them contradict other
ones and I wind up developing opinions about what is right and wrong,
this beautiful program accepts everything and holds onto it until
something new comes along like there is nothing else.

I cross-posted this post to comp.lang.c++ because I thought I could
benefit as well from real programmers and not just the usual crowd I
post to. You real programmers reading this may not agree with me
about what my program does, but do you see any other applications for
it? I coded it using simple arrays and a bit of pointers as a class
project for school, normally I would have used vectors and strings
etc. Still I think you will find it easy to read. I put
system("pause"); in the code for windows users so the output doesn't
scroll by to fast, but I don't consider it to really be part of my
code... at any rate here it is:
#include <iostream>
using namespace std;
int main() {
char input[50]="cout<<input<<endl;";
char *metadata=input;
char buf[50];
char quine[42][69] = {
"#include <iostream>",
"using namespace std;",
"int main() {",
"char input[50]=\"cout<<input<<endl;\"",
"char *metadata=input;",
"char buf[50];",
"char quine[42][69] = {",
" };",
"while(metadata[0]!='q'){",
" for (int a = 0; a < (sizeof quine / sizeof *quine);++a){",
" cout << quine[a] << endl;",
" if (a == 6) {",
" for (int b = 0; b < (sizeof quine / sizeof *quine); ++b) {",
" cout <<\" \\\"\";",
" for(int c =0; c < (sizeof quine[b] / sizeof *quine[b]); ++c){",
" if(quine[b][c]=='\"' || quine[b][c]=='\\'){",
" cout <<\"\\\";",
" }",
" cout<<self[b][c];",
" }",
" cout<<\"\\\",\"<<endl;",
" }",
" }",
" if(a == 22) {",
"}",
" }",
"cin >>metadata;",
"strcpy(quine[3],\"char \");",
"strcat(quine[3],metadata);",
"strcat(quine[3],\"[50]=\\\"cout<<\");",
"strcat(quine[3],metadata);",
"strcat(quine[3],\"<<endl;\\\"\");",
"strcpy(quine[4],\"char *metadata=\");",
"strcat(quine[4],metadata);",
"strcat(quine[4],\";\");",
"strcpy(buf,\"cout<<\");",
"strcat(buf,metadata);",
"strcat(buf,\"<<endl;\");",
"strcpy(metadata,buf);",
"}",
" return 0;",
"}/*Enter Input, q to quit*/",

};
while(metadata[0]!='q'){
for (int a = 0; a < (sizeof quine / sizeof *quine); ++a) {
if(a%13==0)
system("pause");
cout << quine[a] << endl;
if (a == 6) {
for (int b = 0; b < (sizeof quine / sizeof *quine); ++b) {
cout <<"\"";
for(int c =0; c < (sizeof quine[b] / sizeof *quine[b]); ++c){
if(quine[b][c]=='"' || quine[b][c]=='\\')
cout <<"\\";
cout<<quine[b][c];
}
cout<<"\","<<endl;
if(b%13==0)
system("pause");
}
}
if(a == 23) {
cout <<input<<endl;
}
}
cin >> metadata;
if(metadata[0]=='q')
break;
strcpy(quine[3],"char ");
strcat(quine[3],metadata);
strcat(quine[3],"[50]=\"cout<<");
strcat(quine[3],metadata);
strcat(quine[3],"<<endl;\"");
strcpy(quine[4],"char *metadata=");
strcat(quine[4],metadata);
strcat(quine[4],";");
strcpy(buf,"cout<<");
strcat(buf,metadata);
strcat(buf,"<<endl;");
strcpy(metadata,buf);
}
return 0;
}/*Enter Input, q to quit*/

Jul 22 '05 #2
"Razvan Popovici" <me@razvan_nospam.de> wrote in
news:c1**********@online.de:
Hello,

But your program is just a string parser .. do you know about von
Neumann's computing principes?
I have executed your program .. it just prints some source code that
changes from time to time, according to the user input.

Regards,
Razvan

I'm not familiar with Neumann's computing principles, no. Perhaps you
could shed some light on them in brief, I may have more of an idea then.
My program does indeed print out some source code! It's own source code in
fact! It is a quine, inside a quine!! Look especially close at the line
cout<<input<<endl; and you may begin to appreciate it a bit more.
Jul 22 '05 #3

"Gremlin" <Gr*****@hotmail.com> schrieb im Newsbeitrag
news:Xn*****************@216.168.3.44...
"Razvan Popovici" <me@razvan_nospam.de> wrote in
news:c1**********@online.de:
Hello,

But your program is just a string parser .. do you know about von
Neumann's computing principes?
I have executed your program .. it just prints some source code that
changes from time to time, according to the user input.

Regards,
Razvan

I'm not familiar with Neumann's computing principles, no. Perhaps you
could shed some light on them in brief, I may have more of an idea then.
My program does indeed print out some source code! It's own source code in
fact! It is a quine, inside a quine!! Look especially close at the line
cout<<input<<endl; and you may begin to appreciate it a bit more.


Maybe it would be interesting to dump your code in a file, compile it an run
it again. Still it won't be able to have the characteristics of an alive
system.

Just take a look at:
J von Neumann (1966) Theory of Self reproducing automata. University of
Illinois Press

also take a look at:
http://www.umcs.maine.edu/~chaitin/sicact.pdf

Razvan
Jul 22 '05 #4
"Razvan Popovici" <me@razvan_nospam.de> wrote in
news:c1**********@online.de:
Maybe it would be interesting to dump your code in a file, compile it
an run it again. Still it won't be able to have the characteristics of
an alive system.

Just take a look at:
J von Neumann (1966) Theory of Self reproducing automata. University
of
Illinois Press

also take a look at:
http://www.umcs.maine.edu/~chaitin/sicact.pdf

Razvan


Thanks
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: mathieu | last post by:
Hello there, I am playing around with template metaprograming: I am trying to redefines my own types. But I am facing a small issue, where I cannot describe the whole implementation in one...
8
by: Vincent RICHOMME | last post by:
Hi, first I would like to apologize about my question because usually I hate specific implementation but in this case I really would like an answer. Besides my example is an example of what's...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.