바이트와 문자열 입력
바이트와 문자열 입력 (Byte and String Input)
입력 포트에서 문자나 바이트를 읽는 다양한 함수를 다루는 문서예요. read-char, read-line, read-string, read-bytes 계열과, 미리 보기(peek) 및 특수 값 처리까지 살펴볼게요.
출처: Racket Reference
본문
procedure
(read-char [in]) → (or/c char? eof-object?)
in : input-port? = (current-input-port)
in에서 단일 문자를 읽습니다 — 여기에는 여러 바이트를 UTF-8로 디코딩해 문자로 만드는 작업이 포함될 수 있어요("Ports" 참고). 디코딩을 수행하기 위해 최소한의 바이트가 읽히거나 엿보여집니다(peek). 파일 끝(end-of-file) 전에 사용 가능한 바이트가 없으면 eof가 반환됩니다.
예시:
> (let ([ip (open-input-string "S2")])
(print (read-char ip))
(newline)
(print (read-char ip))
(newline)
(print (read-char ip)))
#\S
#\2
#<eof>
> (let ([ip (open-input-bytes #"\316\273")])
; The byte string contains UTF-8-encoded content:
(print (read-char ip)))
#\λ
procedure
(read-byte [in]) → (or/c byte? eof-object?)
in : input-port? = (current-input-port)
in에서 단일 바이트를 읽습니다. 파일 끝 전에 사용 가능한 바이트가 없으면 eof가 반환됩니다.
예시:
> (let ([ip (open-input-string "a")])
; The two values in the following list should be the same.
(list (read-byte ip) (char->integer #\a)))
'(97 97)
> (let ([ip (open-input-string (string #\λ))])
; This string has a two byte-encoding.
(list (read-byte ip) (read-byte ip) (read-byte ip)))
'(206 187 #<eof>)
procedure
(read-line [in mode]) → (or/c string? eof-object?)
in : input-port? = (current-input-port)
mode : (or/c 'linefeed 'return 'return-linefeed 'any 'any-one) = 'linefeed
in에서 다음 줄의 바이트를 포함하는 문자열을 반환합니다.
줄 구분자(line separator) 또는 파일 끝이 읽힐 때까지 in에서 문자가 읽힙니다. 줄 구분자는 결과 문자열에 포함되지 않습니다(하지만 포트의 스트림에서는 제거됩니다). 파일 끝을 만나기 전에 읽힌 문자가 없으면 eof가 반환됩니다.
mode 인자는 줄 구분자를 결정합니다. 다음 심볼 중 하나여야 합니다:
'linefeed— 줄바꿈 문자에서 줄을 끊습니다.'return— 리턴 문자에서 줄을 끊습니다.'return-linefeed— 리턴-줄바꿈 조합에서 줄을 끊습니다. 리턴 문자가 줄바꿈 문자로 뒤따르지 않으면, 그것은 결과 문자열에 포함됩니다. 마찬가지로, 리턴이 앞에 오지 않는 줄바꿈도 결과 문자열에 포함됩니다.'any— 리턴 문자, 줄바꿈 문자, 또는 리턴-줄바꿈 조합 중 어느 것이든 줄을 끊습니다. 리턴 문자가 줄바꿈 문자로 뒤따르면, 둘은 조합으로 취급됩니다.'any-one— 리턴-줄바꿈 조합을 인식하지 않고, 리턴 또는 줄바꿈 문자 중 하나에서 줄을 끊습니다.
리턴과 줄바꿈 문자는 텍스트 모드로 파일을 읽을 때 자동으로 수행되는 변환 이후에 탐지됩니다. 예를 들어, Windows에서 텍스트 모드로 파일을 읽으면 리턴-줄바꿈 조합이 자동으로 줄바꿈으로 바뀝니다. 따라서 파일이 텍스트 모드로 열리면 'linefeed가 보통 적절한 read-line 모드입니다.
예시:
> (let ([ip (open-input-string "x\ny\n")])
(read-line ip))
"x"
> (let ([ip (open-input-string "x\ny\n")])
(read-line ip 'return))
"x\ny\n"
> (let ([ip (open-input-string "x\ry\r")])
(read-line ip 'return))
"x"
> (let ([ip (open-input-string "x\r\ny\r\n")])
(read-line ip 'return-linefeed))
"x"
> (let ([ip (open-input-string "x\r\ny\nz")])
(list (read-line ip 'any) (read-line ip 'any)))
'("x" "y")
> (let ([ip (open-input-string "x\r\ny\nz")])
(list (read-line ip 'any-one) (read-line ip 'any-one)))
'("x" "")
procedure
(read-bytes-line [in mode]) → (or/c bytes? eof-object?)
in : input-port? = (current-input-port)
mode : (or/c 'linefeed 'return 'return-linefeed 'any 'any-one) = 'linefeed
read-line과 같지만 바이트를 읽고 바이트 문자열을 만듭니다.
procedure
(read-string amt [in]) → (or/c string? eof-object?)
amt : exact-nonnegative-integer?
in : input-port? = (current-input-port)
전체 포트를 문자열로 읽으려면 port->string을 사용하세요.
in에서 다음 amt개의 문자를 포함하는 문자열을 반환합니다.
amt가 0이면 빈 문자열이 반환됩니다. 그렇지 않으면, 파일 끝을 만나기 전에 amt보다 적은 문자가 사용 가능하다면, 반환된 문자열은 파일 끝 이전의 문자들만 포함합니다; 즉 반환된 문자열의 길이는 amt보다 작을 것입니다. (결과의 크기가 amt보다 작더라도 입력을 읽는 동안 크기 amt의 임시 문자열이 할당됩니다.) 파일 끝 전에 사용 가능한 문자가 없으면 eof가 반환됩니다.
읽는 동안 오류가 발생하면 일부 문자가 유실될 수 있습니다; 즉 read-string이 오류를 만나기 전에 어떤 문자를 성공적으로 읽었다면, 그 문자들은 버려집니다.
예시:
> (let ([ip (open-input-string "supercalifragilisticexpialidocious")])
(read-string 5 ip))
"super"
procedure
(read-bytes amt [in]) → (or/c bytes? eof-object?)
amt : exact-nonnegative-integer?
in : input-port? = (current-input-port)
전체 포트를 바이트로 읽으려면 port->bytes를 사용하세요.
read-string과 같지만 바이트를 읽고 바이트 문자열을 만듭니다.
예시:
> (let ([ip (open-input-bytes
(bytes 6
115 101 99 114 101
116))])
(define length (read-byte ip))
(bytes->string/utf-8 (read-bytes length ip)))
"secret"
procedure
(read-string! str [in start-pos end-pos]) → (or/c exact-nonnegative-integer? eof-object?)
str : (and/c string? (not/c immutable?))
in : input-port? = (current-input-port)
start-pos : exact-nonnegative-integer? = 0
end-pos : exact-nonnegative-integer? = (string-length str)
read-string처럼 in에서 문자를 읽지만, 그것들을 인덱스 start-pos(포함)부터 end-pos(제외)까지 str에 넣습니다. substring처럼, start-pos나 end-pos가 str의 범위를 벗어나면 exn:fail:contract 예외가 일어납니다.
start-pos와 end-pos의 차이가 0이면 0이 반환되고 str은 수정되지 않습니다. 파일 끝 전에 사용 가능한 바이트가 없으면 eof가 반환됩니다. 그렇지 않으면 반환 값은 읽힌 문자 수입니다. m개의 문자가 읽히고 m < end-pos - start-pos이면, str은 인덱스 start-pos + m부터 end-pos까지 수정되지 않습니다.
예시:
> (let ([buffer (make-string 10 #\_)]
[ip (open-input-string "cketRa")])
(printf "~s\n" buffer)
(read-string! buffer ip 2 6)
(printf "~s\n" buffer)
(read-string! buffer ip 0 2)
(printf "~s\n" buffer))
"__________"
"__cket____"
"Racket____"
procedure
(read-bytes! bstr [in start-pos end-pos]) → (or/c exact-nonnegative-integer? eof-object?)
bstr : bytes?
in : input-port? = (current-input-port)
start-pos : exact-nonnegative-integer? = 0
end-pos : exact-nonnegative-integer? = (bytes-length bstr)
read-string!과 같지만, 바이트를 읽어 바이트 문자열에 넣고 읽힌 바이트 수를 반환합니다.
예시:
> (let ([buffer (make-bytes 10 (char->integer #\_))]
[ip (open-input-string "cketRa")])
(printf "~s\n" buffer)
(read-bytes! buffer ip 2 6)
(printf "~s\n" buffer)
(read-bytes! buffer ip 0 2)
(printf "~s\n" buffer))
#"__________"
#"__cket____"
#"Racket____"
procedure
(read-bytes-avail! bstr [in start-pos end-pos]) → (or/c exact-nonnegative-integer? eof-object? procedure?)
bstr : bytes?
in : input-port? = (current-input-port)
start-pos : exact-nonnegative-integer? = 0
end-pos : exact-nonnegative-integer? = (bytes-length bstr)
read-bytes!과 같지만, 즉시 사용 가능한 바이트를 읽은 뒤 블록하지 않고 반환하며, "특수(special)" 결과에 대해 프로시저를 반환할 수 있습니다. read-bytes-avail! 프로시저는 아직 사용 가능한 바이트(또는 특수 값)가 없을 때만 블록합니다. 또한 read-bytes!와 달리, read-bytes-avail!은 바이트를 결코 버리지 않습니다. read-bytes-avail!이 어떤 바이트를 성공적으로 읽은 다음 오류를 만나면, 그 오류를 억제하고(대략 파일 끝처럼 취급) 읽은 바이트를 반환합니다. (그 오류는 이후의 읽기에 의해 트리거됩니다.) 바이트가 하나도 읽히기 전에 오류를 만나면 예외가 일어납니다.
in이 "Custom Ports"에서 설명된 대로 특수 값을 만들어 낼 때, 결과는 네 개의 인자를 갖는 프로시저입니다. 네 개의 인자는 포트 안에서 특수 값의 위치에 해당하며, "Custom Ports"에서 설명된 대로입니다. 유효한 인자로 프로시저를 한 번보다 많이 호출하면 exn:fail:contract 예외가 일어납니다. read-bytes-avail!이 특수 생성 프로시저를 반환하면, bstr에 문자를 넣지 않습니다. 마찬가지로, read-bytes-avail!은 포트의 스트림에서 특수 값 앞에 사용 가능한 만큼의 바이트만 bstr에 넣습니다.
procedure
(read-bytes-avail!* bstr [in start-pos end-pos]) → (or/c exact-nonnegative-integer? eof-object? procedure?)
bstr : bytes?
in : input-port? = (current-input-port)
start-pos : exact-nonnegative-integer? = 0
end-pos : exact-nonnegative-integer? = (bytes-length bstr)
read-bytes-avail!과 같지만, 파일 끝에 도달하지 않았고 읽기에 사용 가능한 바이트(또는 특수 값)가 없으면 즉시 0을 반환합니다.
procedure
(read-bytes-avail!/enable-break bstr [in start-pos end-pos]) → (or/c exact-nonnegative-integer? eof-object? procedure?)
bstr : bytes?
in : input-port? = (current-input-port)
start-pos : exact-nonnegative-integer? = 0
end-pos : exact-nonnegative-integer? = (bytes-length bstr)
읽는 동안 브레이크가 활성화된다는 점을 제외하면 read-bytes-avail!과 같습니다("Breaks"도 참고). read-bytes-avail!/enable-break가 호출될 때 브레이킹이 비활성화되어 있고, 그 호출의 결과로 exn:break 예외가 일어나면, in에서 어떤 바이트도 읽히지 않았을 것입니다.
procedure
(peek-string amt skip-bytes-amt [in]) → (or/c string? eof-object?)
amt : exact-nonnegative-integer?
skip-bytes-amt : exact-nonnegative-integer?
in : input-port? = (current-input-port)
read-string과 비슷하지만, 반환된 문자들이 엿보여집니다(peek): 포트에 보존되어 이후의 읽기와 엿보기에 사용됩니다. (더 정확히는, 디코딩되지 않은 바이트가 이후의 읽기와 엿보기를 위해 남겨집니다.) skip-bytes-amt 인자는 반환할 문자를 모으기 전에 입력 스트림에서 건너뛸 (문자가 아닌) 바이트 수를 나타냅니다; 따라서 총 skip-bytes-amt 바이트와 amt 개의 문자가 검사됩니다.
대부분의 종류의 포트에서, skip-bytes-amt 바이트와 amt 개의 문자를 검사하려면 바이트/문자가 읽힐 때까지 포트와 연관된 skip-bytes-amt + amt 바이트 이상의 메모리 오버헤드가 최소한 필요합니다. 문자열 포트("String Ports" 참고), 파이프 포트("Pipes" 참고), 또는 특정 엿보기 프로시저를 가진 사용자 지정 포트(엿보기 프로시저가 어떻게 구현되는지에 따라 다름; "Custom Ports" 참고)에서 엿볼 때는 그러한 오버헤드가 필요하지 않습니다.
포트가 스트림 한가운데서 eof를 만들어 내면, 엿보기를 위해 eof를 넘어 건너뛰려는 시도는 eof가 읽힐 때까지 항상 eof를 만들어 냅니다.
procedure
(peek-bytes amt skip-bytes-amt [in]) → (or/c bytes? eof-object?)
amt : exact-nonnegative-integer?
skip-bytes-amt : exact-nonnegative-integer?
in : input-port? = (current-input-port)
peek-string과 같지만 바이트를 엿보고 바이트 문자열을 만듭니다.
procedure
(peek-string! str skip-bytes-amt [in start-pos end-pos]) → (or/c exact-nonnegative-integer? eof-object?)
str : (and/c string? (not/c immutable?))
skip-bytes-amt : exact-nonnegative-integer?
in : input-port? = (current-input-port)
start-pos : exact-nonnegative-integer? = 0
end-pos : exact-nonnegative-integer? = (string-length str)
read-string!과 같지만 엿보기용이고, peek-string처럼 skip-bytes-amt 인자를 갖습니다.
procedure
(peek-bytes! bstr skip-bytes-amt [in start-pos end-pos]) → (or/c exact-nonnegative-integer? eof-object?)
bstr : (and/c bytes? (not/c immutable?))
skip-bytes-amt : exact-nonnegative-integer?
in : input-port? = (current-input-port)
start-pos : exact-nonnegative-integer? = 0
end-pos : exact-nonnegative-integer? = (bytes-length bstr)
peek-string!과 같지만 바이트를 엿보고, 바이트 문자열에 넣고, 읽힌 바이트 수를 반환합니다.
procedure
(peek-bytes-avail! bstr skip-bytes-amt [progress in start-pos end-pos]) → (or/c exact-nonnegative-integer? eof-object? procedure?)
bstr : (and/c bytes? (not/c immutable?))
skip-bytes-amt : exact-nonnegative-integer?
progress : (or/c progress-evt? #f) = #f
in : input-port? = (current-input-port)
start-pos : exact-nonnegative-integer? = 0
end-pos : exact-nonnegative-integer? = (bytes-length bstr)
엿보기용이고 두 개의 추가 인자를 갖는다는 점을 제외하면 read-bytes-avail!과 같습니다. skip-bytes-amt 인자는 peek-bytes에서와 같습니다. progress 인자는 #f이거나 in에 대한 port-progress-evt가 만든 이벤트여야 합니다.
엿보기 위해, peek-bytes-avail!은 파일 끝, 건너뛴 바이트 너머의 적어도 한 바이트(또는 특수 값), 또는 #f가 아닌 progress가 준비될 때까지 블록합니다. 또한, 바이트가 엿보여지기 전에 progress가 준비되면 어떤 바이트도 엿보이거나 건너뛰지 않으며, progress는 엿보기 시도 중에 사용 가능해지면 건너뛰기 과정을 일찍 끝낼 수 있습니다. 게다가 progress는 포트가 여전히 열려 있는지 결정하기 전에도 검사됩니다.
peek-bytes-avail!의 결과가 0인 경우는:
start-pos가end-pos와 같을 때, 또는progress가 바이트가 엿보여지기 전에 준비될 때.
procedure
(peek-bytes-avail!* bstr skip-bytes-amt [progress in start-pos end-pos]) → (or/c exact-nonnegative-integer? eof-object? procedure?)
bstr : (and/c bytes? (not/c immutable?))
skip-bytes-amt : exact-nonnegative-integer?
progress : (or/c progress-evt? #f) = #f
in : input-port? = (current-input-port)
start-pos : exact-nonnegative-integer? = 0
end-pos : exact-nonnegative-integer? = (bytes-length bstr)
read-bytes-avail!*과 같지만 엿보기용이고, peek-bytes-avail!처럼 skip-bytes-amt와 progress 인자를 갖습니다. 이 프로시저는 결코 블록하지 않으므로, 포트에서 skip-bytes-amt 바이트조차 사용 가능해지기 전에 반환될 수 있습니다.
procedure
(peek-bytes-avail!/enable-break bstr skip-bytes-amt [progress in start-pos end-pos]) → (or/c exact-nonnegative-integer? eof-object? procedure?)
bstr : (and/c bytes? (not/c immutable?))
skip-bytes-amt : exact-nonnegative-integer?
progress : (or/c progress-evt? #f) = #f
in : input-port? = (current-input-port)
start-pos : exact-nonnegative-integer? = 0
end-pos : exact-nonnegative-integer? = (bytes-length bstr)
read-bytes-avail!/enable-break과 같지만 엿보기용이고, peek-bytes-avail!처럼 skip-bytes-amt와 progress 인자를 갖습니다.
procedure
(read-char-or-special [in special-wrap source-name]) → (or/c char? eof-object? any/c)
in : input-port? = (current-input-port)
special-wrap : (or/c (any/c . -> . any/c) #f) = #f
source-name : any/c = #f
read-char과 같지만, 입력 포트가 특수 값(사용자 지정 포트의 값 생성 프로시저를 통해, source-name이 그 프로시저에 제공됩니다; 자세한 내용은 "Custom Ports"와 "Special Comments" 참고)을 반환하면, special-wrap을 특수 값에 적용한 결과가 반환됩니다. special-wrap의 #f 값은 항등 함수와 동일하게 취급됩니다.
base 패키지의 6.8.0.2 버전에서 변경됨: special-wrap과 source-name 인자가 추가되었습니다.
procedure
(read-byte-or-special [in special-wrap source-name]) → (or/c byte? eof-object? any/c)
in : input-port? = (current-input-port)
special-wrap : (or/c (any/c . -> . any/c) #f) = #f
source-name : any/c = #f
read-char-or-special과 같지만 문자 대신 바이트를 읽고 반환합니다.
base 패키지의 6.8.0.2 버전에서 변경됨: special-wrap과 source-name 인자가 추가되었습니다.
procedure
(peek-char [in skip-bytes-amt]) → (or/c char? eof-object?)
in : input-port? = (current-input-port)
skip-bytes-amt : exact-nonnegative-integer? = 0
read-char과 같지만 읽는 대신 엿보고, 포트의 시작 부분에서 skip-bytes-amt 바이트(문자 아님)를 건너뜁니다.
procedure
(peek-byte [in skip-bytes-amt]) → (or/c byte? eof-object?)
in : input-port? = (current-input-port)
skip-bytes-amt : exact-nonnegative-integer? = 0
peek-char과 같지만 문자 대신 바이트를 엿보고 반환합니다.
procedure
(peek-char-or-special [in skip-bytes-amt special-wrap source-name]) → (or/c char? eof-object? any/c)
in : input-port? = (current-input-port)
skip-bytes-amt : exact-nonnegative-integer? = 0
special-wrap : (or/c (any/c . -> . any/c) #f 'special) = #f
source-name : any/c = #f
peek-char과 같지만, skip-bytes-amt 바이트 위치 이후에 입력 포트가 바이트가 아닌 값을 반환하면, 결과는 special-wrap에 따라 달라집니다:
special-wrap이#f이면, 특수 값이 반환됩니다(read-char-or-special에서처럼).special-wrap이 프로시저이면, 결과를 만들기 위해 특수 값에 적용됩니다(read-char-or-special에서처럼).special-wrap이'special이면, 특수 값 대신'special이 반환됩니다 — 입력 포트 구현이 반환하는 특수 값 프로시저를 호출하지 않습니다.
base 패키지의 6.8.0.2 버전에서 변경됨: special-wrap과 source-name 인자가 추가되었습니다. 6.90.0.16 버전에서 변경됨: special-wrap의 옵션으로 'special이 추가되었습니다.
procedure
(peek-byte-or-special [in skip-bytes-amt progress special-wrap source-name]) → (or/c byte? eof-object? any/c)
in : input-port? = (current-input-port)
skip-bytes-amt : exact-nonnegative-integer? = 0
progress : (or/c progress-evt? #f) = #f
special-wrap : (or/c (any/c . -> . any/c) #f 'special) = #f
source-name : any/c = #f
peek-char-or-special과 같지만 문자 대신 바이트를 엿보고 반환하며, peek-bytes-avail!처럼 progress 인자를 지원합니다.
base 패키지의 6.8.0.2 버전에서 변경됨: special-wrap과 source-name 인자가 추가되었습니다. 6.90.0.16 버전에서 변경됨: special-wrap의 옵션으로 'special이 추가되었습니다.
procedure
(port-progress-evt [in]) → progress-evt?
in : (and/c input-port? port-provides-progress-evts?) = (current-input-port)
in에서 이후의 어떤 읽기 이후 또는 in이 닫힌 후에 동기화를 위해 준비되는 동기화 가능한 이벤트("Events" 참고)를 반환합니다. 이벤트가 준비된 후에는 계속 준비 상태로 유지됩니다. 진행 이벤트의 동기화 결과는 진행 이벤트 그 자체입니다.
procedure
(port-provides-progress-evts? in) → boolean
in : input-port?
port-progress-evt가 in에 대한 이벤트를 반환할 수 있으면 #t를 반환합니다. 모든 내장 종류의 포트가 진행 이벤트를 지원하지만, make-input-port로 만들어진 포트("Custom Ports" 참고)는 지원하지 않을 수 있습니다.
procedure
(port-commit-peeked amt progress evt [in]) → boolean?
amt : exact-nonnegative-integer?
progress : progress-evt?
evt : evt?
in : input-port? = (current-input-port)
in에서 이전에 엿본 처음 amt 바이트, 비-바이트 특수 값, 그리고 eof를 읽은 것으로 커밋(commit)하려 시도하거나, in에서 엿본 첫 eof 또는 특수 값을 커밋하려 시도합니다. 스트림 중간의 eof는 커밋될 수 있지만, 포트가 소진되었을 때의 eof는 스트림의 데이터에 해당하지 않으므로 반드시 커밋되지는 않습니다.
읽기는 progress가 먼저 준비되지 않을 때(즉, 다른 프로세스가 먼저 in에서 읽지 않을 때)만, 그리고 port-commit-peeked 안의 sync가 evt를 선택할 때만(이 경우 이벤트 결과는 무시됨) 커밋됩니다. evt는 channel-put 이벤트, channel, 세마포어, 세마포어-엿보기 이벤트, 항상(always) 이벤트, 또는 절대(never) 이벤트 중 하나여야 합니다. port-commit-peeked를 호출하는 스레드를 중단하는 것은 커밋이 진행되는 것을 막을 수도 있고 막지 못할 수도 있습니다.
port-commit-peeked의 결과는 데이터가 커밋되었으면 #t, 그렇지 않으면 #f입니다.
in에서 엿본 데이터가 없고 progress가 준비되지 않았다면, exn:fail:contract 예외가 일어납니다. in의 스트림의 현재 시작 부분에서 amt보다 적은 항목이 엿보여졌다면, 엿본 항목들만 읽은 것으로 커밋됩니다. in의 스트림이 현재 eof나 비-바이트 특수 값에서 시작한다면, 그 eof 또는 특수 값만 읽은 것으로 커밋됩니다.
progress가 in에 적용된 port-progress-evt의 결과가 아니면, exn:fail:contract 예외가 일어납니다.
procedure
(byte-ready? [in]) → boolean?
in : input-port? = (current-input-port)
(read-byte in)이 (적어도 byte-ready?가 호출된 시점에) 블록하지 않을 것이면 #t를 반환합니다. (and (sync/timeout 0 in) #t)와 동일합니다.
byte-ready?와 char-ready? 함수는 비교적 적은 응용에 적합합니다. 포트는 동시 생산자와 소비자 사이에서 스트리밍 데이터를 지원하도록 만들어졌기 때문이죠. 어떤 순간에 바이트나 문자가 준비되지 않았다고 해서 반드시 생산자가 데이터 공급을 끝냈다는 뜻은 아닙니다. (또한 포트에 여러 소비자가 있으면, 어떤 프로세스가 byte-ready?로 포트를 폴링하는 시점과 포트에서 데이터를 읽는 시점 사이에 데이터가 소비될 수 있습니다.) 자신만의 스케줄러를 구현하고 있거나 포트의 구현과 사용이 특히 제약되어 있다는 것을 안다면 byte-ready?를 사용하는 것이 합리적입니다.
procedure
(char-ready? [in]) → boolean?
in : input-port? = (current-input-port)
(read-char in)이 (적어도 char-ready?가 호출된 시점에) 블록하지 않을 것이면 #t를 반환합니다. 스트림의 초기 바이트에 따라, UTF-8 인코딩을 형성하기 위해 여러 바이트가 필요할 수 있습니다.
byte-ready?와 char-ready?가 어떤 경우 올바른 선택인지에 대한 주의 사항은 byte-ready?를 참고하세요.
procedure
(progress-evt? v) → boolean?
v : any/c
(progress-evt? evt in) → boolean?
evt : progress-evt?
in : input-port?
한 인자로, v가 어떤 입력 포트에 대한 진행 이벤트이면 #t, 그렇지 않으면 #f를 반환합니다.
두 인자로, evt가 in에 대한 진행 이벤트이면 #t, 그렇지 않으면 #f를 반환합니다.
더 알아보기
- 바이트와 문자열 출력 (Byte and String Output) — 출력의 대응 함수들
- 포트 (Ports) — 포트의 기본과 종류
- 사용자 지정 포트 (Custom Ports) — 특수 값, 특수 생성 프로시저
- 이벤트 (Events) —
sync, 진행 이벤트