rejig takes inspiration from go fmt, implementing my preferred RPN programming style with no option for customization, on purpose. One may quibble with the choices I have made, but when the rules are fixed and automatically enforced, developer focus tends to shift from bikeshedding to substantive matters.
Identifier Names
On the R47 itself, “00” may refer either to:
These cases are not strictly ambiguous because they are all arguments to operations, and the referent type can always be correctly inferred from that op. Nevertheless, rejig saves you the mental burden of recalling which arg type each op takes by prefixing numbered registers with R and flags with F in its R47 text output forms. This leaves labels as the sole case where a bare number is used as an identifier.
Spaces
The R47 programming language was not intended to be parsed, as such. The clearest way to see this is that it separates tokens primarily with whitespace, except in the odd cases where whitespace is significant. Because this inconsistency complicates round-tripping, rejig output can differ from what you see on-screen in 🟧 PRGM mode.
One solution for this class of problem is quoting, but because that brings on a whole pile of other trouble, rejig instead either removes spaces or replaces them with hyphens. A good example of this is the “a b/c” function on the calculator for entering fraction mode, which rejig spells a-b/c. I do realize that this is ambiguous with respect to subtraction, but it is a common way of expressing a mixed fraction, as with “1-⅔” in US cookbooks.
The biggest single case you need to be aware of is with the numeric tests. What the R47 styles “x≠ ?” is canonically spelled without the space in rejig. For instance, the way to check for inequality between the X and Y registers is to write:
x≠? Y
Or, in support of its HP-42S family inputs, rejig also supports this combined style:
x≠y?
Give rejig the --ops flag to get a list of available op names, including all the aliases meant to reduce the need for guessing.
Case Sensitivity
rejig is case-insensitive where possible. It isn’t, always.
Op names are case-insensitive when there are at least three ASCII letters, since the chance of collision becomes low enough to tolerate. Without a lower bound on this rule, the HP-32SII r op to retrieve the calculated linear regression coefficient would be ambiguous with the R op to give a random number on that same machine. For a two-letter example, we have the HP-32S BN spelling for the binary input mode, which tout le monde spells BIN; the length limit avoids a confusion with the R47’s Bn op, returning Bernoulli number `B_n`.
The “ASCII” part of that rule is critical: mathematicians have made many case distinctions over the centuries. To pick on the statisticians, they’re big on distinguishing σ from Σ even though both are Greek sigma. This rule prevents CL𝛸 from being allowed as a cutesy way of spelling CL𝑥; that third character is Greek capital chi, preventing us from accepting it as a swooshy mathematical italic X.
A different context where the same basic logic applies is in register naming. Some machines rejig knows about make a distinction between the a and A registers, the first treated as local and the second as global.
And yet, the three-letter rule is not absolute, else rejig could not obey the separate rule that alpha-named variables and labels are case-sensitive in all forty-series machines including the R47 itself. Because LBL ‘ReJiG’ is not accepted as meaning the same thing as LBL ‘rEjIg’, we must conform.
Yes, this is all a confusing mess, but use the above examples to maintain perspective. Even that pinnacle of engineering (hah!) HP could not make up their own minds on this, within their own line of development.
These rules then interplay, adding additional complexities. The “three ASCII letters” minimum requires rejig to make separate accommodation for both the thirty-series on-screen display of the swap op (x<>y) and the forty-series variant X<>Y, doubtless owed to the HP-41C all-uppercase legacy. You can prove to yourself that rejig isn’t doing automatic case-folding by trying x<>Y or X<>y.
One exception occurs when lowering R47 or HP-42S family programs to a lesser form, requiring rejig to map that string to one of the legal letters or numbers on the target machine. In this way, a reference to “LBL ‘a’” can become “LBL A” in HP-15C output, giving the illusion that rejig is case-folding. What it is actually doing is recognizing that the 15C has no alpha labels, but that label “A” hasn’t been used yet, allowing it to provide a straightforward mapping. If that label had been used already, it would move on to B and so forth until it hit E, then start in on the numbered labels allowed on the 15C.
Comments
rejig recognizes four styles of comments:
#shell script;assembly//C family@RPL
When any of these are found alone on a line after leading whitespace is stripped, they become REM operations at the R47 IR level, with the comment text preserved as the op’s alpha string arg.
The @ form is special. The rejig parser sets a non-coding flag on whole-line comments with this introducer so that the programmer can use it for source-only annotations:
@ This is the start of a long comment
@ which rambles on and on, making us
@ prefer it does not bloat P47 output
@ with REM ops.
This allows verbose program source code annotations.1
All other forms above canonicalize to the # form in UTF-8 output and code as REM ops in P47 output. You may conceive of these as op aliases for REM even though that is not how they work at the parser level. This shell form is both faster to type and easier to read because it requires no quotes around its “argument:”
REM ‘This is an R47 comment, preserved in code.’
…versus…
# This is a rejig comment, preserved in code.
A comment may follow another op, and its arg, if any:
STO R42 ; save intermediate result for later
This comment text is retained in the IR form as metadata for the immediately preceding op — STO in this case — allowing these behaviors:
--fmtpreserves end-of-line comments- converting between text formats that both support end-of-line comments preserves them
- comments align starting at column 21, pushed right when the input file has lines long enough to require it
In this form, @ is not special. It canonicalizes to ; form in UTF-8 output, same as the other three.
End-of-line comments are stripped when writing to any output format that does not support them. The common case is reading from a human-readable UTF-8 form and writing to a binary program form. It can also happen with text program formats like the RLM-11C form, being JSON-based, thus disallowing comments.2
This comment form requires that at least one whitespace character be interposed, else the HP-15C’s RAN# op would be interpreted as RAN followed by a shell-style # comment.
Similarly, we have gone out of our way in rejig to ensure that the R47’s #B op is never misinterpreted as REM ‘B’. Because this was inherited from the HP-16C, renaming the op to not have a leading hash (e.g. NumB) isn’t a viable solution. Neither is dropping the shell-style comment feature purely to protect this single rare op. Alas, that leaves special-casing as the only workable solution. We may at least hope that no future ops will be added to the R47 following this pattern, requiring further special-casing.
The overall intent of this multifarious comment support is that the default rejig output format (.p47u) be as useful for programmer-to-programmer communication as in getting programs from your computer into an R47. To see this in action, I suggest studying my triangle solver. I’ve always been a big fan of documenting code generally, but that goes double for terse languages like the R47’s RPN flavor.
Take the comments showing stack register movements: they aid the reader in understanding the program by documenting how the data moves on the stack at each step. As currently written, these comments assume the simpler SSIZE4 mode even though the program was tested with SSIZE8 mode; my choice was to pick one for clarity or document both options, muddying the presentation. Since the only material difference is that the interactions involving T affect the R47’s D register instead, I took this simpler tack.
Indenting
The base rejig indentation scheme is simple:
Global labels start in the first column, followed by a 2-space indent for subsequent statements.
Non-global labels are indented hierarchically under that.
RTNand return-like unconditionalGTO/XEQtail calls reduce the indent by 1 level, 2 spaces.A do-if-true op gives the subsequent op an extra indent level. This is true even when it combines with the prior rule, since then it is conditionally the end of the subroutine.
The new R47
STRUCTmenu ops match the block structure seen on-device, even with mixed-in classical do-if-true logic. Opening keywords likeIFindent their content by one level except for mid-span keywords likeELSE, and block-closing ops return to the indent level of the opening op.
Ideally, the indent level documents the program flow. The highest likelihood of achieving that is with the paired keywords in the R47’s STRUCT feature set.
Classic RPN forms won’t always do that, and it is not an error in the rejig output formatter when it shows surprising indentation as a result. If you find yourself questioning its results, first ask whether it is a fair expression of the ops as given. It might be telling you something important about how the program works, which you might wish to address.
That is my experience, at any rate. I find that my scheme makes far more sense than the one built into the R47’s PEM mode and its RTF outputs.
Blank Lines
Doubtless because of the limited screen real estate on calculators — even biggish ones like the R47 — it is traditional in RPN to write one line after the next, all the way through, without any blank lines.
Yet, when writing the program out as described above, I do believe we can accept adding one blank line above each obvious section break for readability.
A blank line is added before any group of whole-line @, LBL, and REM statements, in any quantity and order, except for the first in a file. Consecutive @ lines stay in one block; a following LBL/REM stays in that same group so comments cuddle with the label. This also covers machines without LBL (e.g. HP-12C), where @ alone marks section breaks.
rejig adds these when pretty-printing and strips them back out when reading text-form programs back in.
(You may now wish to return to the rejig home page.)
License
This work is © 2026 by Warren Young and is licensed under CC BY-NC-SA 4.0
- ^
The reason
@gets special treatment is a consequence of the RePIG design, which strips them unconditionally on parsing, as RPL does. When we expanded this to allow@comments outside RPL «angle brackets», consistency demanded equal treatment; both the end-of-line and whole-line@comment forms are non-coding, causing them to be stripped from non-UTF-8 outputs. Technically,rejigdoes preserve them at the IR level, but that is to keeprejig --fmtfrom being lossy. This useful side effect of source-only non-coding comments is therefore intentional, not a happy accident. - ^ And yes, I have tried feeding that HP-11C simulator JSONC; no joy.