Re: HP-49G+ - Where is the "last x" key / function? Message #8 Posted by James M. Prange (Michigan) on 25 Oct 2005, 11:00 p.m., in response to message #2 by Jeff O.
Thanks for the credit, Jeff. I may well have posted that program
somewhere, sometime, but it's not my preferred version. My only
problem with it is in the case of an empty last arguments buffer,
it errors out instead of returning 0.
Here are three programs that handle the empty last arguments
buffer case better.
Note that in the programs, I'm using exact integers (type 28) for
the 49 series. "Real" numbers (type 0) also work, but of course
the results from the BYTES command will be different.
This first one both returns 0. (as a real number) to the stack and
leaves it in the buffer if the last arguments buffer was empty.
%%HP: T(3)A(D)F(.);
@ Download (or enter) in exact mode on 49 series.
@ Results from the BYTES command:
@ 49 series checksum: # 2C67h
@ 49 series size: 69.
@ 48 series checksum: # ECA9h
@ 48 series size: 69
\<<
DEPTH \-> d
\<<
LASTARG DEPTH d -
IF
DUP
THEN
DUP2 2 + ROLLD DROPN
END
DUP DROP
\>>
\>>
This second one returns 0. (as a real number) to the stack and
leaves the buffer empty if the last arguments buffer was empty:
%%HP: T(3)A(D)F(.);
@ Download (or enter) in exact mode on 49 series.
@ Results from the BYTES command:
@ 49 series checksum: # B2D2h
@ 49 series size: 90.5
@ 48 series checksum: # F5Dh
@ 48 series size: 94.5
\<<
DEPTH \-> d
\<< LASTARG DEPTH d -
IF
DUP
THEN
DUP2 2 + ROLLD DROPN DUP DROP
ELSE
-55 DUP SF CF
END
\>>
\>>
This last one doesn't return anything to the stack and leaves the
buffer empty if the last arguments buffer was empty.
%%HP: T(3)A(D)F(.);
@ Download (or enter) in exact mode on 49 series.
@ Results from the BYTES command:
@ 49 series checksum: # 8C85h
@ 49 series size: 93.
@ 48 series checksum: # D527h
@ 48 series size: 97
\<<
DEPTH \-> d
\<< LASTARG DEPTH d -
IF
DUP
THEN
DUP2 2 + ROLLD DROPN DUP DROP
ELSE
DROP -55 DUP SF CF
END
\>>
\>>
If system flag -55 is set (No last args), then these programs will
error out.
Note that after some commands that don't take any arguments, like
CLEAR, DROP, and MEM, these programs don't return what was the
last object in level 1.
In the 49 series, LASTARG is invoked by LeftShift ANS (over the
ENTER key), at least in RPN mode. I've never used ALG mode, so
won't offer any advice for that.
For similar programs for the 28 series, change LASTARG to LAST,
and (in the last two programs) change -55 DUP SF CF to 31 DUP CF
SF.
Even in the 48 and 49 series, LAST can be used as a synonym for
LASTARG, to maintain backwards compatibility.
Personally, I prefer the first program that I've posted here best.
Just out of curiosity, which one do users of "Real RPN" models
prefer?
Regards, James
Edited: 25 Oct 2005, 11:04 p.m.
|