Friday, June 5, 2015

TFI-CB:Kewarganegaraan Project : Kegiatan Bersih-Bersih, Part 4 (Last)

Nama : Ivan Reinaldo

NIM   : 1801377686
Tanggal Kegiatan : Kamis, 4 Juni 2015

Berikut laporan mengenai kegiatan bersih-bersih yang dilakukan pada hari keempat.
(Untuk project TFI kali ini, kelompok kami memutuskan untuk membantu dalam bidang kebersihan)

      Akhirnya sampailah kami kepada hari keempat untuk menyelesaikan project ini. Dengan masih tetap semangat untuk melakukan kegiatan kebersihan, kami pun mengunjungi lokasi setelah kegiatan perkuliahan selesai, melakukan pengecekan di lokasi, dan kembali beraksi.
      Seperti hari-hari sebelumnya, kami melakukan pembagian tugas. Untuk kegiatan terakhir ini, saya mendapat bagian bersama 1 teman saya untuk menyapu bagian dalam lokasi. Tentunya, setelah beberapa hari kami melakukan kegiatan kebersihan, kami semakin terbiasa dan hasilnya lebih memuaskan dari sebelumnya.
       Kami pun tidak lupa untuk kembali melakukan sosialisasi kebersihan di lokasi, guna meningkatkan kesadaran dan semangat mereka akan kebersihan. Kami mengucapkan terima kasih kepada pihak lokasi yang sudah memberikan kesempatan kepada kami untuk beberapa hari boleh berkontribusi dalam kegiatan kebersihan di lokasi. Pihak lokasi pun terbuka pada pekerjaan maupun sosialisasi yang kami berikan.
       Dalam beberapa hari ini, saya sadar bahwa ketika kita, sebagai sesama warga negara Indonesia, bekerja sama dalam mencapai suatu tujuan, tidak memandang adanya perbedaan. Pihak lokasi tidak memandang kami hanya sebagai mahasiswa yang sedang melakukan tugasnya, tapi mereka mendukung kontribusi kami di lokasi mereka. Tentunya kami sebagai mahasiswa tidak boleh memandang mereka hanya sebagai staff, karena kita semua adalah warga negara Indonesia.
      Demikianlah project kebersihan ini telah diselesaikan dalam beberapa waktu ini. Kiranya apa yang telah saya sampaikan melalui post ini maupun beberapa post sebelumnya bisa menjadi inspirasi dan meningkatkan kesadaran setiap pembaca, sebagai sesama warga negara Indonesia, pentingnya bekerja sama tanpa memandang perbedaan, untuk mencapai tujuan yang sama dan yang selalu dicita-citakan. Sekian.

Dokumentasi:




DARE TO DREAM!

Thursday, June 4, 2015

TFI-CB:Kewarganegaraan Project : Kegiatan Bersih-Bersih, Part 3

Nama : Ivan Reinaldo
NIM   : 1801377686
Tanggal Kegiatan : Rabu, 3 Juni 2015

Berikut laporan mengenai kegiatan bersih-bersih yang dilakukan pada hari ketiga.
(Untuk project TFI kali ini, kelompok kami memutuskan untuk membantu dalam bidang kebersihan)

      Dengan tetap semangat bersih-bersih seperti hari-hari sebelumnya, kami langsung mengunjungi lokasi yang telah ditentukan. Tidak bosannya kami mengecek kebersihan lokasi terlebih dahulu. Kali ini pun, kami ingin meningkatkan kebersihan lokasi tersebut.
      Kami berdiskusi untuk membagi tugas, dan kali ini, saya mendapat bagian bersama 2 teman saya untuk mengelap dan merapikan meja bangku yang terdapat di lokasi. Karena lokasi yang kami kunjungi merupakan suatu restoran, kerapian meja dan bangku menjadi nomor 1, sehingga kami melakukan semaksimal mungkin untuk mencapai kerapian yang maksimal pula. Kami pun akhirnya menyelesaikan pekerjaan kami dengan hasil yang cukup memuaskan.
     Sebelum meninggalkan lokasi, tentunya kami tidak ingin kontribusi yang telah kami lakukan menjadi sia-sia. Kami menyempatkan diri terlebih dahulu untuk sosialisasi kebersihan kepada staff lokasi tersebut, dengan tujuan agar mereka ikut bersemangat dalam meningkatkan kebersihan, bukan hanya di lokasi tersebut, tetapi dimana pun mereka berada.
     Mereka menerima dan mendengarkan sosialisasi itu dengan baik. Sebagai sesama warga negara Indonesia, memang seharusnya kita bekerja sama untuk mencapai tujuan dan cita-cita yang sama. Kami berharap, kesadaran mereka akan kebersihan bisa terus mereka jaga dan tingkatkan!
      Sekian hal yang ingin saya sampaikan untuk kegiatan ketiga ini. Laporan kegiatan selanjutnya akan diposting dalam kurun waktu dekat.

Dokumentasi:




TERIMA KASIH!

TFI-CB:Kewarganegaraan Project : Kegiatan Bersih-Bersih, Part 2

Nama : Ivan Reinaldo
NIM   : 1801377686
Tanggal Kegiatan : Senin, 1 Juni 2015

Berikut laporan mengenai kegiatan bersih-bersih yang dilakukan pada hari kedua.
(Untuk project TFI kali ini, kelompok kami memutuskan untuk membantu dalam bidang kebersihan)

      Kami melanjutkan kembali project kami ini. Seperti yang dilakukan hari sebelumnya, kami langsung menuju ke lokasi yang telah ditentukan. Pengecekan kebersihan tentunya menjadi suatu kewajiban yang harus dilakukan terlebih dahulu. Lagi-lagi, kami semangat untuk meningkatkan kebersihan di lokasi tersebut.
      Pembagian tugas pun dilakukan untuk meningkatkan efisiensi kerja kami. Untuk hari kedua, saya mendapat bagian bersama 1 teman saya untuk mengelap kaca. Menurut saya, kebersihan kaca merupakan salah satu hal yang penting untuk dijaga, khususnya bagi lokasi yang merupakan toko, untuk menarik perhatian pelanggan. Dan akhirnya pekerjaan kami selesai!
   Kali ini, saya mendapat pengalaman yang unik dan menarik. Ketika teman saya sedang membersihkan bagian luar lokasi, ia bertemu dengan pemiliknya, dan akhirnya mereka mengobrol. Ternyata, pemilik tersebut adalah alumni BINUS! Bahkan, dia bisa menebak bahwa kami sedang berkontribusi dalam project TFI untuk mata kuliah CB.
     Yang ingin saya tekankan kali ini, bahwa sang pemilik pun mendukung kami untuk meningkatkan kebersihan. Kalau saja ia tidak membiarkan kami untuk intervensi kebersihan pada saat itu, tentunya kami tidak bisa melakukan project ini. Hal ini menggambarkan bangsa Indonesia yang mau mencapai suatu cita-cita bersama-sama.
      Sekian hal yang ingin saya sampaikan untuk kegiatan kedua ini. Laporan kegiatan selanjutnya akan diposting dalam kurun waktu dekat.

Dokumentasi:







TERIMA KASIH!

TFI-CB:Kewarganegaraan Project : Kegiatan Bersih-Bersih, Part 1

Nama : Ivan Reinaldo
NIM   : 1801377686
Tanggal Kegiatan : Jumat, 29 Mei 2015

Berikut laporan mengenai kegiatan bersih-bersih yang dilakukan pada hari pertama.
(Untuk project TFI kali ini, kelompok kami memutuskan untuk membantu dalam bidang kebersihan)

      Project kami akhirnya dimulai! Kami mengunjungi tempat yang telah kami tentukan. Hal yang tentunya pertama kami lakukan adalah mengecek kebersihan lokasi. Ternyata, ditemukan bahwa kebersihan kurang maksimal.
      Untuk merealisasikan kebersihan yang kami inginkan, kami tentunya bukan datang untuk memberikan ceramah kebersihan, tapi kami ingin terlibat didalamnya. Tim kami terdiri dari 7 orang, sehingga kami langsung membagi tugas untuk mempercepat pekerjaan.
      Kali ini, saya mendapat bagian bersama 2 teman saya untuk menyapu. Bagi saya sendiri, menyapu bukanlah hal yang sering saya lakukan karena adanya pekerja di rumah. Namun, hal itu tentunya tidak membatasi saya untuk melakukan kegiatan kebersihan. Pada akhirnya, pekerjaan kami selesai dan hasilnya cukup memuaskan kami maupun staff lokasi.
      Hal yang sangat menarik bagi saya dalam kegiatan kali ini adalah hubungan timbal balik yang terbentuk antara tim kami dengan staff lokasi. Di tengah pekerjaan kami, staff di sana menyiapkan minuman bagi kami secara cuma-cuma.
      Saya belajar dari hal ini, bahwa kita sebagai sesama WNI, bersama-sama ikut mendukung dalam mencapai tujuan yang sama, yaitu meningkatkan kebersihan. Tentunya hal tersebut tercermin dalam berbagai bentuk kontribusi. Meskipun pada saat itu kami yang mengambil alih pekerjaan kebersihan, mereka tetap mendukung kami dengan menyiapkan minuman sebagai salah satu penyemangat.
      Sekian hal yang ingin saya sampaikan untuk kegiatan pertama ini. Laporan kegiatan selanjutnya akan diposting dalam kurun waktu dekat.


Dokumentasi:



TERIMA KASIH!
      


Tuesday, February 3, 2015

Chapter 13 : Problem Set

Q6 : Suppose two tasks, A and B, must use the shared variable Buf_Size. Task A adds 2 to Buf_Size, and task B subtracts 1 from it. Assume that such arithmetic operations are done by the three-step process of fetching the current value, performing the arithmetic, and putting the new value back. In the absence of competition synchronization, what sequences of events are possible and what values result from these operations? Assume that the initial value of Buf_Size is 6.
A : The idea here is that the add and subtract operations are not atomic, and could be interrupted in mid-operation, when the other task could then run. If A runs to completion, then B runs to completion, Buf_Size has the value 7 (6 + 2 – 1). Similarly if B runs to completion then A runs to completion. If A or B get interrupted in the middle of adding or subtracting, then whichever task finishes last will determine the value in Buf_Size. If A runs but is interrupted after it fetches Buf_Size but before it stores the modified value (allowing B to fetch Buf_Size), or if B runs first and is interrupted after the fetch but before the store, allowing A to fetch Buf_Size, then if A finishes last Buf_Size will have value 8, and if B finishes last Buf_Size will have value 5.

Q7 : Compare the Java competition synchronization mechanism with that of Ada.
A : Java methods (but not constructors) can be specified to be synchronized. A synchronized method called through a specific object must complete its execu- tion before any other synchronized method can run on that object. Competition synchronization on an object is implemented by specifying that the methods that access shared data are synchronized.
The competition synchronization mechanism of the Ada Language is intended to provide a facility for tasks to synchronize their actions. Accept and select statements are the two main features of the language that deal with the issue of synchronization This paper points out one major problem that arises in connection with these features and proposes a possible solution to it.

Q8 : Compare the Java cooperation synchronization mechanism with that of Ada.
A : Cooperation synchronization in Java is implemented with the wait, notify, and notifyAll methods, all of which are defined in Object, the root class of all Java classes. All classes except Object inherit these methods. Every object has a wait list of all of the threads that have called wait on the object.
In Ada, cooperation synchronization is required between two tasks that when the second task must wait for the first task to finish executing before it may proceed.

Q9 : What happens if a monitor procedure calls another procedure in the same monitor?
A : Because the access mechanisms are part of the monitor, implementation of a monitor can be made to guarantee synchro- nized access by allowing only one access at a time. Calls to monitor procedures are implicitly blocked and stored in a queue if the monitor is busy at the time of the call.

Q10 : Explain the relative safety of cooperation synchronization using semaphores and using Ada’s when clauses in tasks.
A : As soon as we start using concurrent threads, we need to think about various issues that fall under the broad description of thread safety. Generally, we need to take steps to make sure that different threads don't interact in negative ways:
-if one thread is operating on some data or structure, we don't want another thread to simultaneously operate on that same data/structure and corrupt the results;
-when Thread A writes to a variable that Thread B accesses, we need to make sure that Thread B will actually see the value written by Thread A;
-we don't want one thread to hog, take or lock for too long a resource that other threads need in order to make progress.

Chapter 13 : Review Question

Q6 :Describe the logical architecture of a vector processor.
A : Vector processor have groups of registers that store the operands of a vector operation in which the same instruction is executed on the whole group of operands simultaneously. Originally, the kinds of programs that could most benefit from this architecture were in scientific computation, an area of computing that is often the target of multiprocessor machines.

Q7 : What is the difference between physical and logical concurrency?
A : Physical concurrency – Multiple independent processors (multiple threads of control)
Logical concurrency – The appearance of physical concurrency is presented by time-sharing one processor (software can be designed as if there were multiple threads of control)

Q8 : What is a thread of control in a program?
A : A thread of control in a program is the sequence of program points reached as control flows through the program.

Q9 : Why are coroutines called quasi-concurrent?
A : Because they have a single thread of control.

Q10 : What is a multithreaded program?
A : A program designed to have more than one thread of control.

Chapter 12 : Problem Set

Q6 : Compare the multiple inheritance of C++ with that provided by interfaces in Java.
A : C++ inheritance is implementation inheritance. That is, a class inheriting from two of more superclasses actually inherits the code from those classes. Java’s interface mechanism is an interface inheritance. That is, a class implementing two or more interfaces simply inherits (and must provide its own implementations for) the methods of the interface.

Q7 : What is one programming situation where multiple inheritance has a significant advantage over interfaces?
A : When two or more parent classes are derived from one grandparent class and has one child (diamond problem).

Q8 : Explain the two problems with abstract data types that are ameliorated by inheritance.
A : The problems solved are reusability of code and "extensibility". Reusability because one won't have to copy/paste his code from one data type to another, allowing for a greater readability. Extensibility because a method can accept a certain class as an argument, and get a child class of this one. This will allow the user to have a wider set of functionality, but the method will still be able to know that the entities it relies on are present.

Q9 : Describe the categories of changes that a subclass can make to its parent class.
A : Subclasses can add things (variables, methods). Subclass in C++ can effectively remove a method using "private" inheritance. Inherited methods can be overridden.

Q10 : Explain one disadvantage of inheritance.
A : Language & implementation complexity. The shared inheritance problem of multiple inheritance. Subclass is dependent upon its base class (which might change over time).

Chapter 12 : Review Question

Q6 : Describe a situation where dynamic binding is a great advantage over its absence.
A : There is a base class, A, that defines a method draw that draws some figure associated with the base class. A second class, B, is defined as a subclass of A. Objects of this new class also need a draw method that is like that provided by A but a bit different. With overriding, we can directly modify B’s draw function. But without it, we either make a specific function in A for B and inherit it.

Q7 : What is a virtual method?
A : A virtual method is a declared class method that allows overriding by a method with the same derived class signature. Virtual methods are tools used to implement the polymorphism feature of an object-oriented language, such as C#. When a virtual object instance method is invoked, the method to be called is determined based on the object's runtime type, which is usually that of the most derived class.

Q8 : What is an abstract method? What is an abstract class?
A : An abstract method is a method which all descendant classes should have. An abstract class is a class which has abstract method.

Q9 : Describe briefly the eight design issues used in this chapter for object-oriented languages.
A :
-What non-objects are in the language?
-Are Subclasses Subtypes? If so, derived objects can be legally used wherever a parent object could be used.
-Type Checking and Polymorphism
-Single and Multiple Inheritance. Inherit from 1 (or more than 1) parent.
-Object Allocation and Deallocation.  Are objects allocated from heap or stack.
-Dynamic and Static Binding. When are messages bound to methods, before or during run-time?
-Nested Classes. Can a class be nested inside another class?
-Initialization of Objects. Are objs init'd when created? Implicit or explicit?

Q10 : What is a nesting class?
A : A nesting class is a class defined inside another class.

Chapter 11 : Problem Set

Q6 : Discuss the advantages of C# properties, relative to writing accessor methods in C++ or Java.
A : One of the advantage of C# properties relative writing accessor methods in C++ or Java is it can control access to the fields.

Q7 : Explain the dangers of C’s approach to encapsulation.
A : The main problem is that the biggest part of encapsulation is done via hidding, rather than protection. This hidding is achieved through definition hidding: a header file is preprocessed (which is a synonym for copy-pasted) into the implementation file. Anyone with this header file will be able to access any method or public variable of a the client related to the header, left appart any "static" method / variable. Static is actually the only rue level of protection here, as it's the only one that another unit (file) would not be able to access even if it's aware of it's existence. This whole "protection-is-name-hiding" approach leads to a load of problems: you can access a symbol using the wrong datatype and your compiler will happily do so. To protect critical parts, you should rely on text being hidden from the compiler while it's processing certain units (via #ifdef / #define).

Q8 : Why didn’t C++ eliminate the problems discussed in Problem 7?
A : It didn't eliminate the problem because it evolved from C. Hence, it kept a lot of backward compatibility, and the same way of doing basic things. While some problems where solved (like the protected access, which is in-between normal and static in C), some stay, as the symbol access using wrong datatype (inherent to the linker, which doesn't do type-checking).

Q9 : What are the advantages and disadvantages of the Objective-C approach to syntactically distinguishing class methods from instance methods?
A : Instance methods use an instance of a class, whereas a class method can be used with just the class name. A class is like the blueprint of a house: You only have one blueprint and (usually) you can't do that much with the blueprint alone. An instance (or an object) is the actual house that you build based on the blueprint: You can build lots of houses from the same blueprint. You can then paint the walls a different color in each of the houses, just as you can independently change the properties of each instance of a class without affecting the other instances.

Q10 : In what ways are the method calls in C++ more or less readable than those of Objective-C?
A : In Objective C, all method calls are essentially virtual. This makes it a bit easier on the programmer, but it comes at a possible performance decrease. So sometimes methods call in C++ can be more or less readable than those of Objective-C.

Chapter 11 : Review Question

Q6 : Explain how information hiding is provided in an Ada package.
A : There are two approaches to hiding the representation from clients in the package specification. The first one is to include two sections in the package specification, the second one is in which entities are visible to clients and one that hides its contents.

Q7 : To what is the private part of an Ada package specification visible?
A : The private part of an Ada package specification is visible to the compiler but not to the client programs.

Q8 : What is the difference between private and limited private types in Ada?
A : Private types have built-in operations for assignment and comparison. Limited private types don’t have built-in operations.

Q9 : What is in an Ada package specification? What about a body package?
A : Package specification, is an Ada package which provides the interface of the encapsulation (and perhaps more). Body package, is an Ada package which provides the implementation of most, if not all, of the entities named in the associated package specification.

Q10 : What is the use of the Ada with clause?
A : The use of Ada with clause is to make the names defined in external packages visible.

Chapter 10 : Problem Set

Q6 : Although local variables in Java methods are dynamically allocated at the beginning of each activation, under what circumstances could the value of a local variable in a particular activation retain the value of the previous activation?
A : Each activation allocates variables in exactly the same order. Variables are not initialized to any value unless the program contains an initialization statement for the variable – they simply have whatever value is stored in the location they are allocated. If a procedure finishes executing, returns, and is immediately reinvoked, a variable would be assigned the same stack location it had on the previous invocation, and would have the last value from that previous invocation.

Q7 : It is stated in this chapter that when nonlocal variables are accessed in a dynamic-scoped language using the dynamic chain, variable names must be stored in the activation records with the values. If this were actually done, every nonlocal access would require a sequence of costly string comparisons on names. Design an alternative to these string comparisons that would be faster.
A : Using approach that uses an auxiliary data structure called a display. Or, to write variable names as integers. These integers act like an array. So when the activation happens, the comparisons will be faster.

Q8 : Pascal allows gotos with nonlocal targets. How could such statements be handled if static chains were used for nonlocal variable access? Hint: Consider the way the correct activation record instance of the static parent of a newly enacted procedure is found (see Section 10.4.2).
A : Based on the hint statement, the target of every goto in a program could be represented as an address and a nesting depth, where the nesting depth is the difference between the nesting level of the procedure that contains the goto and that of the procedure containing the target. Then, when a goto is executed, the static chain is followed by the number of links indicated in the nesting depth of the goto target. The stack top pointer is reset to the top of the activation record at the end of the chain.

Q9 : The static-chain method could be expanded slightly by using two static links in each activation record instance where the second points to the static grandparent activation record instance. How would this approach affect the time required for subprogram linkage and nonlocal references?
A : Including two static links would reduce the access time to nonlocals that are defined in scopes two steps away to be equal to that for nonlocals that are one step away. Overall, because most nonlocal references are relatively close, this could significantly increase the execution efficiency of many programs.

Q10 : Design a skeletal program and a calling sequence that results in an activation record instance in which the static and dynamic links point to different activation-recorded instances in the run-time stack.
A :
\\
\emph{Answer}:\\
procedure Main\_2 is\\
\verb+    + X : Integer;\\
\verb+    +procedure Bigsub is\\
\verb+    +\verb+    +    A, B, C : Integer;\\
\verb+    +\verb+    +    procedure Sub1 is\\
\verb+    +\verb+    +\verb+    +    A, D : Integer;\\
\verb+    +\verb+    +\verb+    +    begin -- of Sub1\\
\verb+    +\verb+    +\verb+    +    A := B + C; $\longleftarrow$ 1\\
\verb+    +\verb+    +\verb+    +      ...\\
\verb+    +    end; -- of Sub1\\
\verb+    +    procedure Sub2(X : Integer) is\\
\verb+    +\verb+    +      B, E : Integer;\\
\verb+    +\verb+    +      procedure Sub3 is\\
\verb+    +\verb+    +\verb+    +        C, E : Integer;\\
\verb+    +\verb+    +\verb+    +        begin -- of Sub3\\
\verb+    +\verb+    +\verb+    +        ...\\
\verb+    +\verb+    +\verb+    +        Sub1;\\
\verb+    +\verb+    +\verb+    +        ...\\
\verb+    +\verb+    +\verb+    +        E := B + A; $\longleftarrow$ 2\\
\verb+    +\verb+    +      end; -- of Sub3\\
\verb+    +\verb+    +      begin -- of Sub2\\
\verb+    +\verb+    +      ...\\
\verb+    +\verb+    +      Sub3;\\
\verb+    +\verb+    +      ...\\
\verb+    +\verb+    +      A := D + E; $\longleftarrow$ 3\\
\verb+    +    end; -- of Sub2\\
\verb+    +    begin -- of Bigsub\\
\verb+    +\verb+    +    ...\\
\verb+    +\verb+    +    Sub2(7);\\
\verb+    +\verb+    +    ...\\
\verb+    +  end; -- of Bigsub\\
  begin -- of Main\_2\\
\verb+    +  ...\\
\verb+    +  Bigsub;\\
\verb+    +  ...\\
end; -- of Main\_2\\
\\
The sequence of procedure calls is:\\
Main\_2 calls Bigsub\\
Bigsub calls Sub2\\
Sub2 calls Sub3\\
Sub3 calls Sub1\\
\\
The activation records with static and dynamic links is as follows:\\
\begin{figure}
\centering
\includegraphics[scale=0.5]{ari}
\end{figure}

At position 1 in procedure Sub1, the reference is to the local variable,
A, not to the nonlocal variable A from Bigsub. This reference to A has the
chain\_offset/local\_offset pair (0, 3). The reference to B is to the nonlocal B
from Bigsub. It can be represented by the pair (1, 4). The local\_offset is 4,
because a 3 offset would be the first local variable (Bigsub has no parameters). Notice that if the dynamic link were used to do a simple search for
an activation record instance with a declaration for the variable B, it would
find the variable B declared in Sub2, which would be incorrect. If the (1, 4)
pair were used with the dynamic chain, the variable E from Sub3 would be
used. The static link, however, points to the activation record for Bigsub,
which has the correct version of B . The variable B in Sub2 is not in the
referencing environment at this point and is (correctly) not accessible. The
reference to C at point 1 is to the C defined in Bigsub, which is represented
by the pair (1, 5).\\
\\
\noindent

Chapter 10 : Review Question

Q6 : What is the difference between an activation record and an activation record instance?
A : An activation record is the format, or layout, of the moncode part of a subprogram. An activation record instance is a concrete example of an activation record, a collection of data in the form of an activation record.

Q7 : Why are the return address, dynamic link, and parameters placed in the bottom of the activation record?
A : It's because the entry must appear first.

Q8 : What kind of machines often use registers to pass parameters?
A : RISC Machines often use registers to pass parameters.

Q9 : What are the two steps in locating a nonlocal variable in a static-scoped language with stack-dynamic local variables and nested subprograms?
A : First step, find correct activation record (the harder part) and then the second step is determine the offset within that activation record (easy part).

Q10 : Define static chain, static_depth, nesting_depth, and chain_offset.
A : Static chain is chain of static links connecting an activation record to all of it's static ancestors (it's enclosing subprograms).
Static depth is depth of the nesting for each enclosing static scope.
Nesting depth is the difference between the static depth of the reference and that of the scope where it was declared.
Chain offset is same as nesting depth.

Chapter 9 : Problem Set

Q6 : Present one argument against providing both static and dynamic local variables in subprograms.
A : In subprograms local variables can be static or dynamic;
If local variable treated statically:
This allows for compile-time allocation/ deallocation and ensures proper type checking but does not allow for recursion.
And if local variables treated dynamically:
This allows for recursion at the cost of run-time allocation/ deallocation and initialization because these are stored on a stack, referencing is indirect based on stack position and possibly time-consuming.


Q7 : Consider the following program written in C syntax:
void fun (int first, int second) { 
first += first;
second += second;
}
void main() { 
int list[2] = {1, 3}; 
fun(list[0], list[1]);
}
For each of the following parameter-passing methods, what are the values of the list array after execution?
a. Passed by value                       : 1,3
b. Passed by reference                 : 2,6
c. Passed by value-result             : 2,6

Q8 : Argue against the C design of providing only function subprograms.
A : If a language provides only functions, then either programmers must live with the restriction of returning only a single result from any subprogram, or functions must allow side effects, which is generally considered bad. Since having subprograms that can only modify a single value is too restrictive, C’s choice is not good.

Q9 : From a textbook on Fortran, learn the syntax and semantics of statement functions. Justify their existence in Fortran.
A : The Fortran 1966 standard provided a reference syntax and semantics, but vendors continued to provide incompatible extensions. These standards have improved portability.

Q10 : Study the methods of user-defined operator overloading in C++ and Ada, and write a report comparing the two using our criteria for evaluating languages.
A : One of the nice features of C++ is that you can give special meanings to operators, when they are used with user-defined classes. This is called operator overloading. You can implement C++ operator overloads by providing special member-functions on your classes that follow a particular naming convention. For example, to overload the + operator for your class, you would provide a member-function named operator+ on your class.
Meanwhile for Ada, since much of the power of the language comes from its extensibility, and since proper use of that extensibility requires that we make as little distinction as possible between predefined and user-defined types, it is natural that Ada also permits new operations to be defined, by declaring new overloadings of the operator symbols.

Chapter 9 : Review Question

Q6 : What is a Ruby array formal parameter?
A : Ruby supports a complicated but highly flexible actual parameter configuration. The initial parameters are expressions, whose value objects are passed to the corresponding formal parameters. The initial parameters can be following by a list of key => value pairs, which are placed in an anonymous hash and a reference to that hash is passed to the next formal parameter. These are used as a substitute for keyword parameters, which Ruby does not support. The hash item can be followed by a single parameter preceded by an asterisk. This parameter is called the array formal parameter.

Q7 :  What is a parameter profile? What is a subprogram protocol?
A : Parameter profile is the number, order, and types of its formal parameters.
Subprogram protocol is its parameter profile plus, if it is a function, its return type. In languages in which subprograms have types, those types are defined by the subprogram’s protocol.

Q8 : What are formal parameters? What are actual parameters?
A : Formal parameters are the parameters in the subprogram header.
Actual parameters are a list of parameters to be bound to the formal parameters of the subprogram which must be included with the name of the subprogram by the subprogram call statements.

Q9 : What are the advantages and disadvantages of keyword parameters?
A : The advantage of keyword parameters is that they can appear in any order in the actual parameter list. The disadvantage to keyword parameters is that the user of the subprogram must know the names of formal parameters.

Q10 : What are the differences between a function and a procedure?
A : A function returns value but procedures do not. Function are structurally resemble procedures but are semantically modeled on mathematical parameter.