Lecture 9 Notes

Similarly one procedure might call another procedure

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: H § ¥©¥ C £  ¡¦B¨ ¤ ¥ (¥) ¥ © T£ ¦% ¥3 @©9  § ¥©¥  £ G § ¢ ¥ ¦  ¥ "  §  ¡#!7%¡ ¨ ¢  £ ¥ RRR  S75 ¢ § P Q¡" H  £ ¨¥  §I6 H£ ¨¨¨ § ©¥ § ¥©¥ FG¥¦£ ¢  ¦& ¤ ¥ % ¢ ¥¦ ¤ ! B © %¨© £ ' © ¢ $ 3 & £ ¥  & ©¥ £   8 £ ¥¦E     ¥¦¨ ¤  ¥ £  ¡¥ )D$ ) & & C ( C £  ¡¦B¨ ¤ ¥ (¥) ¥ " A£ ¦% ¥3 ¥©¥ @ ©¥9  § ¢ 0  ¥ §  £ ¨ This style of communication is convenient when two procedures might share many quantities; one needs to assign only to the few quantities that change from one call to the next. Similarly, one procedure might call another procedure not directly but through a long chain of procedure calls. They could communicate data directly through a shared variable, without the intermediate procedures needing to know about it. Thus communication through a shared variable can be a kind of information hiding. 5 Another use of assignment is to create hidden state through the use of private variables. ¥©§ ¨¥ £ ©  X¥ £ ©  §  ©¥ § © £ ¥ £  ¢  ¨¥  I6 H ¥  P" Q7¡X6 H  £ ¨¥  ©¥ ¥ ©¨¨ ¥ ¥ £¥  £ © © ¥ £ ¨¥   ¨¥ ¢G § ¢¨ § C ¡) ( X!¡ §  ¢ 4  8  ¥ ¢ ¤  ©§ G " ¡" ( ( § H ¡" " ( 5¤ ¥ £ ( IT  §§6 ( Here the procedure keeps a private variable that stores the number of times has been called. In our language, the operands in a difference expression are evaluated left-to-right. Hence the first call to returns 1, the second call to returns 2, and the entire program has the value -1. ( ( [g = (proc−val (procedure d let d = ... ( Here is a picture of the environment in which is bound. )) ] [ counter = reference to location location for count ( We can think of this as the different invocations of sharing informatio...
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