Welcome! Log In Create A New Profile

Advanced

recursion detection behaviour

Posted by Replace 
recursion detection behaviour
July 10, 2016 06:50AM
What should the proper recursion detection routine do ?

I made a small error, calling a module recursve, which gave me 4 messages in the concole after which the program went into hangup, as did my mac ... out of memory.
Thus, al my last programming was lost after killing the OpenScad......

Should the detection routine not stop rendering and gve control back to me ?

Thomas


www.3daybreaker.blogspot.com

Orca V4.4 rebuild to Ramps with Mk8 and E3D, as well as a Rostock Delta Mini and an OLO in backorder :-)
Re: recursion detection behaviour
July 10, 2016 11:05PM
(philosophy in a programming context) A computer must always do exactly what we tell him to do, even it is not what we want it to do. While this might sound rude, this ensures it is never the computer at fault for not doing what we wanted, instead it is our fault for not telling him right.

A confirmation dialog could pop up, but how would openscad guess how many recursions are too many? Should it take few and it would quickly become annoying. Should it take many and it could end up being too late. IMHO Recursion is a powerful feature for a programming language, and programmer should be trusted to use it right.

You should definitely get used to save more often. I tend to hit CTRL+S every 15-30s...

Better luck in the future.
Re: recursion detection behaviour
July 11, 2016 03:22PM
Hmm,

I agree that it is my fault and my fault only, to make a programming error. This makes me human , fortuntely, and not a program without errors smileys with beer

However, why build in a detection routine for recursive programming, marking them even RED, if this does only inform me that I have hit the end-of-the-world button for both Openscad, as my running MAC ?

I agree that when the oil warning light of my car comes up, it does not stop the engine.... but what If that was an option ?
If the gas warning light comes up, it will eventually stop the engine ! (hot smiley ) (joke)

So, I was surprized that the recursive programming wa not a fault, seen by the compiler.
if that is 'as designed' I would like this as a feature: stop on detection!

So much for my night rest

Thomas


www.3daybreaker.blogspot.com

Orca V4.4 rebuild to Ramps with Mk8 and E3D, as well as a Rostock Delta Mini and an OLO in backorder :-)
Re: recursion detection behaviour
July 12, 2016 07:00AM
The "save" button works while it is rendering, and I should think the red "x" to stop rendering would also work during an infinite recursion loop, so if you realise in time you should be able to rescue your work. It would be very difficult for a compiler to figure out that a complex loop is going to be infinite rather than being stopped by some condition after a long period of time.

Dave
Re: recursion detection behaviour
July 12, 2016 11:51AM
The red X does not appear when recursive modules are written.....


www.3daybreaker.blogspot.com

Orca V4.4 rebuild to Ramps with Mk8 and E3D, as well as a Rostock Delta Mini and an OLO in backorder :-)
Re: recursion detection behaviour
July 12, 2016 05:03PM
I just ran a test with the following code added to a much larger program XMotor.scad

recursiveTest();
module recursiveTest(){
recursiveTest();
}

I got an error re recursive code but then program locked up and I crashed out using task manager.
Reloading the file the new code was not in it so it was lost.
However looking in Documents/Openscad/backups there was a file XMotor-backup-gqHp4680.scad which contained the new code so it is not lost.
Re: recursion detection behaviour
July 13, 2016 01:50PM
Ahh.. the backup it makes before rendering ?



Never thought of that. I will check THANKS


www.3daybreaker.blogspot.com

Orca V4.4 rebuild to Ramps with Mk8 and E3D, as well as a Rostock Delta Mini and an OLO in backorder :-)
Re: recursion detection behaviour
July 16, 2016 04:48PM
I use my favourite editor to write the scad file. When I hit save the preview is updated. So openscad can crash the computer down and I still have the scad file. It also makes easier to check the reference documentation when I can hide code or preview.
Re: recursion detection behaviour
July 17, 2016 12:05AM
I didn't realize that openscad detects recursive code. However having said that, I should also state that there is nothing wrong with recursive code. It is a valid programming concept that I use often. The trick to recursion is to have logic to limit it.

The most I would hope that openscad would do would be to limit the depth of recursion. I think it would be perfectly valid for it to error out if recursion reaches a depth of, say 10 or 20.
Re: recursion detection behaviour
July 17, 2016 01:10PM
Quote
jbernardis
However having said that, I should also state that there is nothing wrong with recursive code.
I fully agree.

Quote
jbernardis
I think it would be perfectly valid for it to error out if recursion reaches a depth of, say 10 or 20.

But here I disagree. I also use recursion quite often, and sometimes the recursion depth can go quite deeper than that. Given OpenScad's "specialty" that variables cannot be reassigned, recursion is often the only possibility to solve some problems which would otherwise be solved with statements like "a=a+x", see e.g. here. So IMHO any arbitrary fixed limit on recursion depth should be avoided.
Re: recursion detection behaviour
July 18, 2016 12:24AM
So... why not just one configurable popup with confirmation button on first detection ? f.i. with a tickbox 'dont warn me again'

This makes sure it was an intended recursion.....

Often you can configure a 'detetion confirmation' in a lot of software.


www.3daybreaker.blogspot.com

Orca V4.4 rebuild to Ramps with Mk8 and E3D, as well as a Rostock Delta Mini and an OLO in backorder :-)
Sorry, only registered users may post in this forum.

Click here to login