Store-passing interpreter - Exercise 4.12

101 views
Skip to first unread message

Luca

unread,
Sep 1, 2013, 5:56:25 PM9/1/13
to eo...@googlegroups.com
Hi guys, I have a question regarding the store passing interpreter example given for exercise 4.6.

Here's the code from the book:

value-of : Exp × Env × Sto → ExpVal
(define value-of
  (lambda (exp env store)
    (cases expression exp
      (const-exp (num)
                 (an-answer (num-val num) store))
      (var-exp (var)
               (an-answer
                (apply-store store (apply-env env var)) ;;(1)
                store))
      (if-exp (exp1 exp2 exp3)
              (cases answer (value-of exp1 env store)
                (an-answer (val new-store)
                           (if (expval->bool val)
                               (value-of exp2 env new-store)
                               (value-of exp3 env new-store)))))
      (deref-exp (exp1)
                 (cases answer (value-of exp1 env store)
                   (an-answer (v1 new-store)
                              (let ((ref1 (expval->ref v1)))
                                (an-answer (deref ref1) new-store))))) ;;(2)
      ...)))

(1) apply-store? why should we call such a function here? For a var-exp the solution should be (an-answer (apply-env env var) store). 
(2) I though the purpose of the entire exercise was to pass the store around, but from this line it seems that the store is still implemented as a global variable, in fact it is not passed to deref. So what's the use of being so careful as to what store is being returned, we could just return store.. it's global!

Does it make sense?

Does anyone want to share their thoughts about this?

Thank you all!

Luca

Yukang Chen

unread,
Sep 13, 2013, 8:42:41 PM9/13/13
to eo...@googlegroups.com
Yes, I am also confusing about this.... 
I try to search apply-store in all the books, but haven't got the definition.

Luca

unread,
Sep 21, 2013, 5:33:36 AM9/21/13
to eo...@googlegroups.com
Hi Chen, yes I think apply-store has nothing to do with a solution in the case of a var-exp for the store-passing interpreter.

Mitchell Wand

unread,
Sep 24, 2013, 6:09:57 PM9/24/13
to eopl3
Sorry to be so slow in responding.

From Section 4.1:

"We model memory as a finite map from locations to a set of values called the storable values.  For historical reasons, we call this the store."

We represent such a map as some data structure, just as we represented environments as a data structure.   We use apply-store to look things up in this map, just like we used apply-env.

This way the interpreter does not make a commitment to the representation of the store, just like using apply-env allows the interpreter to avoid committing itself to any particular representation of the environment. 

Hope that helps.

--Prof. Wand


--
You received this message because you are subscribed to the Google Groups "EOPL3" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eopl3+un...@googlegroups.com.
To post to this group, send email to eo...@googlegroups.com.
Visit this group at http://groups.google.com/group/eopl3.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages