원자 항 처리
원자 항 처리
원자 항을 문자와 문자 코드의 시퀀스로 처리하는 술어들을 설명해요.
본문
이 내장 술어들은 원자 항을 문자와 문자 코드의 시퀀스로 처리할 수 있게 해줘요. 원자를 분할하고 결합하고, 단일 문자를 대응하는 문자 코드로/로부터 변환하고, 숫자를 문자와 문자 코드의 리스트로/로부터 변환하는 기능이 있어요.
atom_length/2
Templates
atom_length(+atom, ?integer)
Description
atom_length(Atom, Length)는 Length가 Atom의 이름의 문자 수와 통일하면 성공해요.
Errors
- Atom이 변수 —
instantiation_error - Atom이 변수도 원자도 아님 —
type_error(atom, Atom) - Length가 변수도 정수도 아님 —
type_error(integer, Length) - Length가 0보다 작은 정수 —
domain_error(not_less_than_zero, Length)
Portability: ISO 술어.
atom_concat/3
Templates
atom_concat(+atom, +atom, ?atom)
atom_concat(?atom, ?atom, +atom)
Description
atom_concat(Atom1, Atom2, Atom12)는 Atom12의 이름이 Atom1의 이름과 Atom1의 이름의 결합이면 성공해요. 이 술어는 백트래킹 시 재실행 가능해요(예: Atom12가 인스턴스화되고 Atom1과 Atom2가 모두 변수인 경우).
Errors
- Atom1과 Atom12가 모두 변수 —
instantiation_error - Atom2와 Atom12가 모두 변수 —
instantiation_error - Atom1이 변수도 원자도 아님 —
type_error(atom, Atom1) - Atom2가 변수도 원자도 아님 —
type_error(atom, Atom2) - Atom12가 변수도 원자도 아님 —
type_error(atom, Atom12)
Portability: ISO 술어.
sub_atom/5
Templates
sub_atom(+atom, ?integer, ?integer, ?integer, ?atom)
Description
sub_atom(Atom, Before, Length, After, SubAtom)는 원자 Atom이 세 원자 AtomL, SubAtom, AtomR로 분할될 수 있어서 Before가 AtomL의 이름의 문자 수, Length가 SubAtom의 이름의 문자 수, After가 AtomR의 이름의 문자 수이면 성공해요. 이 술어는 백트래킹 시 재실행 가능해요.
Errors
- Atom이 변수 —
instantiation_error - Atom이 변수도 원자도 아님 —
type_error(atom, Atom) - SubAtom이 변수도 원자도 아님 —
type_error(atom, SubAtom) - Before가 변수도 정수도 아님 —
type_error(integer, Before) - Length가 변수도 정수도 아님 —
type_error(integer, Length) - After가 변수도 정수도 아님 —
type_error(integer, After) - Before가 0보다 작은 정수 —
domain_error(not_less_than_zero, Before) - Length가 0보다 작은 정수 —
domain_error(not_less_than_zero, Length) - After가 0보다 작은 정수 —
domain_error(not_less_than_zero, After)
Portability: ISO 술어.
char_code/2
Templates
char_code(+character, ?character_code)
char_code(-character, +character_code)
Description
char_code(Char, Code)는 한 문자 원자 Char의 문자 코드가 Code이면 성공해요.
Errors
- Char와 Code가 모두 변수 —
instantiation_error - Char가 변수도 한 문자 원자도 아님 —
type_error(character, Char) - Code가 변수도 정수도 아님 —
type_error(integer, Code) - Code가 정수이지만 문자 코드가 아님 —
representation_error(character_code)
Portability: ISO 술어.
lower_upper/2
Templates
lower_upper(+character, ?character)
lower_upper(-character, +character)
Description
lower_upper(Char1, Char2)는 Char1과 Char2가 한 문자 원자이고 Char2가 Char1의 대문자 변환이면 성공해요. Char1(각각 Char2)이 소문자(각각 대문자) 문자가 아닌 문자이면 Char2는 Char1과 같아요.
Errors
- Char1과 Char2가 모두 변수 —
instantiation_error - Char1이 변수도 한 문자 원자도 아님 —
type_error(character, Char1) - Char2가 변수도 한 문자 원자도 아님 —
type_error(character, Char2)
Portability: GNU Prolog 술어.
atom_chars/2, atom_codes/2
Templates
atom_chars(+atom, ?character_list)
atom_chars(-atom, +character_list)
atom_codes(+atom, ?character_code_list)
atom_codes(-atom, +character_code_list)
Description
atom_chars(Atom, Chars)는 Chars가 이름이 Atom의 이름의 연속 문자들인 한 문자 원자들의 리스트이면 성공해요. atom_codes(Atom, Codes)는 atom_chars/2와 비슷하지만 문자 코드 리스트를 다뤄요.
Errors
- Atom이 변수이고 Chars(또는 Codes)가 부분 리스트이거나 변수인 요소를 가진 리스트 —
instantiation_error - Atom이 변수도 원자도 아님 —
type_error(atom, Atom) - Chars가 리스트도 부분 리스트도 아님 —
type_error(list, Chars) - Codes가 리스트도 부분 리스트도 아님 —
type_error(list, Codes) - Chars 리스트의 어떤 요소 E가 변수도 한 문자 원자도 아님 —
type_error(character, E) - Codes 리스트의 어떤 요소 E가 변수도 정수도 아님 —
type_error(integer, E) - Codes 리스트의 어떤 요소 E가 정수이지만 문자 코드가 아님 —
representation_error(character_code)
Portability: ISO 술어. ISO 참조는 Atom이 변수이고 Chars가 리스트도 부분 리스트도 아닐 때만 type_error(list, Chars)를 일으켜요. GNU Prolog는 Chars가 리스트인지 항상 확인해요. Codes도 마찬가지. Codes의 요소 E가 정수가 아닐 때의 type_error(integer, E)는 GNU Prolog 확장이에요. 이는 문자 코드를 받는 많은 다른 내장 술어(예: char_code/2, put_code/2)에서 이 오류가 감지되므로 ISO 참조의 누락으로 보여요.
number_atom/2, number_chars/2, number_codes/2
Templates
number_atom(+number, ?atom)
number_atom(-number, +atom)
number_chars(+number, ?character_list)
number_chars(-number, +character_list)
number_codes(+number, ?character_code_list)
number_codes(-number, +character_code_list)
Description
number_atom(Number, Atom)— Atom이 Number의 문자들에 대응하는 이름을 가진 원자이면 성공.number_chars(Number, Chars)—number_atom/2와 비슷하지만 문자 리스트를 다룸.number_codes(Number, Codes)—number_atom/2와 비슷하지만 문자 코드 리스트를 다룸.
Errors
- Number와 Atom이 모두 변수 —
instantiation_error - Number가 변수이고 Chars(또는 Codes)가 부분 리스트이거나 변수인 요소를 가진 리스트 —
instantiation_error - Number가 변수도 숫자도 아님 —
type_error(number, Number) - Atom이 변수도 원자도 아님 —
type_error(atom, Atom) - Chars가 리스트도 부분 리스트도 아님 —
type_error(list, Chars) - Codes가 리스트도 부분 리스트도 아님 —
type_error(list, Codes) - Chars 리스트의 어떤 요소 E가 변수도 한 문자 원자도 아님 —
type_error(character, E) - Codes 리스트의 어떤 요소 E가 변수도 정수도 아님 —
type_error(integer, E) - Codes 리스트의 어떤 요소 E가 정수이지만 문자 코드가 아님 —
representation_error(character_code) - Number가 변수이고 Atom(또는 Chars 또는 Codes)이 숫자로 파싱될 수 없고
syntax_errorProlog 플래그 값이 error(8.22.1절) —syntax_error(오류를 설명하는 원자)
Portability: number_atom/2는 GNU Prolog 술어. number_chars/2와 number_codes/2는 ISO 술어. GNU Prolog는 Number가 변수일 때만 Chars(또는 Codes) 리스트의 요소 E에 대해 오류를 발생시키는 반면, ISO 참조는 항상 이를 확인해요. 이는 리스트 자체가 Number가 변수일 때만 확인되므로 오류인 것 같아요. Codes의 요소 E가 정수가 아닐 때의 type_error(integer, E)는 GNU Prolog 확장이에요. 이는 문자 코드를 받는 많은 다른 내장 술어(예: char_code/2, put_code/2)에서 이 오류가 감지되므로 ISO 참조의 누락으로 보여요.
name/2
Templates
name(+atomic, ?character_code_list)
name(-atomic, +character_code_list)
Description
name(Constant, Codes)는 Codes가 Constant(숫자 또는 원자)의 연속 문자들에 대응하는 문자 코드들의 요소를 가진 리스트이면 성공해요. 그러나 name(Constant, Codes)가 참인 원자 중 상수가 인스턴스화되지 않은 채 name/2가 호출되면 만들어지지 않을 원자들이 있어요. 예: 원자 1024. 이런 이유로 name/2의 사용은 권장되지 않으며 호환성 목적으로 제한되어야 해요. atom_codes/2(8.19.6절)나 number_chars/2(8.19.7절)를 사용하는 것이 더 좋아요.
Errors
- Constant가 변수이고 Codes가 부분 리스트이거나 변수인 요소를 가진 리스트 —
instantiation_error - Constant가 변수도 원자 항(atomic term)도 아님 —
type_error(atomic, Constant) - Constant가 변수이고 Codes가 리스트도 부분 리스트도 아님 —
type_error(list, Codes) - Constant가 변수이고 Codes 리스트의 어떤 요소 E가 변수도 정수도 아님 —
type_error(integer, E) - Constant가 변수이고 Codes 리스트의 어떤 요소 E가 정수이지만 문자 코드가 아님 —
representation_error(character_code)
Portability: GNU Prolog 술어.
new_atom/2, new_atom/1
Templates
new_atom(+atom, -atom)
new_atom(-atom)
Description
new_atom(Prefix, Atom)은 이름이 Prefix의 이름의 문자들로 시작하는 새 원자와 Atom을 통일해요. 이 술어는 기호 생성기예요. new_atom/3 호출 전에 Atom이 존재하지 않는다는 것이 보장돼요. Prefix에 덧붙여 Atom을 형성하는 문자들은 A-Z(대문자), a-z(소문자), 0-9(숫자) 중 하나예요.
new_atom/1은 new_atom(term_, Atom)과 비슷해요. 즉 생성된 원자는 term_로 시작해요.
Errors
- Prefix가 변수 —
instantiation_error - Prefix가 변수도 원자도 아님 —
type_error(atom, Prefix) - Atom이 변수가 아님 —
uninstantiation_error(Atom)
Portability: GNU Prolog 술어.
current_atom/1
Templates
current_atom(?atom)
Description
current_atom(Atom)은 Atom과 통일하는 원자가 존재하면 성공해요. $로 시작하는 것을 제외한 모든 원자가 발견돼요(시스템 원자). 이 술어는 백트래킹 시 재실행 가능해요.
Errors
- Atom이 변수도 원자도 아님 —
type_error(atom, Atom)
Portability: GNU Prolog 술어.
atom_property/2
Templates
atom_property(?atom, ?atom_property)
Description
atom_property(Atom, Property)는 current_atom(Atom)이 성공하고(8.19.10절) Property가 원자의 속성 중 하나와 통일하면 성공해요. 이 술어는 백트래킹 시 재실행 가능해요.
원자 속성:
length(Length)— Length가 원자 이름의 길이.hash(Hash)— Hash가 원자의 해시 코드.term_hash/2(8.4.8절)도 참조.prefix_op— 이 이름으로 현재 정의된 접두 연산자가 있으면.infix_op— 이 이름으로 현재 정의된 중위 연산자가 있으면.postfix_op— 이 이름으로 현재 정의된 후위 연산자가 있으면.needs_quotes— 나중에 읽기 위해 원자를 인용해야 하면.needs_scan— 읽기 위해 출력할 때 원자를 스캔해야 하면(예:\이스케이프 시퀀스로 출력해야 하는 특수 문자 포함).
Errors
- Atom이 변수도 원자도 아님 —
type_error(atom, Atom) - Property가 변수도 원자 속성 항도 아님 —
domain_error(atom_property, Property) - Property =
length(E)또는hash(E)이고 E가 변수도 정수도 아님 —type_error(integer, E)
Portability: GNU Prolog 술어.