-1

The below code is able to successfully convert an integer file to a list however i need to convert an integer to a list such as. Can anyone assist please ?

readint 134516; result should be a list [1,3,4,5,1,6];

fun readint(infile : string) = 
  let
    val ins = TextIO.openIn infile
    
    fun loop ins =
      case TextIO.scanStream (Int.scan StringCvt.DEC) ins of
        SOME int => int :: loop ins
      | NONE     => []
  in
    loop ins before TextIO.closeIn ins
  end;
Chris
  • 26,361
  • 5
  • 21
  • 42
AinGLaw
  • 1
  • 2
  • 2
    First write a function that converts an integer to a list, then call that in this function. (Hints: `134516 mod 10` is `6`; `134516 div 10` is `13451`. Add recursion.) – molbdnilo Apr 21 '22 at 12:39

1 Answers1

-1

You want to to create a recursive function that uses the modulo (mod) and integer division (div) operators.

  • can you further assist please ? – AinGLaw Apr 21 '22 at 11:36
  • 1
    I hope you'll excuse me if I think this looks a lot like a programming exercise question. Are you having a problem with the algorithm or with the standard ml language? We are not here to do your work for you. – Fredrik Arnerup Apr 22 '22 at 15:01