Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write code to write code?

Tags:

theory

I've heard that there are some things one cannot do as a computer programmer, but I don't know what they are. One thing that occurred to me recently was: wouldn't it be nice to have a class that could make a copy of the source of the program it runs, modify that program and add a method to the class that it is, and then run the copy of the program and terminate itself. Is it possible for code to write code?

like image 726
Ziggy Avatar asked Oct 30 '08 16:10

Ziggy


3 Answers

If you want to learn about the limits of computability, read about the halting problem

In computability theory, the halting problem is a decision problem which can be stated as follows: given a description of a program and a finite input, decide whether the program finishes running or will run forever, given that input.

Alan Turing proved in 1936 that a general algorithm to solve the halting problem for all possible program-input pairs cannot exist

like image 114
Paul Dixon Avatar answered Sep 18 '22 23:09

Paul Dixon


Start by looking at quines, then at Macro-Assemblers and then lex & yacc, and flex & bison. Then consider self-modifying code.

Here's a quine (formatted, use the output as the new input):

#include<stdio.h>

main()
{
  char *a = "main(){char *a = %c%s%c; int b = '%c'; printf(a,b,a,b,b);}";
  int b = '"';
  printf(a,b,a,b,b);
}

Now if you're just looking for things programmers can't do look for the opposite of np-complete.

like image 21
dlamblin Avatar answered Sep 19 '22 23:09

dlamblin


Sure it is. That's how a lot of viruses work!

like image 25
Tony Andrews Avatar answered Sep 18 '22 23:09

Tony Andrews