Hatena::Groupsicp

EhrenのSICP学習場

 | 

2010-01-11

3.1.1 代入と局所状態(続き)

17:47

一応問題を全部解いたけど、どちらかというとメッセージパッシングとset!の練習の問題だから先を急ぐ人は別に解かなくてもいいのかも。

ex3.2

(define (make-monitored func)
  (let ((calls 0))
        (lambda (m)
          (cond ((eq? m 'how-many-calls?) calls)
                ((eq? m 'reset-count) (set! calls 0))
                (else
                 (begin (set! calls (+ calls 1))  (func m))
                 )
                )
          )
        ))

ex3.3

(define (make-acount balance password)
  (define (withdraw amount)
    (if (>= balance amount)
        (begin (set! balance (- balance amount))
               balance)
        "Insufficient funds"))
  (define (deposit amount)
    (set! balance (+ balance amount))
    balance)
  (define (dispatch pwd m)
    (if (eq? password pwd)
        (cond ((eq? m 'withdraw) withdraw)
              ((eq? m 'deposit) deposit)
              (else (error "Unknown request")))
        (error "Incorrect password")))
  dispatch)

ex3.4

(define (make-acount balance password)
  (define incorrect-types 0)
  (define (withdraw amount)
    (if (>= balance amount)
        (begin (set! balance (- balance amount))
               balance)
        "Insufficient funds"))
  (define (deposit amount)
    (set! balance (+ balance amount))
    balance)
  (define (call-the-cops)
    (error "call the cops!"))
  (define (dispatch pwd m)
    (if (eq? password pwd)
        (begin
          (set! incorrect-types 0)
          (cond ((eq? m 'withdraw) withdraw)
                ((eq? m 'deposit) deposit)
                (else (error "Unknown request"))))
        (begin
          (if (>= incorrect-types 6)
              (call-the-cops)
              (begin
                (set! incorrect-types (+ incorrect-types 1))
                (error "Incorrect password"))))))
  dispatch)

EasterEaster2012/01/10 06:53Why does this have to be the ONLY reliable srouce? Oh well, gj!

RayaneRayane2013/08/07 05:25That's a smart answer to a tricky qutesion

GauravGaurav2013/08/09 07:27Well done <a href="http://jakregph.com">arlitce</a> that. I'll make sure to use it wisely.

EniEni2013/08/15 13:24Just the type of ingihst we need to fire up the debate. http://yulljp.com [url=http://hfmrntv.com]hfmrntv[/url] [link=http://wmmuqfw.com]wmmuqfw[/link]

NollieNollie2016/05/11 00:42(Escctroniel) This TV has one of the smallest form factors of any of the 40″ flat screen LED TVs so fit in my rather small space 38 1/2″ x 24 1/2″. It has excellent picture and sound. The only reason that I rate it 4* instead of 5* is because it has rather limited inputs and outputs on the back panel (2 HDMI, 1 component video which can alternate as a composite video in) there is no VGA in for a computer, no S-video in, no audio out). It think it is an excellent value. Samsung obviously went with less inputs and outputs and putting their priority in the picture and sound quality of this TV.

 |