PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/rosetta_code/roman_numerals.rx

https://github.com/crcx/retro-language
Forth | 28 lines | 24 code | 4 blank | 0 comment | 2 complexity | 137197098b94555d70c78b0cb5c1a89c MD5 | raw file
  1. This is a port of the Forth code; but returns a string rather than displaying
  2. the roman numerals. It only handles numbers between 1 and 3999.
  3. : vector ( ...n"- )
  4. here [ &, times ] dip : .data ` swap ` + ` @ ` do ` ; ;
  5. : .I dup @ ^buffer'add ;
  6. : .V dup 1 + @ ^buffer'add ;
  7. : .X dup 2 + @ ^buffer'add ;
  8. [ .I .X drop ]
  9. [ .V .I .I .I drop ]
  10. [ .V .I .I drop ]
  11. [ .V .I drop ]
  12. [ .V drop ]
  13. [ .I .V drop ]
  14. [ .I .I .I drop ]
  15. [ .I .I drop ]
  16. [ .I drop ]
  17. &drop
  18. 10 vector .digit
  19. : record ( an- )
  20. 10 /mod dup [ [ over 2 + ] dip record ] &drop if .digit ;
  21. : toRoman ( n-a )
  22. here ^buffer'set
  23. dup 1 3999 within 0 =
  24. [ "EX LIMITO!\n" ] [ "IVXLCDM" swap record here ] if ;