(Lispex)sicp.io
5.1 · 이름 붙은 상태 칸

레지스터는 바뀌는 값을 모두 명시한다.

기계 상태를 고정된 레지스터 값 모음으로 나타내고 한 번의 전이가 다음 상태를 계산하게 할 수 있습니다.

생각해 볼 질문

계산을 다시 이어 가려면 어떤 정보가 상태에 있어야 할까요?

  • Represent registers as one explicit state value
  • Separate a single transition from repeated execution
  • Read a final state instead of only a final number

The state list holds a, b, and the number of completed transitions. step performs one Euclidean reduction and returns a new list without hiding any changing value.

run does not contain the arithmetic rule itself. It asks whether b is zero and otherwise repeats step, so the transition rule and the controller remain separate.

리스펙스 · SICP 코드SICP에 필요한 Scheme 호환 문법을 리스펙스 SICP 프로필로 실행합니다.
(begin
  (define (step state)
    (let ((a (car state))
          (b (cadr state))
          (steps (caddr state)))
      (if (= b 0)
          state
          (list b (remainder a b) (+ steps 1)))))
  (define (run state)
    (if (= (cadr state) 0)
        state
        (run (step state))))
  (run (list 206 40 0)))
리스펙스 학습용 런타임리스펙스 SICP 프로필 1.0.0
리스펙스 SICP 런타임 불러오는 중
리스펙스 · SICP 코드UTF-8 316 / 1,048,576바이트
예제
결과
출력
진단
보이는 실행 흐름0 / 0 개의 실행 이벤트
    이 브라우저 결과는 리스펙스 바우치나 권한이 아닙니다.wasm —
    예상 관찰

    The first program returns the final register state (2 0 4). The gcd is 2 and four transitions completed.

    실행 흐름에서 볼 점

    Follow each step application and watch the old b become the next a. The state value records the transition count alongside the arithmetic registers.

    직접 해보기

    힌트를 보기 전에 프로그램을 바꿔 보세요.

    Run the machine with a equal to 30 and b equal to 18. Predict the complete final state, including the transition count.

    힌트 하나 보기

    Write one new list after each remainder operation.