G
Gremlin
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 / sizeof *quine); ++c){",
" if(quine[c]=='\"' || quine[c]=='\\'){",
" cout <<\"\\\";",
" }",
" cout<<self[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 / sizeof *quine); ++c){
if(quine[c]=='"' || quine[c]=='\\')
cout <<"\\";
cout<<quine[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*/
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 / sizeof *quine); ++c){",
" if(quine[c]=='\"' || quine[c]=='\\'){",
" cout <<\"\\\";",
" }",
" cout<<self[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 / sizeof *quine); ++c){
if(quine[c]=='"' || quine[c]=='\\')
cout <<"\\";
cout<<quine[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*/