Is there a chr() equivalent function in Little?

Hi again,

I found there was an ord() function to get the code value of a character, but where is the reverse function (often named chr()) to build a character from an integer code value, if there is any?

The Little library does not have a chr() equivalent, but you can accomplish it via sprintf:

string mychr(int code) {
        return (sprintf("%c", code));

There doesn’t seem to be one. See tcl/library/libl.tcl in the source for the definition of ord(). In the meantime you can use something like format("%c", intValue) and if you feel adventurous, add a chr() function to that library.

Yes, I used the sprintf version (and in the Tcl version of the same program I now see I had used format).

It just hurts my sense of symmetry :slight_smile: that ord() is available and its symmetrical sister is not. Especially considering that ord() is in fact just calling scan().

We agree. We’ll add it to the Little library soon. Thanks for the suggestion.

1 Like