Post Reply 
[SOLVED] DSRN (dog slow roman numerals)
06-16-2014, 09:13 PM
Post: #51
RE: DSRN (dog slow roman numerals)
Now you may call me a traitor of my own position, but I wondered whether it was useful to overload * to multiply a string by a number: like "M" * 3 = "MMM".
What if we use Forth's /MOD (n1 n2 - rem quot) instead of IDIV2 (n1 n2 - quot rem)?

Code:
\<<
  { 1000 900 500 400 100 90 50 40 10 9 5 4 1 }
  \<< /MOD \>>
  MAP
  { "M" "CM" "D" "CD" "C" "XC" "L" "XL" "X" "IX" "V" "IV" "I" }
  DOT
  NIP
\>>

But then I noticed: MAP can't access the stack below the list. Furthermore if more than one element is created they are enclosed within a list.

Example:
{ 1 2 3 }
\<< DUP \>>
MAP


returns:
{{ 1 1 } { 2 2 } { 3 3 }}

So that won't work. I'd prefer that MAP just pushes an element of the list on the stack, applies the program and then pops the top of the stack back to the list.
Thus the result would be:
1
2
3
{ 1 2 3 }

You can still create a list if you want to. But now it happens under the hood and you can't avoid it.

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: DSRN (dog slow roman numerals) - HP67 - 06-11-2014, 07:06 PM
RE: DSRN (dog slow roman numerals) - HP67 - 06-12-2014, 11:44 AM
RE: DSRN (dog slow roman numerals) - HP67 - 06-12-2014, 04:49 PM
RE: DSRN (dog slow roman numerals) - HP67 - 06-15-2014, 12:02 PM
RE: DSRN (dog slow roman numerals) - HP67 - 06-16-2014, 06:09 AM
RE: DSRN (dog slow roman numerals) - HP67 - 06-12-2014, 05:46 PM
RE: DSRN (dog slow roman numerals) - Thomas Klemm - 06-16-2014 09:13 PM



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