4

How can I print a lowercase Greek epsilon in SML (using Poly/ML)?

I've tried the following:

print "ε"; (* Error-unprintable character found in file *)
print "\u03B5"; (* Error-Conversion exception (Invalid string constant) raised while converting \u03B5 to string *)

Is this simply not possible? Surely it is the job of the terminal to actually render the character, and therefore printing the raw character code to stdout should be possible?

Alex Coplan
  • 13,211
  • 19
  • 77
  • 138

1 Answers1

3

The Unicode escape sequence \u03B5 corresponds to UTF-16.

Your terminal probably runs UTF-8 in which ε is 0xCE 0xB5. Entering them as decimal bytes:

> print "\206\181\n";
ε
sshine
  • 15,635
  • 1
  • 41
  • 66
  • 1
    Thanks - it's worth noting that the String.size function will treat these bytes as two separate characters, and therefore it is necessary to write your own function if you want to correctly calculate the length of a string when printed. – Alex Coplan Aug 11 '15 at 11:20
  • 2
    I wrote some functions for manipulating UTF8 strings in SML at https://raw.githubusercontent.com/HOL-Theorem-Prover/HOL/master/src/portableML/UTF8.sml (replace the .sml suffix with .sig to see the signature). – Michael Norrish Feb 18 '16 at 22:53