<jupyter_start><jupyter_text>SICP 习题 （3.4）解题总结: 给账号绑个110   SICP 习题 3.4 要求我们修改 3.3的(make-account)函数，增加一个输错密码的计数器，输错7次密码就打110报警。当然，这个只是个样例，没有真的对接电话接口。同样，代码没有特别需要讲解的：<jupyter_code>(define (make-account balance account-password)
  (define illegal-access-times 0)
  (define (withdraw amount)
    (if (>= balance amount)
	(begin (set! balance (- balance amount))
	       balance)
	"insufficient funds"))
  (define (deposit amount)
    (set! balance (+ balance amount))
    balance)

  (define (wrongpassword amount)
    (if (< illegal-access-times 7)
	(begin (set! illegal-access-times (+ illegal-access-times 1))
	"incorrect password")
	(begin 
	  (call-the-cops)
	  "incorrect password (and you don't know that I will call a cop)")))

  (define (call-the-cops)
    (display " cops are comming"))

  (define (rightpassword)
    (set! illegal-access-times 0))

  (define (dispatch password m)

    (if (not (equal? password account-password))
	wrongpassword
	(begin
	  (rightpassword)
	  (cond ((eq? m 'withdraw) withdraw)
		((eq? m 'deposit) deposit)
		(else (error "unknow request -- Make-Account"
			     m))))))
  dispatch)
(define (start-test-3-4)
  (define acc (make-account 100 'my-password))
  ((acc 'other-password 'deposit) 50)
  ((acc 'other-password 'deposit) 50)
  ((acc 'other-password 'deposit) 50)
  ((acc 'other-password 'deposit) 50)
  ((acc 'other-password 'deposit) 50)
  ((acc 'other-password 'deposit) 50)
  ((acc 'other-password 'deposit) 50)
  ((acc 'other-password 'deposit) 50)
  
  )
(start-test-3-4)<jupyter_output>cops are comming
{'fraction_non_alphanumeric': 0.15067611075338055, 'fraction_numerical': 0.025756600128783, 'mean_word_length': 4.045454545454546, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '327941', 'license': 'MIT', 'n_tokens_mistral': 663, 'n_tokens_neox': 626, 'n_words': 145, 'path': 'cn/.ipynb_checkpoints/sicp-3-04-checkpoint.ipynb', 'repo_name': 'DamonDeng/sicp_exercise', 'size': '1553'}