Code center > Suggestions

Subfunctions

(1/5) > >>

Greven:
What about some kind of jump/goto/gosub-command? I know this will difficult to implement, but we some carefull thoughts, this could be very very powerfull to and making the genome more non-linear!!!??

Numsgil:
I've been thinking about adding sub functions and functions, and the like, and a major problem I can see is infinite loops.  If a sub calls itself, that is a recursive call, it could freeze the program.  Or if three functions call each other creating a loop.  Once we approach the possibility of loops alot of problems spring up that I don't know how to fix.

Greven:
I am against caps of any sort in DB, but sometimes it could be nessicary. We could say that a bot only can make x calls in any given cycle or make it cost a lot, so many would kill it? As you said in another thread, only time will let us get the optimal solution. (or something like it)

Numsgil:
We could prevent bots from calling sub functions from inside sub functions.  That is, limit the nesting capability to one level.

Or two levels, or three levels.  Probably three levels is good enough.  We can set it as a hard limit or chose a different method if we like, but three deep should be the limit.

So instead of X calls per cycle, you can only make X calls without reaching the end of the sub function.  That would work well I think.

Then the problem becomes how to address the new functions without drastic alterations to the DNA.  One solution I can see is 'storing' these functions in memory addresses.

Then if you do *600 you're not putting a memory location onto the stack, but making a call to a sub function.  Kind of like a pointer to a function in C, for people who are familiar with C.  That way mutations can get to existing sub functions easily enough.

You probably won't be able to overwrite sub function memory locations.  Or amybe you can and then you just lose that sub function in the nether regions of the bot's DNA.

On the other hand, it may or may not be biologically realistic.  Definately an interesting idea to explore.

Numsgil:
On to another topic, I've been looking at the possibility for subprograms.  I think the cost of calling a subprogram should be (Some user defined constant) * sum of (x^n/3^n) for n = 0 to 7 and x = how many calls you've made without returning - 1 (since we start at the 0th n).

So the first call costs 1 nrg.  The next call costs 1.5.  Then: 3, 8.6, 29,93.  The absolute maximum number of calls without returning you can make is 12.  The 13th call costs 47000 nrg, which is strictly impossible.

That ensures that infinite loops are impossible (assuming that the program checks for bot death before it gets to that point).  It also penalizes infinite loops without drastically hurting bots that just want to make a few calls without going deep into the tree.

Like this:

'this would assign a free memory location not taken
'by sysvars as a pointer to the sub function
def sub1 as function

REGULAR PROGRAM CODE
.sub1 call
REGULAR PROGRAM CODE
end

sub1 : 'this tells the program we're defining our sub function now
'Do some math
.sub1 *50 mult call
return '(or maybe end, or stop, or ret, I'm not sure about the syntax yet)
'returns us back to the segment of DNA that called us.

The bot would call sub1 somewhere in its DNA.  sub1 could then execute recursively for up to 12 loops before it would kill the bot.  It would stop if 50 is ever not zero (that would change where the call command is trying to call, and so the call command would fail.

However, if a bot sets 50 to 1 befoe making the calls, the bot could make up to 32000 calls (at 1 nrg each) since the sub function won't be executing other sub functions.

I'm not sure if sub functions should be able to put things on the stack, put things on the condition stack, or write to memory locations (or all of the above).

I could implement "call" as a 'jump to the xth DNA unit and place location in DNA on the calling stack' and "return" as 'jump back to the yth DNA unit where y is on the calling stack'.  Then the DNA is more likely to mutate to use it.

Also means the function pointer can be used as a regular custom variable.

Navigation

[0] Message Index

[#] Next page

Go to full version