It works fine with Free42 3.0.10 on Android. At which step do you get this error message?lispm wrote: ↑Sun Mar 20, 2022 9:19 amDear dlachieze
returns errorCode: Select all
1 XEQ "PUSH" XEQ "POP"
"too few Arguements" in NSTK
"Invalid Type" in 4STK
at least with my Free42 3.0.10 on Ubuntu and Android
PUSH and POP stack routines
Re: PUSH and POP stack routines
DM42: 00425 - DM41X: β00066 - WP43: 00042
Re: PUSH and POP stack routines
The new version works fine. Great idea to use NEWLIST APPEND RCL X<>Y EXTEND to the implement the First in Last Out. Did not think of that!
Last edited by lispm on Tue Mar 22, 2022 12:50 pm, edited 1 time in total.
TI 55, HP16C, HP41C, DM42, APPLE ][, TRS-80, ATARI 800XL, ATARI 520ST, XEROX 1186 DANDELION, SYMBOLICS 3640, TI EXPLORER II
BLOG: https://yazuu.org/en/showblog_public.php?user=1&blog=
-
- Posts: 1107
- Joined: Tue May 02, 2017 5:48 pm
- Location: Netherlands
- Contact:
Re: PUSH and POP stack routines
I just realized that my version had a bug: it needed a CF 25 in the case HEAD returned NO, that is, when trying to pop from an existing but empty stack. In its original form, it would leave flag 25 set when it returned in that case, which of course is Not Good™.
I updated my earlier post, adding the missing CF 25.
The POP function is a bit tricky because you can't use FUNC for it. With FUNC, the function will either return an error or consume its declared number parameters and return its declared number of results; it cannot return one number of results in one non-error scenario and a different number of results in another non-error scenario. And that means you can't use it to implement something like HEAD or POP... But then that also means you have to be careful with flag 25. FUNC takes care of saving and restoring flag 25, and so if you're not using FUNC, at least you should clear flag 25.
What's really needed here are RTN/RTNYES/RTNNO variants that allow you to override the parameter and result counts specified in the FUNC call. Something I'll have to think about, I was already planning to go back to the drawing board for FUNC in NSTK mode...
(Or you could say that trying to pop from an empty stack should be considered an error. In that case, POP becomes a lot simpler: LBL "POP" FUNC 01 SF 25 HEAD "μ" FC? 25 RTNERR 6 END.)
I updated my earlier post, adding the missing CF 25.
The POP function is a bit tricky because you can't use FUNC for it. With FUNC, the function will either return an error or consume its declared number parameters and return its declared number of results; it cannot return one number of results in one non-error scenario and a different number of results in another non-error scenario. And that means you can't use it to implement something like HEAD or POP... But then that also means you have to be careful with flag 25. FUNC takes care of saving and restoring flag 25, and so if you're not using FUNC, at least you should clear flag 25.
What's really needed here are RTN/RTNYES/RTNNO variants that allow you to override the parameter and result counts specified in the FUNC call. Something I'll have to think about, I was already planning to go back to the drawing board for FUNC in NSTK mode...
(Or you could say that trying to pop from an empty stack should be considered an error. In that case, POP becomes a lot simpler: LBL "POP" FUNC 01 SF 25 HEAD "μ" FC? 25 RTNERR 6 END.)
Re: PUSH and POP stack routines
Hi Thomas. do you mind if I Update your SW on my original post, because it is much better and I don't want the reader to install an inferior version?
All I did was to remove the RTNYES from your code because it requires an additional keypress when in CUSTOM mode to# see the result.
All I did was to remove the RTNYES from your code because it requires an additional keypress when in CUSTOM mode to# see the result.
TI 55, HP16C, HP41C, DM42, APPLE ][, TRS-80, ATARI 800XL, ATARI 520ST, XEROX 1186 DANDELION, SYMBOLICS 3640, TI EXPLORER II
BLOG: https://yazuu.org/en/showblog_public.php?user=1&blog=
-
- Posts: 1107
- Joined: Tue May 02, 2017 5:48 pm
- Location: Netherlands
- Contact:
Re: PUSH and POP stack routines
Sure, go ahead!
I would recommend not removing the RTNYES, though. As long as you're only calling POP from programs, it doesn't matter, of course; in running programs, RTNYES has exactly the same effect as RTN or END. But for consistency when called from the keyboard, I feel that a function that can return No should return only Yes or No. It's a matter of taste, I'll admit, but that is my take. (Or instead of returning No when the stack is empty, return an error. That's the shortest version of the code, and I think the most appropriate for interactive use as well.)
I would recommend not removing the RTNYES, though. As long as you're only calling POP from programs, it doesn't matter, of course; in running programs, RTNYES has exactly the same effect as RTN or END. But for consistency when called from the keyboard, I feel that a function that can return No should return only Yes or No. It's a matter of taste, I'll admit, but that is my take. (Or instead of returning No when the stack is empty, return an error. That's the shortest version of the code, and I think the most appropriate for interactive use as well.)