Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: Understanding recursive code Date: Wed, 10 Feb 2021 11:19:52 +0000 Organization: A noiseless patient Spider Lines: 30 Message-ID: <87tuqkgofb.fsf@bsb.me.uk> References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="1cf95790cca243eb5e1e6b17078f9ce0"; logging-data="29100"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/OP8MuWChx4hrkayw3M3b7iNIDItFkh/o=" Cancel-Lock: sha1:MG186mnWhyixpLXhVSNSHKXUgyA= sha1:9YNle6e+WSs6fhjWwwvEm2nN6M8= X-BSB-Auth: 1.b955c04490cc26b89233.20210210111952GMT.87tuqkgofb.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:39449 Jonas Thörnvall writes: > I had a look at my own recursive code, and realised i am not sure i > get what actually break my recursion. Could someone explain. What you have posted is not a complete example. First, I have to guess what the call is that you are debugging. I've assumed it's evalPrimary(calcSTR); Second, the code references undefined variables. For example, 'evaluation' is used in conditional tests but is never set. That's not the only case of using undefined variables, but it's the most obvious. Third, the almost exclusive use of global rather than local variables makes it almost impossible for me to reason about what the code is doing. Every function call could, until I can prove otherwise, change almost every variable referenced in the calling function. I last debugged such a program when I stopped being a research assistant helping non-programmers using FORTRAN IV. That was in 1979. I don't want to start again. It's a grim job. I know you will want to just plough on, hammering the code into shape, but if you were a student of mine I would insist that you start again with a well thought out high-level plan which can be written in code without a single global variable. -- Ben.