Is there an easier replacement for <<number::utf8>>?

I have a didactic example that I’ve used to teach several languages, and it requires getting an Unicode character from a integer, accomplished in Python as char(n).

I know I can do it with <<n::utf8>> but that opens a huge syntactic can of worms. Is there a simpler option?

Thanks!

:unicode.characters_to_binary([53])

4 Likes

List.to_string([n]).

iex(5)> List.to_string([243])
"ó"

iex(3)> <<243::utf8>>
"ó"
4 Likes

Thanks, @LostKobrakai and @alco!

iex(1)> List.to_string([0x1F44D, 0x1F64F])
"👍🙏"

For context, this is the didactic example I was updating: rf/elixir at master · ramalho/rf · GitHub

Thank you!

$ ./rf.exs face cat
U+1F431	🐱	CAT FACE
U+1F638	😸	GRINNING CAT FACE WITH SMILING EYES
U+1F639	😹	CAT FACE WITH TEARS OF JOY
U+1F63A	😺	SMILING CAT FACE WITH OPEN MOUTH
U+1F63B	😻	SMILING CAT FACE WITH HEART-SHAPED EYES
U+1F63C	😼	CAT FACE WITH WRY SMILE
U+1F63D	😽	KISSING CAT FACE WITH CLOSED EYES
U+1F63E	😾	POUTING CAT FACE
U+1F63F	😿	CRYING CAT FACE
U+1F640	🙀	WEARY CAT FACE