Recursion programming on the Plus42

75 views
Skip to first unread message

Paal Rasmussen

unread,
Nov 9, 2023, 9:05:27 AM11/9/23
to Free42 & Plus42
I'm flabbergasted! Just wanted to share. 
An old pet of mine that I was always taught was "bad programming" has come of age, and in some form is also available on my favourite calculator. Thank you!

I'm currently reading Manuel Rubio-Sánchez' Recursive Programming, and feeling like being injected with a high dose of vitamins trying out things on the Plus42.I am wondering what techniques people have for debugging recursion on the Plus42? It quickly becomes so I lose the birds eye view of things.

Anyway, I'd love to hear what people thing about this wonderful extension!


Thomas Okken

unread,
Nov 10, 2023, 6:11:48 AM11/10/23
to Free42 & Plus42
I assume you're asking about debugging equations, since debugging recursive RPN programs is no different than debugging any other RPN program.

The most commonly used tools for debugging are STOP, which you can insert into a program to make it stop running. Once stopped, you can execute it step-by-step using SST (a.k.a. SST↓, Step Into), SST→ (Step Over), and SST↑ (Step Out), and you can use R/S to resume execution. While stopped, you can use VIEW to look at variables and registers without disturbing the stack.

In an equation, you can insert a STOP using the STOP() function. This function takes one argument and returns it unchanged, so wrapping STOP() around a subexpression causes STOP to be performed after that subexpression has finished evaluating.

SST↓, SST→, and SST↑ work while evaluating expressions, but what you're actually stepping through in that case is the RPN code that was generated by the equation parser, and it won't always be obvious which part of the equation corresponds to the current RPN program line. TRACE and STRACE modes help with this, by printing the current position in the equation text in addition to the current RPN program line.

Hmmm, now that I'm thinking about this, it would be useful to have a VIEW() function, so you could make an equation print variables while it is executing, without having to use breakpoints or single-stepping. I'll add that in the next build.
Reply all
Reply to author
Forward
0 new messages