Lecture Programming languages (2/e): Chapter 13b - Tucker, Noonan

Chapter 13b - Smalltalk. Smalltalk is a very simple language, both syntactically and semantically. The power of Smalltalk comes from its class libraries, most of which are written in Smalltalk itself. Interestingly, even control structures are objects in Smalltalk. | Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised that ancient and Modern writers have not attributed greater importance to the laws of inheritance . Alexis de Tocqueville Contents Prelude: Abstract Data Types The Object Model Smalltalk Java Python Smalltalk the original object-oriented language developed in 1970s at Xerox PARC Xerox Alto Smalltalk system OS IDE mouse based GUI Steve Jobs visit General Characteristics Simple language Most of the class libraries written in Smalltalk Everything is an object, even control structures Excluding lexical productions, grammar has 21 productions (3 pages) The value of every variable is an object; every object is an instance of some class. A method is triggered by sending a message to an object. The object responds by evaluating the method of the same name, if it has one. Otherwise the message is sent to the parent object. The process continues until the method is found; otherwise an error is raised. All methods return a value (object). Precedence Unary messages, as in: x negated Binary messages, as in: x + y Keyword messages, as in: Turtle go: length In the absence of parentheses, code is evaluated from left to right. Examples: x + y * z squared a max: b - c anArray at: i put: (anArray at: i + 1) By default, Smalltalk uses infinite precision, fractional arithmetic. 1/3 + 2/6 + 3/9 evaluates to 1. (a > b) ifTrue: [ max := a ] ifFalse: [ max := b ]. [ ] - uninterpreted block Boolean method Distinct from: ifFalse:ifTrue: sum := 0. 1 to: n do: [ :i | sum := sum + (a at: i) ]. sum := 0. a do: [ :x | sum := sum + x ]. sum := 0. i := 1. [ i <= n ] whileTrue: [ sum := sum + (a at: i). i := i + 1]. "True methods" ifTrue: trueBlock ifFalse: falseBlock ^ trueBlock value ifTrue: aBlock ^ aBlock value ifFalse: aBlock ^ nil ifFalse: falseBlock ifTrue: trueBlock ^ trueBlock value Examle: Polynomials Represent Polynomials: 3 x2 + 5x - 7 Representation: | Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised that ancient and Modern writers have not attributed greater importance to the laws of inheritance . Alexis de Tocqueville Contents Prelude: Abstract Data Types The Object Model Smalltalk Java Python Smalltalk the original object-oriented language developed in 1970s at Xerox PARC Xerox Alto Smalltalk system OS IDE mouse based GUI Steve Jobs visit General Characteristics Simple language Most of the class libraries written in Smalltalk Everything is an object, even control structures Excluding lexical productions, grammar has 21 productions (3 pages) The value of every variable is an object; every object is an instance of some class. A method is triggered by sending a message to an object. The object responds by evaluating the method of the same name, if it has one. Otherwise the message is sent to the parent object. The process continues until the .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
160    324    2    01-05-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.