Trabb Pardo–Knuth algorithm: Difference between revisions
RPL: more comment
(add RPL - idiomatic) |
(RPL: more comment) |
||
Line 3,757:
=={{header|RPL}}==
Idiomatic RPL is based on use of stack whenever possible, short code and minimalist UX.
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
Line 3,765 ⟶ 3,766:
≪ DUP ABS √ SWAP 3 ^ + ≫ ''''FUNC'''' STO
≪ "
HALT 11 →LIST → s▼
ROT '''
-1 '''STEP'''▼
≫ ≫ ''''TPK'''' STO▼
|
'''FUNC''' ''( x -- sqrt(abs(x))+x^3 )''
Line 3,787 ⟶ 3,785:
call a function to do an operation
if result overflows
alert user
else print result
|}
<code>CONT</code> is not an instruction but a command, triggered by a specific keystroke.
On RPL versions used by HP-48 calculators and beyond, the first
≪ { }
1 11 '''START''' "Enter a number" { "?" V } INPUT + '''NEXT''' → s
to slightly improve the collection of the 11 numbers, avoiding the need for the <code>CONT</code> command.
{{in}}
<pre>
Line 3,806 ⟶ 3,802:
<pre>
11: "Too large!"
10: "
9: "
8: "
7: "
6: "
5: "
4: "
3: "
2: "
1: "Too large!"
</pre>
▲ HALT 11 →LIST → s
▲ -1 '''STEP'''
▲ ≫ ≫ ''''TPK'''' STO
=={{header|Ruby}}==
|