| 이전 주제 보기 :: 다음 주제 보기 |
| 글쓴이 |
메시지 |
최민아
가입: 2009년 9월 28일 올린 글: 236
|
올려짐: 2012년10월18일 22:46 주제: 10.18 실습 문서가 한번 더 수정되었습니다. + 뼈대코드 추가 (2012.10.27 17:40 수정) |
|
|
10.18 실습 문서를 수정하였습니다.
http://ropas.snu.ac.kr/~ta/4190.210/12/practice/ex5.pdf
switch-inputs를 없앴습니다. switch-input은 initial-wire-volt에 포함되므로 필요하지 않습니다.
회로가 바뀌는 것을 볼 수 있도록, 테스트케이스를 수정하고 추가했습니다.
명령형 프로그래밍을 위한 make-wire를 포함하고 있는 테스트 코드를 추가했습니다.
오타를 수정했습니다.
실습은 10월 28일 전까지 제출해 주시기 바랍니다.
---------
실습문제를 다시 수정하였습니다.
명령형(물건중심) 프로그래밍에 대한 강의록 링크를 최신 강의록 주소로 수정했습니다.
http://ropas.snu.ac.kr/~kwang/4190.210/12/3.pdf
전깃줄, wire, 와이어 등을 전깃줄로, volt, 볼트 등을 전위로 통일했습니다.
최민아 가 2012년10월27일 17:43에 수정함, 총 2 번 수정됨 |
|
| 위로 |
|
 |
조동철
가입: 2011년 9월 6일 올린 글: 35
|
올려짐: 2012년10월18일 22:54 주제: |
|
|
------------------------------------------------------------------------
제가 잘 못 알고 있었네요.
예제코드 수정없이 그냥 사용하겠습니다.
조동철 가 2012년10월19일 16:43에 수정함, 총 1 번 수정됨 |
|
| 위로 |
|
 |
임성철
가입: 2012년 9월 8일 올린 글: 35
|
올려짐: 2012년10월18일 23:17 주제: |
|
|
| 인용: |
set-wire-volts : initial-wire-volts circuit ! circuit state
|
| 인용: |
set-wire-volts : initial-wire-volts circuit ! circuit
|
그리고 이 두 개 중에 어떤 구현이 맞는 거에요?
값중심 구현하고 명령 구현의 함수 정의가 다르게 되어있어서요 |
|
| 위로 |
|
 |
최민아
가입: 2009년 9월 28일 올린 글: 236
|
올려짐: 2012년10월19일 16:18 주제: |
|
|
run과 print는 parameter 여러개를 받는 것이 아니라 pair 한 개를 받습니다.
(문서에 *가 아니라 X로 나와있습니다.)
값중심 구현과 명령형 구현의 타입이 다릅니다.
명령형 구현에서는 wire의 voltage 값들이 wire 자체에 포함되어 있기 때문에 circuit만으로 충분합니다.
값 중심 구현에서는 wire가 문자열이므로 따로 wire별 voltage가 필요해 state가 필요합니다. |
|
| 위로 |
|
 |
민현기
가입: 2012년 9월 15일 올린 글: 29
|
올려짐: 2012년10월23일 20:07 주제: |
|
|
세번째 회로에서 오타가 있는 것 같습니다.
(define or1 (or-gate "w1" "w2" "w3"))
(define not1 (not-gate "w3" "w1"))
(define switch1 (switch "w2"))
(define circuit1 (add-gate-to-circuit "or1" or1 empty-circuit))
(define circuit2 (add-gate-to-circuit "not1" not1 citcuit1))
(define circuit3 (add-gate-to-circuit "switch1" switch1 circuit2))
(define circuit-state
(set-wire-volts
(list
(cons "w1" zero) (cons "w2" zero) (cons "w3" zero) (cons "w4" one))
circuit4))
(print (run circuit-state 3))
> w1 1
> w2 0
> w3 1
여기서 (cons "w4" one)는 아예 없는 wire 인데 들어가 있습니다.
또 cirucuit4는 없는데 지금 입력으로 들어옵니다. 이걸 circuit3 로 바꿔줘야 맞는 것 같습니다.
또 결과물 역시 (print (run circuit-state 3)) 이 아니라
(print (run circuit-state 2)) 가 되어야 아래 결과와 일치하는 것 같습니다. |
|
| 위로 |
|
 |
최민아
가입: 2009년 9월 28일 올린 글: 236
|
|
| 위로 |
|
 |
최민아
가입: 2009년 9월 28일 올린 글: 236
|
올려짐: 2012년10월26일 13:34 주제: |
|
|
| 코드: | (define empty-circuit ())
(define (add-gate-to-circuit gate-name gate circuit)
(cons (cons gate-name gate) circuit))
(define (and-gate w1 w2 w3)
(list 'and w1 w2 w3))
(define (or-gate w1 w2 w3)
(list 'or w1 w2 w3))
(define (not-gate w1 w2)
(list 'not w1 w2))
(define (switch w1)
(list 'switch w1))
(define (match-gate output circuit)
(define name-gate-lst (filter (lambda (p) ...) circuit))
(if (null? name-gate-lst)
null
(cdr (car name-gate-lst))))
(define (input-wire gate n)
(list-ref gate n))
(define (output-wire gate)
(list-ref gate (- (length gate) 1)))
(define (is-and? gate)
(and
(list? gate)
(equal? 'and (car gate))))
(define (is-or? gate)
...)
(define (is-not? gate)
...)
(define (is-switch? gate)
...)
(define (set-wire-volts initial-wire-volts circuit)
(cons circuit initial-wire-volts))
(define one ...)
(define zero ...)
(define (step circuit-state)
(define circuit ...)
(define state ...)
(define (find-volt wire state) ;; find voltage of given wire in state
...)
(define next-state
(map (lambda (wire-volt)
(letrec ((wire ...)
(volt ...)
(gate (match-gate wire circuit)))
(cond ((null? gate) wire-volt)
((is-and? gate)
...)
((is-or? gate)
...)
((is-not? gate)
...)
(else wire-volt))))
state) )
(cons circuit next-state))
(define (run circuit-state n)
(if (= 0 n)
...
(run (step ...) (...))))
(define (print circuit-state)
(define (print-state state)
(cond ((null? state) (newline))
(else (begin
(display ...)
(display " ")
(display ...)
(newline)
(print-state ...)))))
(define state (cdr circuit-state))
(print-state state))
;; test 1.
(define and1 (and-gate "w1" "w2" "w3"))
(define or1 (or-gate "w3" "w4" "w5"))
(define not1 (not-gate "w5" "w2"))
(define switch1 (switch "w1"))
(define switch2 (switch "w4"))
(define circuit1 (add-gate-to-circuit "and1" and1 empty-circuit))
(define circuit2 (add-gate-to-circuit "or1" or1 circuit1))
(define circuit3 (add-gate-to-circuit "not1" not1 circuit2))
(define circuit4 (add-gate-to-circuit "switch1" switch1 circuit3))
(define circuit5 (add-gate-to-circuit "switch2" switch2 circuit4))
(define circuit-state
(set-wire-volts
(list
(cons "w1" zero) (cons "w2" zero) (cons "w3" zero) (cons "w4" one) (cons "w5" one))
circuit5))
(print (run circuit-state 1))
;; test 2
(define and1 (and-gate "w1" "w2" "w3"))
(define not1 (not-gate "w3" "w1"))
(define switch1 (switch "w2"))
(define circuit1 (add-gate-to-circuit "and1" and1 empty-circuit))
(define circuit2 (add-gate-to-circuit "not1" not1 circuit1))
(define circuit3 (add-gate-to-circuit "switch1" switch1 circuit2))
(define circuit-state
(set-wire-volts
(list (cons "w1" one) (cons "w2" one) (cons "w3" zero)) circuit3))
(print (run circuit-state 3))
;; test 3
(define or1 (or-gate "w1" "w2" "w3"))
(define not1 (not-gate "w3" "w1"))
(define switch1 (switch "w2"))
(define circuit1 (add-gate-to-circuit "or1" or1 empty-circuit))
(define circuit2 (add-gate-to-circuit "not1" not1 circuit1))
(define circuit3 (add-gate-to-circuit "switch1" switch1 circuit2))
(define circuit-state
(set-wire-volts
(list
(cons "w1" zero) (cons "w2" zero) (cons "w3" zero))
circuit3))
(print (run circuit-state 2))
;; test 4
(define and1 (and-gate "w1" "w2" "w3"))
(define not1 (not-gate "w3" "w4"))
(define not2 (not-gate "w4" "w1"))
(define switch1 (switch "w2"))
(define circuit1 (add-gate-to-circuit "and1" and1 empty-circuit))
(define circuit2 (add-gate-to-circuit "not1" not1 circuit1))
(define circuit3 (add-gate-to-circuit "not2" not2 circuit2))
(define circuit4 (add-gate-to-circuit "switch1" switch1 circuit3))
(define circuit-state
(set-wire-volts
(list
(cons "w1" zero) (cons "w2" zero) (cons "w3" zero) (cons "w4" one))
circuit4))
(print (run circuit-state 1)) |
저번 주 실습 값 중심 구현 뼈대 코드입니다.
실습이 많이 어려우신 분들은 참고하세요.
물건 중심 구현도 비슷하게 하실 수 있습니다. |
|
| 위로 |
|
 |
김민석
가입: 2012년 9월 15일 올린 글: 40
|
올려짐: 2012년10월26일 21:19 주제: |
|
|
저번 실습때 2번은 안해도 된다고 하신거 같은데 2번도 해야하나요?
잘못 들었던 건지 기억이 잘 안나네요 |
|
| 위로 |
|
 |
최민아
가입: 2009년 9월 28일 올린 글: 236
|
올려짐: 2012년10월27일 16:31 주제: |
|
|
물건 중심 구현은 해야 합니다. 2번 collect 함수에 대해 말씀드렸습니다.
시험기간이라 바쁘신지 실습 제출하신 분이 드물고
collect가 어렵다는 의견이 많아
많이 어려우신 분들은 2번 collect 함수를 짜지 않으셔도 괜찮습니다.
이번 실습의 주목적은 같은 구현을 값 중심과 물건 중심으로 프로그래밍 해보는 것이니까요. |
|
| 위로 |
|
 |
|