- Type
- Midterm past paper
- Course
- CS508 Modern Programming Languages
- Size
- PDF 6 MB
- Updated
- 23 Oct 2026
You get 3 free files a day on the website. Add the Chrome extensionSign in with the extension for 30 a day.
Preview text
Text from pages 2, 3, 4 of 380. Download the file for all 380 pages.
M
Compare ADA dor loop with dolist and dotime in LISP
Answer: page 72
Iteration: dotimes and dolist
Apart from recursion, in LISP we can write code involving loops using iterative non recursive mechanism. There are two basic statements for that purpose: dotimes and dolist. These are discussed in the following paragraphs. dotimes dotimesis like a counter-control for loop. Its syntax is given as below: (dotimes(count n result) body) It executes the body of the loop n times where count starts with 0, ends with n-1. The result is optional and is to be used to hold the computing result. If result is given, the function will return the value of result. Otherwise it returns NIL. The value of the count can be used in the loop body.
dolist
The second looping structure is dolist. It is used to iterate over the list elements, one at a time. Its syntax is given below: (dolist(x L result) body) It executes the body for each top level element x in L. x is not equal to an element of L in each iteration, but rather x takes an element of L as its value. The value of x can be used in the loop body. As we have seen in the case of dotimes, the resultis optional and is to be used to hold the computing result. If result is given, the function will return the value of result. Otherwise it returns NIL.
Q. No. 2 M - 5
Differentiate between ADA access types and C/C++ pointer type
Answer: page 52 An access type roughly corresponds to a C++ pointer. typeAddress_Ref is access Address; A_Ref := new Address; A_Ref. Postal_Code := "94960-1234"; Note that, unlike C, there is no notational difference for accessing a record field directly or through an access value. To refer to the entire record accessed by an access value use the following notation: Print(A_Ref.all);
Q. No. 3 M - 3
Why predicate is a special function in LISP
A predicate is a special function which returns NIL if the predicate is false, T or anything other than NIL, otherwise. Predicates are used to build Boolean expressions in the logical Statements. The following comparative operators are used as functions for numerical values and return a T or NIL. =,
- (= (+ 2 4) (* 2 3))
- T
- (> (- 5 2) (+ 3 1))
- NIL
Differentiate between C/C++ unions and ADA discriminated type (3)
Discriminated Records
Discriminated records are like union types in C. There are however major differences between C union types and Ada discriminated records. The union type in C is fundamentally unsafe, and therefore unacceptable. For example, consider the following definition: union(int, float) puzzle;
Now puzzle has either an intor a float. But at runtime, the compiler and the environment cannot tell which particular value has been stored currently. So we have to trust the programmer. In Ada we are short on trust. The whole philosophy is that a programmer is a human and all humans make mistakes. So to make it safer, Ada uses discriminates in a record that tells what type of data is currently stored there. This is shown in the following example: typeIF is(Int, Float); typeInt_Float (V : IF := Int) is record caseV is whenInt => Int_Val : Integer; whenFloat => Float_Val : Float; end case; end record;
What additional features are added in COBOL
Answer: page 27
It was the first language to add macro facility in a high-level language. It also introduced hierarchical data structures(records) and nested selection statements. The language supported long variable names (up to 30 characters) with hyphens, data division, and fixed-point arithmetic.
Is there anything like templates as in C++.
Answer: page 60
Generics are like templates in C++ and allow parameterization of subprograms and packages with parameters which can be types and subprograms as well as values and objects.
Q1. Whether polymorphism is allowed in Ada or not? Briefly state. (2 marks)
Answer: Ada 83 supported a form of polymorphism through the use of overloading that allowed the developer to reuse a procedural name or operator by redefining the context and semantics. For example, when using integer numbers, the + sign adds one integer to another. The + operator could be redefined to work with an abstract data type consisting of a set of colors and provide the proper color mix (i.e., red + yellow = orange). This polymorphic behavior had to be resolved at compile time. Ada 95 supports a true polymorphic operation through the use of class-wide types and type extensions, which can contextually recognize the appropriate operation to perform.
Q2. How Bitwise Exclusive Or, and Not is represented in Ada? (2 marks)
Bitwise Exclusive Or =Xor Bitwise Not =Not Logical Not =Not
Q3. Identify Local and Global variable (3 marks)
>(defun y-plus(x)(+x y))
Answer: page 69
This function adds x to y where x is the parameter passed to the function and y is a global variable since it is not defined inside the function. It works in the following manner: >(setq y 2) >(y-plus 23)
With this we introduce the concept of local and global variables. Local variables are defined in function body. Everything else is global.
Related CS508 files
All CS508 files →- CS508 Midterm Past Papers by Mr Attitude Midterm PDF 932 KB
- CS508 Midterm Solved MCQs with References by Arslan Midterm PDF 562 KB
- CS508 Midterm Past Papers by Junaid Midterm PDF 1.5 MB
- CS508 Midterm Solved Papers by Fatima Ali Midterm PDF 288 KB
- CS508 Official Handouts Official handout PDF 1.2 MB Free
- CS508 Solved Quiz 4 by Masters Quiz PDF 5.6 MB
Get more out of VUBuddy, for free
- Unlimited downloads
- The explanation behind every MCQ answer
- Study offline on slow data
- 30 downloads a day instead of 3
- Sign in and buy Pro Semester here
One Pro Semester membership works in both the extension and the app.