char->integer(3scm)
π char->integer, integer->char β the glow-up between characters and integers π
okay so this is char->integer(3scm) from the Scheme Programmer's Manual, and bestie, it's literally the tiny two-way door between a character and a number. come on in π«Ά
πΈ NAME πΈ
char->integer, integer->char β conversion between characters and integers
no cap, that's the whole vibe: one goes this way, the other goes that way β¨
π LIBRARY π
here's where you import 'em from, depending on which flavour of Scheme you're living in:
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
pick your fighter π
π SYNOPSIS π
(char->integer char)
(integer->char sv)
π¦ DESCRIPTION π¦
so char->integer takes a Unicode character and hands you back an exact integer between 0 and #xD7FF, or between #xE000 and #x10FFFF β and that number is equal to the Unicode scalar value of that character. iconic behaviour, honestly π
R6RS β sv must be a Unicode scalar value, i.e., a non-negative exact integer object in [0, #xD7FF] βͺ [#xE000, #x10FFFF]. and for a Unicode scalar value sv, integer->char returns its associated character. that's it, that's the deal π―
R7RS β given an exact integer that is the value returned by a character when char->integer is applied to it, integer->char returns that character. round trip, slay ππ¨
also (and this is the part where R7RS does its own thing): given a non-Unicode character, it returns an exact integer greater than #x10FFFF. and this is true independent of whether the implementation uses the Unicode representation internally. so don't come for it about internals, it said what it said π
π«Ά RETURN VALUES π«Ά
returns a single integer and character object, respectively. one each. no bundling, no surprises β¨
π₯ EXAMPLES π₯
watch it do the thing:
(integer->char 32)
=> #\space
(char->integer (integer->char 5000))
=> 5000
(integer->char #\xD800)
=> &assertion exception ;R6RS
that last one? yeah. that's a &assertion exception in R6RS, bestie β #\xD800 is not the move π good behaviour from the implementation though, love that for it π
β COMPATIBILITY β
R6RS defines these procedures in terms of Unicode scalar values. R7RS allows an implementation to support additional characters, and to omit support for some Unicode characters. R5RS defines these procedures so that char<=? on characters matches <= on the corresponding scalar values. so like, everyone agrees on the ordering vibe, they just disagree on the guest list π§
π ERRORS π
this procedure can raise exceptions with the following condition types:
&assertion(R6RS) β the wrong number of arguments was passed, or an argument was outside its domain.
R7RS β the assertions described above are errors. implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically. fail catastrophically is right there in the spec, ngl, do not test it for fun π
π SEE ALSO π
char<=?(3scm)
π STANDARDS π
R4RS, IEEE Scheme, R5RS, R6RS, R7RS
all of them. every single one. periodt π
πΈ AUTHORS πΈ
this page is part of the scheme-manpages project. it includes materials from the RnRS documents. more information can be found at https://github.com/schemedoc/manpages/. go show them some love, they ate π«Ά
and that's the whole page, bestie β char->integer(3scm) from the Scheme Programmer's Manual, dated 2021-02-21. mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2021 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms