[QUOTE=nullsquared;14290040]Use recursion. Think of each piece of code as its own runnable piece. When you encounter a loop, that's another runnable piece within the upper 'parent' piece. It'd recurse like so:
[code]
run [whole]
// encounter loop
run [loop 0]
// encounter another loop
run [loop 1]
// end condition not met, keep run this loop again and again
run [loop 1]
...
// end condition not met, run this loop again and again
run [loop 0]
..
// end condition for loop 0 is met, continue execution wherever loop 0 left off
[/code]
Notice how each iteration of the loop recurses if the loop must go on. There's no iteration or anything.[/QUOTE]
Okay thanks that helped alot. I think I'm going to need to re-write my code.
[QUOTE=iPope;14302251]Okay thanks that helped alot. I think I'm going to need to re-write my code.[/QUOTE]
Do [B]not[/B] use recursion for implementing a loop. It's stupid and wrong.
[QUOTE=jA_cOp;14309894]Do [B]not[/B] use recursion for implementing a loop. It's stupid and wrong.[/QUOTE]
At a (small) size of 1MB stack size, you get 1048576 bytes to use before you overflow. I'm sure that's enough for brainfuck programs. Besides, my version only enters a level of recursion per loop, not per loop iteration. Each loop iteration is a recursive separate call from the parent block. Therefore, you'll have to nest ... [i]quite[/i] a lot of loops to overflow.
[QUOTE=nullsquared;14310226]At a (small) size of 1MB stack size, you get 106496 bytes to use before you overflow. I'm sure that's enough for brainfuck programs. Besides, my version only enters a level of recursion per loop, not per loop iteration. Each loop iteration is a recursive separate call from the parent block. Therefore, you'll have to nest ... [i]quite[/i] a lot of loops to overflow.[/QUOTE]
That doesn't make it any less of an inferior solution in any aspect.
[QUOTE=nullsquared;14310226]At a (small) size of 1MB stack size, you get 106496 bytes to use before you overflow. I'm sure that's enough for brainfuck programs. Besides, my version only enters a level of recursion per loop, not per loop iteration. Each loop iteration is a recursive separate call from the parent block. Therefore, you'll have to nest ... [i]quite[/i] a lot of loops to overflow.[/QUOTE]
Actually I believe it depends on the app.
Firefox only allocates 0x3000 (12288) bytes for the stack. While this random .net app I have allocated 0xA000 (40960) bytes.
Anyways, where are you getting 106496 bytes from 1mb?
(also, I'm not disagreeing. I think recursion is perfectly fine and a good way to do it. My code actually uses recursion in the parsing the loops)
[QUOTE=jA_cOp;14310292]That doesn't make it any less of an inferior solution in any aspect.[/QUOTE]
In what way is it inferior?
[QUOTE=high6;14310421]Actually I believe it depends on the app.
Firefox only allocates 0x3000 (12288) bytes for the stack. While this random .net app I have allocated 0xA000 (40960) bytes.
[/quote]
Well, either way, 1MB was an example.
[quote]
Anyways, where are you getting 106496 bytes from 1mb?
[/quote]
Woops, should be 1048576.
How is it a bad solution? If you're not creating craploads of variables within the function there shouldn't be any problem.
brainfuck is a simple language, keeping your own stack frames for every nested loop should be much better than expanding the host language's stack, which would use more memory too if you're passing arguments or creating local variables.
If I read you correctly nullsquared, your method also suggested making a call for every loop iteration (not recursively, of course), which is more unessecary bloat compared to a 'while' loop, or for(;;) with your own condition.
If you want the convenience of the simplicity of recursion implementing a loop, try to make it tail recursion, that will make for some really good code generation compared to normal recursion or a complex system of keeping your own stack.
[QUOTE=jA_cOp;14317683]brainfuck is a simple language, keeping your own stack frames for every nested loop should be much better than expanding the host language's stack, which would use more memory too if you're passing arguments or creating local variables.
[/quote]
My version uses 24 bytes per call. Tell me when you get to 1024^2 bytes (in the case of a relatively small stack).
[quote]
If I read you correctly nullsquared, your method also suggested making a call for every loop iteration (not recursively, of course), which is more unessecary bloat compared to a 'while' loop, or for(;;) with your own condition.
[/quote]
Running a loop will require you to run the loop code using the same function anyway. My way simply avoids the loop - each 'loop-run-code' returns the index to continue from - if the current value is not 0, then this loop body is run again; this is basically your described 'while' loop method, just without the 'while'.
Invalid File. This error has been forwarded to MediaFire's development team.
It'll be back sometimes soon, but *god* you didn't have to bump such and old thread...
Whoops, sorry.
Sorry, you need to Log In to post a reply to this thread.