Why ETA Is Not My Favourite Programming Language

29th August 2002

Ahem.

Since [the recusive factorial program] is a relatively large program, some annotation is in order:

line 1
Lantern 1: pamphlet
Call the subroutine at line 14 to read a number, in the form of a sequence of decimal digits, from the standard input. That number is placed on the stack.
line 2
Lantern 2: unkempt
Call the factorial function itself at line 5, converting the number on top of the stack into its own factorial.
line 3
Lantern 3: impiety
Call the subroutine at line 32 to output the result as a sequence of decimal digits
line 4
junctor: Vermont
Output a trailing newline character, and jump to line zero, terminating execution. This is the end of the main program: the remainder of the code consists of the subroutines called in these first four lines, and the subroutines that they in turn call.
line 5
NUTMEG 1: myrrh
The factorial routine itself: the prologue at line 5 rolls the argument n above the return address; line 11 makes the recursive call with argument n-1 if the argument is not 1; line 12 calls the routine at line 42 to multiply n by fact(n-1); and line 13 is the epilogue, rollin the return address back above the result, and transferring control to it.
line 14
=== FLUID ===
The subroutine to read a decimal constant from the standard input: lines 14-17 skip any leading sequence of space characters; lines 18 initialises the accumulator; lines 19-24 deal with an incoming digit; lines 25-29 break on a space or newline or at end of file, and otherwise loop; lines 30 and 31 discard the junk character on top of the stack and return the accumulated value to the caller.
line 32
5. gunmen = aleph;
The subroutine to write a decimal constant to the standard output: line 32 is the function-call prologue; lines 33-39 calculate and stack each digit in turn, least-significant first; line 40 calls the output-a-string subroutine at line 58 to unstack the digits to standard output most-significant first; line 41 is the function-return epilogue.
line 42
naked hymnal => belch
The subroutine to multiply two numbers together, which works by the primitive method of adding the value of the top-but-one value on the stack to an accumulator, initialised to zero, the number of times indicated by the top value on the stack. Prologue on lines 42-45, main loop on lines 46-55, and epilogue on line 56 and 57.
line 58
NUTMEG 18: myrrh
The subroutine to write out stacked characters, down to but not including a terminating NUL character. The function-return epilogue happens to be in the middle of the code, on line 61 (why not?)

What could possibly be clearer?

- Mike Taylor, The ETA Programming Language, section 7 (Examples), sub-section 7.4 (Factorial (Recursive))

Case closed.

Feedback to <mike@miketaylor.org.uk> is welcome!