0
(define (make-checking beg-bal)
(let* ((balance beg-bal)
(tlist '()))
(define (writer s x)
(display s)
(display x)
(newline))
(define (deposit f)
(set! balance (+ balance f))
(set! tlist (append tlist (list f))))
(define (withdraw f)
(cond ((> funds balance)
"Insufficient Funds")
(else
(set! balance (- balance f))
(set! tlist f))))
(define (write-check f)
(cond ((< balance f) "Insufficient Funds")
((<= f balance)
(set! balance (- balance f))
(set! tlist (append tlist (list (* -1 f)))))
(else (display "Error") 'done)))
(define (print-statement)
(let ((t tlist) (z 0))
(display (string-append "Beginning Balance: " (number->string beg-bal)))
(newline)
(cond ((null? t) 'done)
((< (car t) 0) (string-append "Transaction: Check Amount: " (number->string (car t))))
((> (car t) 0) (string-append "Transaction: Check Amount: " (number->string (car t))))
(else print-statement))
(display (string-append "Balance: " (number->string balance)))
(newline)))
(define (current-balance)
balance)
(lambda (method)
(cond ((eq? method 'beg-bal) beg-bal)
((eq? method 'deposit) deposit)
((eq? method 'withdraw) withdraw)
((eq? method 'write-check) write-check)
((eq? method 'print-statement) print-statement)
((eq? method 'balance) current-balance)
(else 'undefined-operation)))))
"Tests"
(define checking (make-checking 100))
((checking 'write-check) 10)
((checking 'write-check) 10)
((checking 'deposit) 100)
((checking 'write-check) 10)
((checking 'print-statement))
((checking 'balance))
누군가가 출력을 print-statement
함수로 실행할 때 왜 출력되지 않는지 알 수 있습니까? 단어가있는 출력은 display
함수로 인해 문자열과 반환으로 간주되고 하단의 170
은 전체 함수에서 반환되는 단어입니다.구성표 기능을 확인하십시오.
> beginning balance: 100
> transaction: check amount: -10
> transaction: check amount: -10
> transaction: deposit amount: 100
> transaction: check amount: -10
> balance: 170
> 170
와우이 작품에 큰 도움을 주셔서 감사합니다! – dscarf