1. What are the three primary uses of symbolic logic in formal logic? -To express propositions, to express the relationships between propositions, and to describe how new propositions can be inferred from other propositions that are assumed to be true.
2. What are the two parts of a compound term? - Functor and ordered list of parameters.
3. What are the two modes in which a proposition can be stated? - One in which the proposition is defined to be true, and one in which the truth of the proposition is something that is to be determined. In other words, propositions can be stated to be facts or queries.
5. What are antecedents? Consequents? -Antecedents are right side of a clausal form proposition. Consequent is left side of a clausal form propositions.
6. Give general (not rigorous) definitions of resolution and unification. -Resolution is the inference rule that allows inferred propositions to be computed from given propositions, thus providing a method with potential application to automatic theorem proving. Unification is the process of determining useful values for variables.
9. What does it mean for a language to be nonprocedural? -Language in which the programs do not exactly state how a result is to be computed but rather describe the form of the result.
11. What is an uninstantiated variable? -A variable that has not been assigned a value.
13. What is a conjunction? -Conjunctions contain multiple terms that are separated by logical AND operations.
1. “All predicate calculus propositions can be algorithmically converted to clausal form”. Is this statement true or false? Explain. -This statement is true. Nilsson (1971) gives proof that this can be done, as well as a simple conversion algorithm for doing it.
2. Describe how a logic programming language is different from a general programming language. -Programming that uses a form of symbolic logic as a programming language, unlike other general programming language, is often called logic programming; languages based on symbolic logic are called logic programming languages, or declarative languages.
8. Critically comment on the following statement: “Logic programs are nonprocedural”. - It is true, because logical programs use lots of different processes based on its conditions. If a certain logical requirement is true, then a program will execute the corresponding process, instead of procedurally executing the statements.
2. What does a lambda expression specify? -The predicate function is often given as a lambda expression, which in ML is defined exactly like a function, except with the fn reserved word, instead of fun, and of course the lambda expression is nameless.
5. Explain why QUOTE is needed for a parameter that is a data list. -To avoid evaluating a parameter, it is first given as a parameter to the primitive function QUOTE, which simply returns it without change.
6. What is a simple list? - A list which membership of a given atom in a given list that does not include sublists.
7. What does the abbreviation REPL stand for?
-REPL stand for read-evaluate-print loop.
11. What are the two forms of DEFINE? -The simplest form of DEFINE is one used to bind a name to the value of an expression. This form is (DEFINE symbol expression) The general form of such a DEFINE is (DEFINE (function_name parameters) (expression)
13. Why are CAR and CDR so named? -The names of the CAR and CDR functions are peculiar at best. The origin of these names lies in the first implementation of LISP, which was on an IBM 704 computer. The 704’s memory words had two fields, named decrement and address, that were used in various operand addressing strategies.
Each of these fields could store a machine memory address. The 704 also included two machine instructions, also named CAR (contents of the address part of a register) and CDR (contents of the decrement part of a register), that extracted the associated fields. It was natural to use the two fields to store the two pointers of a list node so that a memory word could neatly store a node.
Using these conventions,the CAR and CDR instructions of the 704 provided efficient list selectors. The names carried over into the primitives of all dialects of LISP.
18. What is tail recursion? Why is it important to define functions that use recursion to specify repetition to be tail recursive?
-A function is tail recursive if its recursive call is the last operation in the function. This means that the return value of the recursive call is the return value of the nonrecursive call to the function. It is important to specify repetition to be tail recursive because it is more efficient(increase the efficiency).
19. Why were imperative features added to most dialects of LISP? - LISP began as a pure functional language but soon acquired some important imperative features to increased its execution efficiency.
26. What is type inferencing, as used in ML? -Type inference refers to the automatic deduction of the type of an expression in a programming language. If some, but not all, type annotations are already present it is referred to as type reconstruction.
29. What is a curried function? -Curried functions a function which a new functions can be constructed from them by partial evaluation.
30. What does partial evaluation mean? - Partial evaluation means that the function is evaluated with actual parameters for one or more of the leftmost formal parameters.
32. What is the use of the evaluation environment table? -A table called the evaluation environment stores the names of all implicitly and explicitly declared identifiers in a program, along with their types. This is like a run-time symbol table.
33. Explain the process of currying.
- The process of currying replaces a function with more than one parameter with a function with one parameter that returns a function that takes the other parameters of the initial function.
8. How is the functional operator pipeline ( |> ) used in F#? answer: The pipeline operator is a binary operator that sends the value of its left operand, which is an expression, to the last parameter of the function call, which is the right operand. It is used to chain together function calls while flowing the data being processed to each call.
9. What does the following Scheme function do? (define ( y s lis) (cond (( null? lis) ‘ () ) ((equal? s (car lis)) lis) (else (y s (cdr lis))) ))
answer: y returns the given list with leading elements removed up to but not including the first occurrence of the first given parameter.
6. What is exception propagation in Ada? -Exception propagation allows an exception raised in one program unit to be handled in some other unit in its dynamic or static ancestry. This allows a single exception handler to be used for any number of different program units. This reuse can result in significant savings in development cost, program size, and program complexity.
9. What is the scope of exception handlers in Ada? -Exception handlers can be included in blocks or in the bodies of subprograms, packages, or tasks.
10. What are the four exceptions defined in the Standard package of Ada? -There are four exceptions that are defined in the default package, Standard: - Constraint_Error - Program_Error - Storage_Error - Tasking_Error
11. Are they any predefined exceptions in Ada? -Yes
12. What is the use of Suppress pragma in Ada?
-The suppress pragma is used to disable certain run-time checks that are parts of the built-in exceptions in Ada.
14. What is the name of all C++ exception handlers? -Try clause.
30. In which version were assertions added to Java? -Assertions were added to Java in version 1.4.
31. What is the use of the assert statement? -The assert statement is used for defensive programming. A program may be written with many assert statements, which ensure that the program’s computation is on track to produce correct results.
32. What is event-driven programming? -Event-driven programming is a programming where parts of the program are executed at completely unpredictable times, often triggered by user interactions with the executing program.
33. What is the purpose of a Java JFrame? -The JFrame class defines the data and methods that are needed for frames. So, a class that uses a frame can be a subclass of JFrame. A JFrame has several layers, called panes.
34. What are the different forms of assert statement? -There are two possible forms of the assert statement: a.assert condition; b.assert condition : expression;
1.What mechanism did early programming languages provide to detect or attempt to deal with errors?
-Early programming languages were designed and implemented in such a way that the user program could neither detect nor attempt to deal with such errors. In these languages, the occurrence of such an error simply causes the program to be terminated and control to be transferred to the operating system.
2.Describe the approach for the detection of subscript range errors used in C and Java.
-In C subscript ranges are not checked. Java compilers usually generate code to check the correctness of every subscript expression. If any exception generates, then an unchecked exception is thrown.
6.In languages without exception-handling facilities, it is common to have most subprograms include an “error” parameter, Which can be set to some values representing “OK” or some other value representing “error in procedure”. What advantage does a linguistic exception-handling facility like that of Ada have over this method?
-There are several advantages of a linguistic mechanism for handling exceptions, such as that found in Ada, over simply using a flag error parameter in all subprograms. One advantage is that the code to test the flag after every call is eliminated. Such testing makes programs longer and harder to read. Another advantage is that exceptions can be propagated farther than one level of control in a uniform and implicit way. Finally, there is the advantage that all programs use a uniform method for dealing with unusual circumstances, leading to enhanced readability.
7.In languages without exception-handling facilities, we could send an error-handling procedure as parameter to each procedure that can detect errors than must be handled. What disadvantage are there to this method?
- There are several disadvantages of sending error handling subprograms to other subprograms. One is that it may be necessary to send several error handlers to some subprograms, greatly complicating both the writing and execution of calls. Another is that there is no method of propagating exceptions, meaning that they must all be handled locally. This complicates exception handling, because it requires more attention to handling in more places.
14. Summarize the arguments in favor of the termination and resumption models of continuation. -The resumption model is useful when the exception is only an unusual condition, rather than an error. The termination model is useful when the exception is an error and it is highly unlikely that the error can be corrected so that execution could continue in some useful way.