Lecture 9 Notes

Thus we model an effect as a scheme effect we

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: v1 v2 " !# v1  " !  " " !# "" !  " !#  ! 0  8 1 0 2 2 v1 v2  = exp1 exp2 exp3 exp2 if ( 1 exp3 if ( 1 0 exp1 exp1 exp2 exp1 exp2 1 4 3  2¨  ¨¦ ©§¥ ¢¤ £¡¢ £  ¥ ¨¦ £ ¤¢   ¥ ¨¦  £ ¤¢  5.2.3 Specifying Operations on Explicit References v l 1 dom( 1) " !# ! " !  " " ! # " !   " ! © ¨ §# ¦ " !  " " !# l 0 exp 0 4 2¨  ¨ ¤¥¢£©( ©§¥ ¨ ¨¦  "! £ ¤¢  ¥ ¨¦ 4523¨¤¤¨ ¨¤ ¨¦ ©§¥ £ ¡ ¤¢ ¨¦ ©§¥  4   ¨ 3¨ ) 2¨ ¤1 £ %¢  ©§¥ ¨¦ £ %¢  ¨¦ ©§¥  exp1 exp2 l lv 1 1 1 (l ) 0  exp 0  exp !  0 ¡ exp l v 1 1 " ! © ¨ ¦¥# " !  "  " ! #  "" !  " !#  ! 1 exp1 exp2 0 2 lv 2 8£ ¥ ¥©¥ 6 ¨ £ ¤¢  £ ¤¢   ¨¦ ©§¥ £ %¢  This rule says that a evaluates its operands from left to right. The value of the first operand must be a reference to a location l . The then updates the resulting store by putting the value v of the second argument in location l . What should a return? It could return anything. To emphasize the arbitrary nature of this choice, we have specified that it returns 23. 8£ ¥ ¥©¥ 6 ¨ 8£ 9 ¥ 6 ¨¨ ¥©¥ )  ©3¨ ¤ %1 ¢ & ¢ ¥42¨£¢ ¤ 53¤¡¡¨ §¦ 1 5¥ ¨ & 5.2.4 Implementation: The specification language we have used so far makes it easy to describe the desired behavior of effectful computations, but it does not embody a key fact about the store: a reference ultimately refers to a real location in a memory that exists in the real world. Since we have only one real world, our program can only keep track of one state of the store. In our implementations, we take advantage of this fact by modelling the store using Scheme’s own store. Thus we model an effect as a Scheme effect. We represent the state of the store as a Sc...
View Full Document

This document was uploaded on 03/17/2014 for the course CSG 111 at Northeastern.

Ask a homework question - tutors are online