Lecture 9 Notes

The distinction between locations and references may

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: to that place. The distinction between locations and references may be seen by analogy: a location is like a file and a reference is like a URL. The URL refers to the file, and the file contains some data. Similarly, a reference denotes a location, and the location contains some data. References are sometimes called L-values. This name reflects the association of such data structures with variables appearing on the left-hand side of assignment statements. Analogously, expressed values, such as the values of the right-hand side expressions of assignment statements, are known as R-values. We consider two designs for a language with a store. We call these designs explicit references and implicit references. 3 5.2 EXPLICIT-REFS: A language with explicit references Add references as a new kind of expressed value. ¡ ¡ Int Bool ExpVal Proc ¡ ExpVal DenVal Ref (ExpVal) Ref (ExpVal) means the set of references to locations that contain expressed values. 3 new operations: ¥©¥ ¢ ¥©§¥£ ¨¦¤¢ — allocates a new location and returns a reference to it. ¥©¥ ¨¨¢ — changes the contents of the location that the reference represents. — dereferences a reference: that is, it returns the contents of the location that the reference represents. 4 5.2.1 Examples Recall: Binding is about the association of names with values; assignment is about the sharing of values between different procedures. When a binding to a location is shared by multiple procedures, a change to the location by one is seen by all. and ¢ £ ¥ ¡¥ Here are two procedures, is bound to . , that both refer to a shared location, which £ They communicate not by passing data explicitly, but by changing the contents of the variable they share.  © ¡¨ ¢ 5£ ¥ ¡75$ ¥ ¥ ©8  (©&6© ¥ ¡4 2£ ¢  ¥ § ¨ !¦0'!%% $ &3 1 ¥ &¥) (©&   £ ¦¥ ¨¥ ¤ £  ¥ ¥©  ©§¥ ¥  ¥ ¨¦£ ¦£ ¨¥ ¤ ¡"#!¡  §  ©§ ¨ ¨¥ X%'  ¢ VQSE" £ ¨¨¨ £  %¦0£  £ RRR6 § PW H § ¥©¥ C (¥)  £ ¥ RRR SV£ ¥ ¥ § PU¡" H  £ §¨ I6 G£ G¨  ¥©¥...
View Full Document

Ask a homework question - tutors are online