Skip to content

Instantly share code, notes, and snippets.

@lsparrish
Created December 6, 2009 07:28
Show Gist options
  • Save lsparrish/250116 to your computer and use it in GitHub Desktop.
Save lsparrish/250116 to your computer and use it in GitHub Desktop.
Refactored pad
variable addr
::: Power function
: pow ( bp-n )
over here ! ::: Store the base for later use.
1 - 0; ::: Subtract 1 from the power and exit if the result is 0.
for here @ * next ; ::: Fetch the base and multiply it by the number.
::: Get the top value from the address stack.
: r ( -n ) ` pop ` dup ` push ; immediate
: pad ( - )
addr @ @ ::: Get the value pointed to by addr.
6 for dup ::: Handle up to 6 digits.
base @ r pow ::: Multiply the base by itself, a given number of times.
<if 32 emit then next ::: When the number is less than the smallest number
::: that takes up the given number of columns,
::: begin emitting spaces.
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment