Is there a chr() equivalent function in Little?


#1

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?


#2

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

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

#3

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.


#4

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().


#5

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