lspector / Clojush

The Push programming language and the PushGP genetic programming system implemented in Clojure.
http://hampshire.edu/lspector/push.html
Eclipse Public License 1.0
330 stars 92 forks source link

Fix/max nested depth bug #289

Closed thelmuth closed 4 years ago

thelmuth commented 4 years ago

This fixes the nested depth StackOverflow with some code stack instructions.

lspector commented 4 years ago

Merged although I note that the recursion in the depth checker could itself overflow the Java call stack if the limit is too high. Alternative approaches might use zippers or a traversal of a printed representation of the tree that increments/decrements a counter as parentheses are processed... but probably this isn't necessary.

thelmuth commented 4 years ago

Good point. I'm not sure why this didn't happen in my tests. I'm guessing because the max-points limit I used (5000) doesn't allow code to get big enough for this to hit the recursion limit. I'm going to try some limited tests with a bigger max-points to see what happens.

thelmuth commented 4 years ago

Yup, my larger trials show that the new function causes stack overflows, as you expected. I'll work on a replacement.

While the string approach sounds easiest, I'm wary because I'd have to be careful about things like strings that contain parentheses, parenthesis character literals, etc.