sicp

How do I get a scheme interpreter working inside Emacs?

被刻印的时光 ゝ 提交于 2019-12-18 10:26:10
问题 I'm going through SICP and I'd like to have an interpreter analogous to the interactive Python interpreter to play around in while I'm watching the lectures and reading the book. Furthermore, I'd like this interpreter to run inside Emacs so I can jump back and forth between files of scheme code and the interactive interpreter and so forth. However, I'm fairly new to Emacs and have not as of yet been able to get this to work or find one clear set of instructions to use in getting it to work.

Understanding the environment model of evaluation

笑着哭i 提交于 2019-12-18 09:16:41
问题 Exercise 3.20 in SICP: Draw environment diagrams to illustrate the evaluation of the sequence of expressions (define x (cons 1 2)) (define z (cons x x)) (set-car! (cdr z) 17) (car x) 17 using the procedural implementation of pairs given above. My eyes are destroyed so I cannot draw. I will instead try to imagine as best as I can how the environment model evolves. First, here is the procedural pairs implementation. (define (cons x y) (define (set-x! v) (set! x v)) (define (set-y! v) (set! y v)

SICP recursive process vs iterative process: using a recursive procedure to generate an iterative process

你。 提交于 2019-12-17 12:38:09
问题 in SICP Section 1.2.1 The author giving such a code example below to show how to using iterative process to solve the factorial problem: (define (factorial n) (fact-iter 1 1 n)) (define (fact-iter product counter max-count) (if (> counter max-count) product (fact-iter (* counter product) (+ counter 1) max-count))) and say "It may seem disturbing that we refer to a recursive procedure such as fact-iter as generating an iterative process.However, the process really is iterative: Its state is

SICP Section 3.1.1 - Local state in procedures seems inconsistent

╄→гoц情女王★ 提交于 2019-12-14 02:18:54
问题 I am working my way through SICP. I am on Section 3.1.1 and looking at local state. I am evaluating these exercises in GNU Guile v2.0.11. I did find a similar question about this section, but it seems not to address the point I am struggling with, or I am overly obtuse. The two examples I am looking at are these: (define new-withdraw (let ((balance 100)) (lambda (amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds")))) (define (make-withdraw

Pass by value confusion in Scheme

末鹿安然 提交于 2019-12-13 02:27:45
问题 Consider the following procedure taken from SICP: (define (make-withdraw balance) (lambda (amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds"))) Suppose I say: (define x (make-withdraw 100)) make-withdraw returns a procedure ( (lambda (amount) ... ) ) inside a new environment called e2 (enclosing the binding for the variable balance ), and binds that procedure to x in the global frame. Now, say I call: (f x) where (define (f y) (y 25)) 1 . I

Class instance implementation, initializing instance - from SICP python

社会主义新天地 提交于 2019-12-12 22:02:21
问题 I'm trying to the understand the initialization function in a python class system implementation, taken from this book (SICP python - reference to book section). The init_instance (initialization) function """Return a new object with type cls, initialized with args.""" is where I'm having trouble. Below I've tried to narrow down my question, by explaining what I've understood. def make_instance (cls): #good with this """return a new object instance, which is a dispatch dictionary""" def get

Value returned by a define expression in Scheme

风流意气都作罢 提交于 2019-12-12 13:43:12
问题 I ran this in MIT/GNU Scheme: (define x (+ 2 3)) The interpreter then prints: ;Value: x But according to my textbook, the value returned by a define expression should be undefined. Why did the interpreter print ";Value: x" then? 回答1: If the standard report does not specify a return or mentions that it is undefined an implementation is literally free to choose the value returned and it would be according to the standard. That also means you cannot depend on one implementations behaviour would

“not a proper list” error in DrRacket writing Scheme

孤者浪人 提交于 2019-12-11 13:59:04
问题 I just follow the instructions at 3.3.3 of SICP to create the table. The code I wrote just works well. here is code_0.scm: #lang scheme (require rnrs/base-6) (require rnrs/mutable-pairs-6) (define (make-table) (list '*table*)) (define (assoc key records) (cond ((null? records) false) ((equal? key (caar records)) (car records)) (else (assoc key (cdr records))))) (define (insert! key value table) (let ((record (assoc key (cdr table)))) (if record (set-cdr! record value) (set-cdr! table (cons

TypeError, the object is not applicable

こ雲淡風輕ζ 提交于 2019-12-11 13:06:43
问题 I wrote a relatively simple bank account function, however when I try to run it I get an TypeError and I'm not sure to why? It's straight out of SICP so the solution is readily available, I just want to understand why my answer produces that error. Any thoughts? Here is my code: (define (make-password-account balance password) (define (withdraw amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient Funds")) (define (deposit amount) (set! balance (+

Meaning of 'quote in Lisp

吃可爱长大的小学妹 提交于 2019-12-11 06:26:20
问题 This question arose when reading SICP . Why (list 'quote '(a b c)) evaluated by the interpreter ( R5RS in Dr.Racket ) as '(a b c) . For me it should be (quote (a b c)) . For instance (list 'quot '(a b c)) is evaluated as (quot (a b c)) . What is so special in the 'quote ? 回答1: It also took me a while to understand this problem. But it's just your good-hearted lisp interpreter showing (quote (a b c)) in it's equivalent form '(a b c). Since there is no such equivalence/syntactic sugar for