Stack overflow


SP4CEBAR 2022-06-25 10:30 (Edited)

Until now, I've never made a function call itself because it kind of feels "illegal"
This is a really simple experiment where a function keeps calling itself until the stack overflow

Recursion.nx | Open in app
2022-06-25 10:30

Timo 2022-06-25 13:49

For infinite repetition you should obviously not do that. But there are some mostly mathematical or logic related problems, which can be solved very nicely with recursion (a function calling itself).

Or another example: you have a function which outputs the list of files of a directory. You may want to show also the files in all subdirectories.

You can have a function with one parameter for the path of the directory. Then, whenever it finds a subdirectory, it calls itself with that subdirectory as the parameter.

The function will eventually finish after outputting recursively all files.

(Of course there are no subdirectories in LowRes NX…)

SP4CEBAR 2022-06-25 14:01

I happened to be working on a tree file structure, that was my initial motivation to look at recursion

McPepic 2022-06-25 14:18

That’s a great website.

SP4CEBAR 2022-06-25 15:45

yes, they manage to answer specific google searches really well, but if you actually ask a question, they are likely to find it unworthy and they'll downvote it to delete it, instead of helping you

G-9 2022-06-26 10:51

Lol funny realidad 2022 desagar para android website

Log in to reply.