Re: your opinion of the HP49G Message #30 Posted by Howard Owen on 20 Aug 2005, 4:11 p.m., in response to message #26 by Tony Duell
My brain may be calcifying, but RPL has been giving me pain. I think it's because I want to grasp it completely, the way I understand C, or Perl, or the 41C. I run into trouble because it's not just RPL, but the vast number of functions available in the 48G (for example) that I have to know in order to be expert. I had a practise back in the 1980s, when I was first learning to program, of coding Euclid's algorithm on each new system and/or programming language I encountered. The first system I did that on was the 41C, which was also the first machine I learned to program. Anyhow, I reverted to my old practise to try to break through this impractical "I want it all, now" desire of mine with the 48. A concrete problem has always been a boon to me. I know the 48GX I used probably has a GCD function. I know the Sparcom Math card does, but that's not the point of the exercise. Here's what I came up with. It expects the two numbers to test on levels 1 and 2. It consumes these, and leaves the GCD in level 1:
<<
WHILE DUP 0 # REPEAT
DUP 3 ROLLD MOD
END
DROP
>>
Update: the "0 #" isn't required, since any non-zero numeric value is logical true. So the routine could be <<WHILE DUP REPEAT DUP 3 ROLLD MOD END DROP>>, which is even more unreadable.
So, that's short and sweet. It also isn't recursive. That's good because I dont know how you'd do recursion without names. (RPL has named routines and variables, I know. I just didn't use them for this example.) I then set out to code the same algorithm on my HP-41CX. This is probably a good deal better than the first time I coded this algorithm in 1982 or so. It turned out to be quite similar to the 48 version, in fact:
01 LBL 01
02 STO Z
03 MOD
04 X#0?
05 GTO 01
06 RDN
That's even more concise. The inputs and output are the same as for the 48 version.
The "Forthian" vocabulary of the 48 is less familar to me than the 41C's language. I learned Forth, back in the day, along with many other languages I never used for real coding problems. So the lack of practise hurts. And six months from now, if I don't continue to code on the 48, I'll forget that "3 ROLLD" is equivilant to "ROT SWAP" for example. The 41's language is so ingrained, and so much simpler, that I won't have that difficulty with its code until my dying day, assuming I keep my mental acuity that long. 8)
So I think I may be able to start enjoying the 48 more if I ask less of myself at one sitting. I may not master the device ever, since there is a lot to know that isn't interesting or relevant for me. But If I can find a way to pick through what is there, I may do better, and enjoy it more.
Edited: 20 Aug 2005, 5:59 p.m.
|