Docsity

Prolog Rules and Computer Tasks - Prof. Randy R. Appleton, Study notes of Programming Languages

Toggle sidebar
bg1
The No-Computer
Part
1) Assume I have the following prolog rules.
mustang(X, Y) :- mustang(Y,X).
mustang(X,X).
What will the following bit of prolog print?
mustang(a,a).
2) What does the following scheme code do: (a)
a) Make a list with an 'a'.
b) Define the function 'a''.
c) This is not legal scheme.
d) None of these
3) Python and PHP have an eval() like function, that takes a string and runs it as if it was Python or
PHP. C++ does not. How come C++ would have a harder time implementing such a function if it is
easy in PHP or Python?
4) An array of 100,000 ints in C++ takes 400,000 bytes to store. It takes more than 400,000 bytes to
store in Python. Why?
5) To access an array element in C++ takes O(1) time. To access an array in PHP takes longer. How
come?
6) Which of the following strings are matched by the regular expression โ€œa{2,3}b?โ€?
abba abacas aback abort abend abeam
7) Write the following Java code in either PHP or Python.
public class foo {
public void set(int a) { a = b;}
pf3

Partial preview of the text

Download Prolog Rules and Computer Tasks - Prof. Randy R. Appleton and more Study notes Programming Languages in PDF only on Docsity!

The No-Computer

Part

  1. Assume I have the following prolog rules. mustang(X, Y) :- mustang(Y,X). mustang(X,X). What will the following bit of prolog print? mustang(a,a).
  2. What does the following scheme code do: (a) a) Make a list with an 'a'. b) Define the function 'a''. c) This is not legal scheme. d) None of these
  3. Python and PHP have an eval() like function, that takes a string and runs it as if it was Python or PHP. C++ does not. How come C++ would have a harder time implementing such a function if it is easy in PHP or Python?
  4. An array of 100,000 ints in C++ takes 400,000 bytes to store. It takes more than 400,000 bytes to store in Python. Why?
  5. To access an array element in C++ takes O(1) time. To access an array in PHP takes longer. How come?
  6. Which of the following strings are matched by the regular expression โ€œa{2,3}b?โ€? abba abacas aback abort abend abeam
  7. Write the following Java code in either PHP or Python. public class foo { public void set(int a) { a = b;}