Running SICP Pattern Matching Rule Based Substitution Code?

Your code is from 1991. Since R5RS came out in 1998, the code must be written for R4RS (or older). One of the differences between R4RS and later Schemes is that the empty list was interpreted as false in the R4RS and as true in R5RS Example: (if '() 1 2) gives 1 in R5RS but 2 in R4RS Procedures such as assq could therefore return '() instead of false.

This is why you need to change the definition of extend-directory to: (define (extend-dictionary pat dat dictionary) (let ((vname (variable-name pat))) (let ((v (assq vname dictionary))) (cond ((not v) (cons (list vname dat) dictionary)) ((eq? (cadr v) dat) dictionary) (else 'failed))))) Also back in those days map was called mapcar. Simply replace mapcar with map The error you saw in DrRacket was: mcdr: expects argument of type ; given '() This means that cdr got an empty list.

Since an empty list has no cdr this gives an error message. Now DrRacket writes mcdr instead of cdr, but ignore that for now Best advice: Go through one function at a time and test it with a few expressions in the REPL. This is easier than figuring everything out at once Finally begin your program with: (define user-initial-environment (scheme-report-environment 5)) Another change from R4RS (or MIT Scheme in 1991?) Addendum: This code http://pages.cs.brandeis.edu/~mairson/Courses/cs21b/sym-diff.scm almost runs.

Prefix it in DrRacket with: lang r5rs (define false #f) (define user-initial-environment (scheme-report-environment 5)) (define mapcar map) And in extend-directory change the (null? V) to (not v). That at least works for simple expressions.

Your code is from 1991. Since R5RS came out in 1998, the code must be written for R4RS (or older). One of the differences between R4RS and later Schemes is that the empty list was interpreted as false in the R4RS and as true in R5RS.

Example: (if '() 1 2) gives 1 in R5RS but 2 in R4RS. Procedures such as assq could therefore return '() instead of false. This is why you need to change the definition of extend-directory to: (define (extend-dictionary pat dat dictionary) (let ((vname (variable-name pat))) (let ((v (assq vname dictionary))) (cond ((not v) (cons (list vname dat) dictionary)) ((eq?(cadr v) dat) dictionary) (else 'failed))))) Also back in those days map was called mapcar.

Simply replace mapcar with map. The error you saw in DrRacket was: mcdr: expects argument of type ; given '() This means that cdr got an empty list. Since an empty list has no cdr this gives an error message.

Now DrRacket writes mcdr instead of cdr, but ignore that for now. Best advice: Go through one function at a time and test it with a few expressions in the REPL. This is easier than figuring everything out at once.

Finally begin your program with: (define user-initial-environment (scheme-report-environment 5)) Another change from R4RS (or MIT Scheme in 1991? ). Addendum: This code http://pages.cs.brandeis.edu/~mairson/Courses/cs21b/sym-diff.scm almost runs.

Prefix it in DrRacket with: #lang r5rs (define false #f) (define user-initial-environment (scheme-report-environment 5)) (define mapcar map) And in extend-directory change the (null? V) to (not v). That at least works for simple expressions.

Thanks for the response! I'm using the neil/sicp, but felt it was beneficial to provide the different errors from both. I made the adjustments as suggested which led me to some "false" errors which I tried changing to #f's, which led me to another mutable-paid error.

-- At the end of the day, I guess I'm just trying to learn the code, but I can't find code that works. Do you know of any working code from this video lesson that can be found? To your advice, I definitely will continue to try going through one function at a time, but this is pretty heady code for my current lisp expertise.

– Benjamin Powers Aug 8 at 3:27 I added a link to a newer version used at Brandeis. – soegaard Aug 8 at 9:22 Yes! I really, really appreciate this.

Thank you very much. – Benjamin Powers Aug 8 at 14:56.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions