Post Reply 
[VA] HP-71B Mini-challenge: Qualifying for a job
09-17-2022, 10:40 AM
Post: #22
RE: [VA] HP-71B Mini-challenge: Qualifying for a job
(09-17-2022 09:05 AM)ThomasF Wrote:  Hm, maybe I missed something?

Me Too!
Fortunately, through your code, I discover something fundamental that I wish to share with all of you.

This challenge is really a coup de pied au cul. I discover that I did not understand how my HP-1B behave.

Thanks to your code, I realized something important: by using several nested DEF FN definitions, it needs as many END DEF to close all these up properly.
Any missing END DEF make the second part of the program included in the definition part and it will not be executed unless you explicitly type RUN 10 [End Line]!

If we copy the codes proposed by J-F Garnier or those of ThomasF, we expect that pressing the RUN key will display the time.

Try it! Is the time displayed? What happened?


Now type this version of the code where I deliberately add a few DISP instructions to trace on:

1 DEF FNZ @ DISP "Z" @ DEF FNS(N) @ IF N>0 THEN FNS=RND+FNS(N-1)
2 DISP "S";N @ END DEF @ DISP "ZZ" @ END DEF @ DEF FNO=1
3 DEF FNG=FNS(8)-4 @ DEF FND=IP(RND*6)+1

10 DISP DATE$&" "&TIME$


Set your DELAY at something practical, such as DELAY 1,.125 for example.

When you press the RUN key, current Date and Time are displayed immediately.
Notice that no "Z" nor any "S..." appears.
That's OK.

Try a reasonable FNS(10), display show live counts from S 0 to S 10 before displaying resulting random summation. No Time-Date Stample.
That's OK.

Try FNO or FND, the expected random result immediately appears.
That's OK.

Try FNG. Please notice the live count from S 0 to S 8 due to the FNS(8) call from FNG expression.
That's OK.

Now try FNZ, the Z and ZZ are briefly displayed before the expected 0 result.
Is that OK?
Are you sure?

Why doesn't any "S 0" (or any "S ..." depending of actual N value) appears??

Now, alter the line 2 of my code by changing the two END DEF into simple END.
Press the RUN key, did the Date and Time still display?
Did the function call FNS(4), FNO FND and FNG behave the same as previously?
Did the function call FNZ display any Z or ZZ ?

humm... humm...

Now restore the first END in line 2 into the original END DEF instruction and remove the second END.
Did RUN key display the date and time?
What's wrong with FNZ? Why did the Date and Time appears?

First:
From the point of view of the definition's structures, the two END are equivalent to the two END DEF instructions but there really END instruction that stop the running program before Date and Time display.

Second:
The END DEF instructions are needed when we nested user's function definitions.
That why no "S ..." were displayed when FNZ is evoked, the DISP "S";N is not part of the DEF FNZ definition block. The DEF FN structures are nested such like any FOR TO NEXT structures are.


I add colors to help interpratation of my code. each user function have a different color. Black remain for block-program level.

1 DEF FNZ @ DISP "Z" @ DEF FNS(N) @ IF N>0 THEN FNS=RND+FNS(N-1)
2 DISP "S";N @ END DEF @
DISP "ZZ" @ END DEF @ DEF FNO=1
3 DEF FNG=FNS(8)-4 @ DEF FND=IP(RND*6)+1

10 DISP DATE$&" "&TIME$


It's the amazing HP-71B.
No hint of how nested definitions are handled is made in The Reference Manual. However, this is indeed possible and has been thought out by the designers of this overpowered BASIC.

This is what I discover, it makes my day.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] HP-71B Mini-challenge: Qualifying for a job - C.Ret - 09-17-2022 10:40 AM



User(s) browsing this thread: 1 Guest(s)