views:

90

answers:

3
+1  Q: 

PLT Scheme Memory

So I need some help with implementing a Make-memory program using Scheme. I need two messages 'write and 'read. So it would be like (mymem 'write 34 -116) and (mymem 'read 99) right? and (define mymem (make-memory 100)).....How would I implement this in scheme? using an Alist???I need some help coding it. I have this code which makes make-memory a procedure and when you run mymem you get ((99.0)) and what i need to do is recur this so i get an alist with dotted pairs to ((0.0)). So any suggestions on how to code this?? Does anyone have any ideas what I could do to recur and make messages Write and read??

(define make-memory
  (lambda (n)
    (letrec ((mem '())
             (dump (display mem)))
      (lambda ()
        (if (= n 0)
            (cons (cons n 0) mem) mem)
            (cons (cons (- n 1) 0) mem))
      (lambda (msg loc val)
        (cond
          ((equal? msg 'read) (display 
                               (cons n val))(set! n (- n 1)))
          ((equal? msg 'write) (set! mem 
                                     (cons val loc)) (set! n (- n 1)) (display mem)))))))


(define mymem (make-memory 100))

Yes this is an assignment but I wrote this code. I just need some help or direction. And yes I do know about variable-length argument lists.

A: 

Seems that what you need is make-vector.

Eli Barzilay
+1  A: 

Is the class you're in using the Design Recipe a la How To Design Programs?

If so, it looks like you're on step one.

If not: can you specify the behavior you're looking for using a set of examples, and then turn them into test cases?

John Clements