나는 SICP의 비디오 강연을보고있다. 현재 나는 4A Pattern Matching과 Rule Based Substitution을 사용 중이다.sicp 패턴 일치 - 화합물?
지금까지 Matcher와 Instantiator가 쉽다는 것을 알았습니다. 그러나 나는 머리를 단순화 자로 가져갈 수 없다.
(define (simplifier the-rules)
(define (simplify-exp exp)
(try-rules (if (compound? exp)
(map simplify-exp exp)
exp)))
(define (try-rules exp)
(define (scan rules)
(if (null? rules)
exp
(let ((dict (match (pattern (car rules))
exp
(empty-dictionary))))
(if (eq? dict 'failed)
(scan (cdr rules))
(simplify-exp (instantiate (skeleton (car rules)) dict))))))
(scan the-rules))
simplify-exp)
나는
pair?
의 관점에서
compound?
정의이 주제에 여기에 또 다른 질문을 보았다. 그런데
try-rules
에 무슨
simplify-exp
먹이?
라켓이나 스킴을 사용하고 있습니까? 질문은 [tag : scheme]으로 태그가 붙지 만 코드는'#lang racket'으로 시작합니다. 그것들은 * 유사한 * 언어이지만, 그들은 동일하지 않습니다. Scheme과 많은 Lisps에서 빈리스트 *는 원자이다. 그래서 ((nulls) (())'(당신이 대답에 추가 한 것은)'((atom? . –