Coding Evolution

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums

Coding Evolution

Postby dhnhatthe » Thu Aug 13, 2015 9:33 am

Hi at my school in my engineering computations class we were talking about programming a replica of the human mind. The problem was brought up that the computer will only run until the it runs out of code to read. My question is this. Is there a computing language that has the ability to write self sustaining code during execution? That is generate code dynamically based on parameters given at the start of the program? Would this be hard to implement?

If your still confused imagine you are riding the slope of a function of nth parameters and you do not know what the explicit function is but you have incite of what the gradient is 1 unit forward and back of your position.
Since we only know two points of the gradient in total space, writing loops initializing the start and end points will not work. However if we only initialize the beginning point and tell the computer to calculate the gradient of the line at the forward and backward positions in space we can then estimate the gradient of the line at the next point and compare this gradient to the gradient of the previous point and "guess" what the next value of the gradient would be. For this to happen the computer would have to make a choice of the best method to compare the two slopes and instead of explicitly writing if-then checks and outcomes we only write one if statement which is "the method that has the higher presidency is most likely to be the best method to choose". Logically at the start of the program we have given the computer starter methods to solve this problem and therefore the computer executes all of them and decides which is the best choice for this step. It then logs this choice out of the lists as having a higher success rate over the other methods and takes that into account at the next step. If we could then find a way for the computer to know if a choice it made is wrong we could tell it to backtrack and try again.

What do you guys think?
Last edited by dhnhatthe on Thu Nov 19, 2015 9:43 am, edited 1 time in total.
Posts: 1
Joined: Thu Aug 13, 2015 9:31 am

Re: Coding Evolution

Postby CuteAlien » Thu Aug 13, 2015 1:10 pm

Code is just data and any language can modify data. Self-modifying code means you have to get that data interpreted again (or compiled and run again which is pretty much the same in this context). The easiest languages to do this in are interpreted languages - especially in Lisp this is used a lot.

But you already start with a wrong premise. Programs don't stop because they run out of code. You can loop endlessly - this is pretty much what nearly every application you are using does. For example your web-browser. It doesn't stop at some point of time because it runs out of code. It runs until someone quits it. Or it crashes due a bug. Or someone puts out the power. Aside from that it could run to the end of times.

And that's likely also how your brain works. You don't have one endless thought that you think on and one from birth until you die. Instead your brain probably hangs around in an endless loop and once in a while starts processes which lead to a bit of thinking.

By the way self-modifying code is used already in some artificial intelligence algorithms. Genetic programming especially. And it's also important in a philosophical context. Because computers are Turing complete - and Turing complete means more or less it can run *any* math function out there as long as it has enough memory - and because programs can overwrite themselves it means - a program can rewrite itself to be any other program possible. Like the monkeys typing Shakespeare thing it might take a while.
IRC: #irrlicht on
Code snippets, patches&stuff:
Free racer created with Irrlicht:
User avatar
Posts: 8465
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Coding Evolution

Postby chronologicaldot » Thu Aug 13, 2015 5:29 pm

^ What he said. O_O
Or maybe the internal clock resets when the program depends on it. Hurray Unix end?

Since I insist on sticking my foot in my mouth at least once, let me add: I've found that it's faster just writing an algorithm dedicated to a job than trying to do, what is comparably, an inefficient AI, which will inevitably outdated for one reason or another in light of newer discoveries and tech. Not to say it isn't cool, though what is top-of-the-line-tech today will inevitably be outdated tomorrow, so every cool AI you come up with will leave you dissatisfied in the wake of someone else's advances.

There are some other tricky problems to overcome. Obviously, you can't rewrite the main while loop. You also have to decide which code can't be changed, since obviously, even if you could let it rewrite nearly everything, you don't want your program to erase itself out of existence (perhaps due to "testing" an optimization).
One way to do it without requiring a special interpreted language would be to write two programs: One to do all the rewriting in light of feedback and the other to be the final "product".

But I'm just tossing ideas out there.
User avatar
Competition winner
Posts: 556
Joined: Mon Sep 10, 2012 8:51 am

Re: Coding Evolution

Postby Cube_ » Fri Aug 14, 2015 12:45 pm

Exactly what CuteAlien said, now as for self modifying code; polymorphism does this to an extent but template metaprograming is a much better example, metaprogramming is the act of writing code that writes code; which to me sounds exactly like what you're looking for.
Incidentally template metaprogramming is turing complete (and it's merely a reasonably small subset of C++), technically though you could write self modifying code using functional programming so long the language is turing complete, the only real issue is not if but how; that's up to you to figure out though (I'm no AI guru, I couldn't help you even if I tried).

"Metaprogramming is the writing of computer programs with the ability to treat programs as their data. It means that a program could be designed to read, generate, analyse or transform other programs, and even modify itself while running."
That's wikipedias description of metaprogramming, regardless metaprogramming isn't the only solution, it's merely one of the more obvious ones.
"this is not the bottleneck you are looking for"
User avatar
Posts: 1011
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: Coding Evolution

Postby Dreadstew » Tue Mar 13, 2018 10:51 pm

I think the easiest way to write a self-generating program would be to have the main program generate code in a new file, run the compiler on it, then kick it off as a new process from the main program. Really interesting idea. I've thought about this before... skynet poop lol.
Posts: 11
Joined: Wed Apr 01, 2015 5:18 pm

Return to Game Programming

Who is online

Users browsing this forum: No registered users and 1 guest