프로그래밍
• 뭔가를 해내는 방법을 기술하기
– “ 해내는” = “ 계산하는”
– 루트 2 를 찾는 방법 – 자장면을 만드는 방법 – 전화를 거는 방법
– 결혼을 하는 방법
• 뭔가를 정의하기 , 와는 다르다
– 루트 2 는 제곱하면 2 가 되는 수
– 자장면은 가장 싸고 맛있는 중국음식
– 전화걸기는 소리와 영상을 주고받고자 작업들어가는 것 – 결혼은 남자와 여자가 후손을 잘 만들어내기위한 계약
컴퓨터 프로그래밍의 어려움
• 프로그램은 규모와 복잡도가 점점 커짐
– 소프트웨어는 하드웨어가 더 좋아지는 속도보다 훨씬 빨리 더 복잡해지고 커진다
• 프로그램은 자동으로 실행됨
– 기계는 우리가 바라는 바를 실행하지 않는다
– 기계는 프로그램에 써 있는 것을 실행할 뿐이다
프로그래밍 시스템 기술의 대응
• 프로그램은 규모와 복잡도가 점점 커짐
– 프로그래밍을 점점 더 상위에서 하도록하는 도구 제공 :
• 프로그래밍 언어 시스템 : bits, assembly, C, Java, C#, Schem e, ML, etc.
– 계산의 복잡한 내용을 쉽게 관리하는 도구 제공 :
• 프로그래밍 언어 시스템 : C, Java, ML, Scheme, C#, etc.
• 프로그램이 자동으로 실행됨
– 프로그램의 오류를 자동으로 검증하는 도구 제공
• 1 세대 ( 문법검증 ): all languages
• 2 세대 ( 타입검증 ): ML, Java
• 3 세대 … : new frontiers
목표 = 그 대응의 개념 / 구조 / 방법 / 미래기술등을 실습을 통해서 익히기
이제 시작해 봅시다
프로그램을 구성하는 데 필요한 요소
• 기본원소들 primitives
– voltages, resistors, capacitors, inductors, … – 0, 1, AND gates, OR gates, NOT gates, … – integers, strings, booleans, +, -, =, ^, …
• 조합하는 방법들 means of combination
– rules about wiring together in an electronic circuit – rules about connecting together in a Boolean circuit – rules about composing together in a compound
• 속내용을 감추는 방법들 means of abstraction
– black boxes: amplifier, receiver, transmitter, … – black boxes: XOR, MUX, …
– black boxes: min, max, average, marry … pair, list, tree, set, vehicle, fire, …
• 실행과정의 이해
– electronic laws about V, I, R, C – truth tables of Bollean gates – evaluation rules of programs
Programming Elements
• 기본원소들 primitives
• 조합하는 방법들 means of combination
• 속내용을 감추는 방법들 means of abstract ion
• 프로그램 실행과정의 이해 rule of evaluatio n
Scheme Basics:
expressions, values, types
• an expression computes a value, which i s returned when the expression is evalua
ted
• every value has a type
now on in Scheme
Programming Elements: primitives
type elements built-in operators
numbers 0, -1, 10, 1.2, 2.3e4 +, -, /, *, =, <, >, <=,
>=
strings “snow”, “thi
s is @” stringlength, string=
?
booleans #t, #f and, or, not
primitives
Programming Elements: primitives
• primitives are self-evaluating exprs
– 1 evaluates to number 1 – #t evaluates to boolean #t – “a” evaluates to string “a”
– + evaluates to number-addition operator + – / evaluates to number-division operator /
• primitives are also called “constants”
Programming Elements:
combinations
• open paranthesis, expressions, close pa ranthesis
• the expression evaluates the sub-expressions then apply the value of the 1st-subexpr to the values of argument exprs
• the 1st-subexpr must evaluate to a procedure
(+ 1 2)
compound expressions
Programming Elements:
combinations
can use nested combinations
use the combination rule recursively
(+ (* 1 2) 3)
(* (+ 1 2) (- 1 2))
Programming Elements: abstracti ons (naming)
• (define pi 3.14)
• name pi now means value 3.14
• such name-value pairs are remembered by the computer in a table called “enviro
nment”
• can use pi for 3.14 thereafter (define pi 3.14)
(* pi 10)
Programming Elements: abstracti ons (naming)
• (define <name> <expr>)
evaluates the <expr> and its return-value is named <name>.
(define pi 3.14)
(define x (+ (* pi 10) 0.1)) (= (+ x x) (* 2 x))
Scheme Basics:
rule of evaluation
• if primitives, return value
• if name, return its associated value in en vironment
• if special form, do something special
• if compound expr, then
– evaluate all the sub-expressions
– apply the operator value to the values of th e operands and return the result
Read-Eval-Print
Read
Compile; Evaluate
execution world visible world
visible world
(* 2 (+ 3 4))
internal representation of expr
value of expr
14
The Two Worlds
visible world
syntax
execution world
semantics
expr
printed representation of value
value 12 value 3.14
12 12