Post Reply 
(48G) GCD: Greatest Common Divisor
09-01-2018, 06:46 PM (This post was last modified: 09-01-2018 06:51 PM by DavidM.)
Post: #15
RE: (48G) GCD: Greatest Common Divisor
(09-01-2018 05:05 PM)Thomas Klemm Wrote:  Can somebody explain how the size of these programs are determined?

It puzzles me a bit that this program uses 22.5 bytes:
Code:
« WHILE REPEAT END »

The reason this is larger is due to the way that the internal UserRPL compiler adds an empty "secondary" in between the REPEAT and the END. The empty secondary is comprised of the two SysRPL primitives :: and ;. Each one uses 2.5 bytes, for a total of 5 bytes which are "invisible" in the text form of the source code.

Something has to exist after the REPEAT and before the END for the RPL stream to be processed correctly.

(09-01-2018 05:05 PM)Thomas Klemm Wrote:  Whereas this longer program uses only 20 bytes:
Code:
« WHILE REPEAT SWAP END »

This one is compiled as you would probably expect, with the SWAP command between the REPEAT and END. SWAP only takes 2.5 bytes (compared to the 5 above), hence the smaller size of the total program.

For completeness, here's the SysRPL representations of both programs after the RPL compiler is done with them:
Code:

« WHILE REPEAT END »
::
  x<<
  xWHILE
  xREPEAT
  ::
  ;
  xWHILEEND
  x>>
;

« WHILE REPEAT SWAP END »
::
  x<<
  xWHILE
  xREPEAT
  xSWAP
  xWHILEEND
  x>>
;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (48G) GCD: Greatest Common Divisor - DavidM - 09-01-2018 06:46 PM



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