2 7 1 data type Lisp S CAR

















![18 7. 4 배열 • 구조 자료형(structured data types) – [집합체(aggregate), 복합형(composite type)] – 18 7. 4 배열 • 구조 자료형(structured data types) – [집합체(aggregate), 복합형(composite type)] –](https://slidetodoc.com/presentation_image_h/c3c7047f4adfdbadab64069a1d1c8d48/image-18.jpg)



















































- Slides: 69
2 7. 1 자료형과 선언 • 자료형 (data type) • 자료형 - 객체 집합 + 연산(생성, 작성, 소멸, 수정, 분해) 예) Lisp - S-식 + CAR, CDR, CONS 예) 명령형 PL - 기본 자료형 : 정수, 실수, 문자, 논리 형 등등 • 이 장에서 다룰 자료형의 범주 – 내장 자료형 : 표현법, 연산 – 사용자 정의 자료형 • 기본 자료형 Fortran 77 INTEGER REAL LOGICAL CHARACTER DOUBLE COMPLEX C int short long float double char Java int short byte long float double char boolean Ada integer float boolean character natural duration priority
16 7. 3 열거형 (Enumerated Data Types) • 순서 관련 연산 pred(wed) => tue pred(sun) => 미정의 succ(wed) => thu succ(sat) => 미정의 • <순서 관련 연산자> • pred(x) - x 이전에 정의된 값 • succ(x) - x 다음에 정의된 값 • ord(x) - x가 정의된 위치 열거형 문제점 – 다중 정의(Multiple definition) - 동일한 상수를 두 열거형의 리터럴 값으로 사용 : 형 대조시 문제 - Pascal : 불허용, Ada : 허용 – Ada의 예 type months is (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov , Dec); type summermonths is (Jun, Jul, Aug); X : months; Y : summermonths; ORD(Jul) ? ? ? months’ORD(Jul) 또는 summermonths’ORD(Jul) 로 구분
18 7. 4 배열 • 구조 자료형(structured data types) – [집합체(aggregate), 복합형(composite type)] – 여러 자료를 묶어 하나의 단위로 처리하는 자료형 – 배열(array) - homogeneous data 모임 – 레코드(record) - heterogeneous data 모임 집합체(aggregate) 배열형 (array type) , 배열(array)
27 7. 4 배열 • Pascal – 배열 첨자 : 실수형을 제외한 스칼라형 (정수형, 열거형) var temperature:array [months] of real; rainfall :array [months] of real; i : months; . . . temperature : =(15. 5, 12, 10. 4, 29, 45, 65. 5, 78, 84, 82, 61, 42, 22. 5); rainfall : = (10. 6, 15. 5, 22. 5, 30, 15, 5. 4, 0. 5, 0. 1, 0. 6, 1. 8, 6. 6, 10. 5) ; temperature[May] : = 25. 5; for i : =Jan to Dec do x : = x + temperature[i];
30 7. 4 배열 • 배열 연산 Fortran, Algol 60 배열 원소에 대한 연산만 가능 APL, PL/I, Algol 68 배열 배정 연산(A←B, A = B, A: =B ) 예) PL/I DCL A(10, 10), B(10) 배열 복사(B = A(i , *)) • 배열 초기화(Ada) type MAT is array(INTEGER range 1. . 2, INTEGER range 1. . 2) of INTEGER; A:MAT : =((10, 20), (30, 40)); A:MAT : = (1 => 1, others => 0), 2 => (2 => 1, others => 0));
33 7. 6 레코드 • • 이질형 요소들의 모임인 자료형 예) Pascal type stock = record name:array[1. . 30] of char; price:array[1. . 365] of real; dividend:real; volume:array[1. . 365] of integer; exchange:(nyse, amex, nasdaq) end; var newstock, ibm:stock; • • stock : 5개 필드로 구성된 레코드형 • 필드 ① price, volumn : 숫자형 배열 ② name : 문자형 배열 ③ dividend : 실수형 ④ exchange : 열거형(nyse, amex, nasdaq) • newstock, ibm : 레코드형(stock) 변수 필드 참조 방식 ① 필드(변수명) name(ibm), price(ibm)[25], dividend(ibm), volumn(ibm)[25], exchange(ibm) ② 변수명. 필드(Pascal, Ada) ibm. name, ibm. price[25], ibm. dividend, ibm. volumn[25], ibm. exchange ③ 필드 of 변수명 (Algol 68) name of ibm, price[25] of ibm
34 7. 6 레코드 • 역사 – Cobol 시작(structure) – PL/I – Pascal(record) => 가변부(variant part) 추가 • 레코드 초기화 (Algol W, Algol 68, Ada) var ibm, csc:stock; ibm : =make-stock('IBM', 0. . 0, 5. 25, 0. . 0, nyse ); csc : =make-stock('Computer Science Corp. ', 0. . 0, 0, 0. . 0, nyse); • with문(Pascal) – 변수명을 생략하는 필드 지정 구문 newstock. name : ="dec"; newstock. dividend : =36; newstock. exchange : =amex; with newstock do begin name : ="dec"; dividend : =36; exchange : =amex; end;
35 7. 6 레코드 • Ada의 레코드 사용 예 – Ada type FLIGHT; type LISTOFFLIGHTS is access FLIGHT; type FLIGHT is record FLIGHTNO : INTEGER range 0. . 100; SOURCE : STRING; DESTINATION : STRING; RETURNFLIGHT : LISTOFFLIGHTS; end record; X, Y : LISTOFFLIGHTS; . . . • X. RETURNFLIGHTS : FLIGHT형을 가리키는 X. RETURNFLIGHTS : = Y; 포인터 (여기서는 Y를 가리킴) • 사용 X. RETURNFLIGHTS. FLIGHTNO X. RETURNFLIGHTS. SOURCE
40 7. 7 포인트 자료형 (Point Data Types) • • 예) Ada type NODEPTR is access NODE type NODE is record NUMBER : REAL; NEXT : NODEPTR; end record; 객체 생성 및 값 배정 (Pascal과 Ada 비교) var P, Q:NODEPTR;. . . new(P); P↑. NUMBER : = 3. 54; P↑. NEXT : = nil; • Pascal Ada var P, Q:NODEPTR : = new NODE(3. 54, nil); 필드 접근과 복사 (Ada에서의 field 지정) P. NEXT : = Q. NEXT; Ada P. NUMBER : = Q. NUMBER; Ada P. all : = Q. all
53 7. 9 자료형의 동치 (Equivalence) • 부 자료형 (sub type) – Pascal, Modula-2의 부분 영역형 – Ada에서 사용 • subtype aint is INTEGER range 1. . 100 ; • 파생 자료형 (derived type) – 부분 영역형을 새 자료형으로 간주 – Ada에서 사용 • type bint is new INTEGER range 100 ;
56 자료형 (data type) 용어 국제 표준 규격 15. 04. 01 data type 자료형 A defined set of data objects of a specified data structure and a set of permissible operations, such that these data objects act as operands in the execution of any one of these operations. <Example> An integer type has a very simple structure, each occurrence of which, usually called value, is a representation of a member of a specified range of whole numbers and the permissible operations include the usual arithmetic operations on these integers. <NOTE> The term " type" may be used instead of "data type" when there is no ambiguity. 명시된 자료 구조를 갖는 자료 객체들의 정의된 집합과, 어떤 연산의 수행 중 그 자료객체가 피 연산자로 쓰이도록 허용된 연산들의 집합 <예> 정수형은 매우 간단한 구조를 가지며, 통상 값이라 불리는 것 즉 정수형의 값은 명시된 범위의 전체 수 중 한 원소의 표현이다. 그리고 이것에 허용된 연산으로는 이러한 정수에 대한 통상의 산술 연산이 포함된다. <주> 모호성이 없으면 “형(type)”은 “자료형(data type)”을 대신하여 사용되어질 수 있다.
57 강자료형 (strong typing) 용어 국제 표준 규격 15. 04. 30 strong typing 강자료형 Enforcement of the requirement that operands in a language construct must be of data types compatible with those of the operation or have explicitly undergone type conversion before the operation is performed. <Example> The strong typing in Ada makes the addition of 2 + 3. 5 illegal, because 2 is an integer and 3. 5 a real number. 언어 구성자에서 쓰인 피연사자들이 해당 연산에 적법한(compotible) 자료형이기를 요구하거나 연산이 수행되기 전에 명시적인 형 변환을 수행하도록 하는 요구 하는. <예> 강자료형인 Ada에서 2 + 3. 5 덧셈은 부적절하다. 왜냐하면 2는 정수이고, 3. 5는 실수이기 때문이다
58 스칼라형 (data type) 용어 국제 표준 규격 15. 04 scalar type simple type 스칼라형 단순형 A data type, each instance of which represents a scalar. <NOTE> pascalar types are either ordinal types or real types. Ada scalar types are either discrete types or real types 각각의 인스턴스가 스칼라인 자료형 <주> Pascal의 스칼라형은 서수형이나 실수형이다. Ada의 스칼라형은 이산형이나 실수형이다.
59 다형성 (polymorphism) 용어 국제 표준 규격 15. 09. 10 polymorphism 다형성 The ability of different objects to respond to the same message differently. 다양한 객체들이 동일한 메시지에 다르게 응답하는 능력.
60 집합체 (aggregate) 용어 국제 표준 규격 15. 03. 06 aggregate 집합체 A structured collection of components, where the components may have the same or different data structure, and where the data structure of the collection itself may also be a constituent part of a corresponding composite type. 구조화된 구성 요소들의 모임인데, 그 구성 요소들은 동일하거나 상이한 다른 자료구조들을 가질 수 있으며 그 모임자체의 자료 구조 또한 상응하는 혼합형의 부분요소가 될 수 있다.
61 배열형 (array type) 용어 국제 표준 규격 15. 04. 19(15. 03. 08) 1. array type 2. array 배열형 배열 1. A composite type whose components are the same data type. 2. An aggregate that is an instance of an array type and each element or appropriate group of elements in which may be referenced randomly and independently of the others. <NOTE> Array types may be organized and referenced as if the components were arranged in columns, rows, etc. 1. 구성원들이 동일한 자료형인 복합형 2. 각 요소 또는 적정 그룹의 요소들이 다른 요소들과 독립적으로 임의로 참조될 수 있는, 배열형의 인스턴스인 집합체 <주> 배열형은 마치 구성 요소들이 열, 행으로 정렬되는 것처럼 구성되거나 참조 될 수 있다.
62 배열 슬라이스 (array slice) 용어 국제 표준 규격 15. 03. 09 array slice 배열 슬라이스 A portion of an array that consists of contiguous cells along any dimension. <NOTE> In Ada, an array slice is also a basic operation. 배열에서, 임의 한 차원에서의 연속적인 원소들로 구성되어진 부분 <주> Ada에서 배열 슬라이스는 기본 연산이다.
63 레코드형 (record type) 용어 국제 표준 규격 15. 04. 20 record type 레코드형 A composite type whose components are field types or other record types. <Example> A personnel record may consist of personal arranged as fields or subrecords within this personnel record. <NOTE> 1. A record type defines a set of values and operations. An instance of such a record type may contain values which themselves are records. 2. This definition is identical to the definition in entry 17. 05. 13 of ISO/IEC 2382 -17. The example and notes have been added. 구성요소들이 필드형 또는 다른 레코드형인 복합형 <예> 사원 레코드는 이 사원 레코드내의 필드 또는 하위레코드로 정렬된 개인 데이터로 구성될 수 있다. <주> 1. 레코드형은 값과 연산의 집합을 정의한다. 이런 레코드형의 인스턴스는 그 자신이 레코드인 값을 갖을 수 있다. 2. 이 정의는 ISO/IEC 2382 -17의 17. 05. 13 항목의 정의와 같다. 예와 주석문이 추가되어 왔다.
64 가변부 (variant part) 용어 국제 표준 규격 15. 03. 10 variant part 가변부 A part of a record, composed of data objects, whose corresponding data structures or declared data types may vary. <NOTE> Both the number of data objects and their composition may vary. 자료 객체들로 구성된 레코드의 한 부분으로, 해당 자료구조나 선언된 자료형이 변할 수 있는 부분 <주> 자료 객체의 수와 그들의 구성 모두 변형될 수 있다.
65 판별자 (discriminant) 용어 국제 표준 규격 15. 03. 12 discriminant (noun) 판별자 (명사) A parameter-like language construct that indicates the data structure to be used within a given variant record. 주어진 가변 레코드에서 사용되는 자료구조를 가리키는 매개변수와 유사한 언어 구성자
66 포인터 (pointer) 용어 국제 표준 규격 15. 03. 20 pointer (in programming language) 포인터(프로그래밍 언어에서) A data object whose data value is the address of another data object. 자신의 자료값이 다른 자료 객체의 주소가 되는 자료 객체
67 자료형 변환 (type conversion) 용어 국제 표준 규격 15. 03. 09 type conversion 형 변환 Transformation of the representation of data value of one data type to that of another data type, usually performed to avoid an illegal data type mismatch. <NOTE> Type conversion among numeric types frequently is permitted but may cause loss of accuracy, precision, or both. 한 자료형의 자료값 표현을 다른 자료형의 자료값 표현으로 변환하는 것, 보통 다른 자료형과의 타입이 맞지 않음을 피하기 위해 수행 <주> 수치형 사이에서 형변환은 자주 허락된다. 그러나 정확도, 정밀도 또는 둘 모두 를 잃게되는 원인이 될 수 있다.
68 부분 자료형 (sub type) 용어 국제 표준 규격 15. 04. 22 sub type 부분 자료형 A data type derived from another data type by one or more constraints on that other data type. 다른 자료형에 대한 하나 이상의 제약조건에 의해 그 자료형으로부터 파생된 자료형
69 파생 자료형 (derived type) 용어 국제 표준 규격 15. 04. 28 derived type 파생 자료형 A data type whose data values and operations are replicas of those of an existing parent type. <NOTE> 1. Strong typing prohibits operations among data values of different derived type, or between a derived type and a parent type, unless explicit type conversion is used. 2. The set of data value or the applicable operations of derived type may be reduced or expanded. 3. Contrast with parent type. 자료값과 연산들이 기존의 원 자료형에서 복사된 자료형 <주> 1. 만약 명백한 형 변환이 사용되지 않는다면, 강자료형은 다른 유도 자료형들의 자료값들 사이의 연산이나 유도 자료형과 원 자료형 사이의 연산을 금지한다. 2. 파생 자료형의 자료값 또는 적용가능한 연산들의 집합은 감소되거나 확장되어 질 수 있다. 3. 원 자료형과 대조