Lisp EN -- Test -- 2006-2007 -- info.uvt.ro

From Wikiversity
Important! These pages are somehow outdated and it is recommended to consult the newer version at Functional programming -- 2008-2009 -- info.uvt.ro (by Ciprian Crăciun).

Lisp EN -- 2006-2007 -- info.uvt.ro


Contents[edit]

The test will be next Saturday (2007-04-21), maybe in the morning. (The exact hour and location I will transmit at the next lab.)

The test will consist of 4 problems, each requesting to implement a specific function from the categories presented below. The time frame (the time allocated to solving the problems) will be 1 hour.


(Shallow) Tail recursive functions[edit]

This class of functions was presented in:

Examples:

  • Implement a shallow tail recursive function which removes all the occurrences of a given atom in a given list.
(my-remove-shallow 1 '(1 2 3 4 3 2 1)) => (2 3 4 3 2)
(my-remove-shallow 'a '(a b c a (a b c) a b)) => (b c (a b c) b)
  • Implement a shallow tail recursive function which counts all the elements that respect a given predicate in a given list.
(my-count-if #'oddp '(1 2 3 4 5)) => 3


Deep recursive functions[edit]

This class of functions was presented in:

Examples:

  • Implement a deep recursive function which substitutes all the occurrences of a given atom in a given tree (a list that contains other lists).
(my-substitute-deep 'a 1 '(a b c (a b c) a b c)) => (1 b c (1 b c) 1 b c)
  • Implement a deep recursive function which finds if in a given tree (a list that contains other lists) exists an element that respects a given predicate.
(my-find-if-deep #'zerop '(1 2 3 (0 4) 1 2)) => t
(my-find-if-deep #'numberp '(a b c (d e f) g)) => nil


Iterative functions[edit]

These functions should be implemented by using one of the following:

Examples:

  • Implement a function that sums all the number elements in a given list (it shall filter all the non numbers and ignore any embedded lists).
(my-sum '(1 2 a b c (3 4)) => 3


Macros[edit]

You will have to implement a macro that has a similar functionality to a given one. See Lisp EN -- Laboratory 6 -- 2006-2007 -- info.uvt.ro.

Examples:

  • Implement a macro that loops a given number of times and executes the given statements. (You must use do.)
(my-repeat 5
    (print "This message")
    (print "should appear 5 times..."))


Evaluation[edit]

Each of the four problems will be evaluated on a scale from 0 to 10.

For example some evaluation guide lines:

  • if the problem executes correctly (proven by at least 5 tests) and respects the constraints (for example is tail recursive) => 10;
  • if the problem executes correctly but does not respect the constraints => 8;
  • if the problem is almost correct and respects the constraints, but it does not compile (or executes) => 6;
  • if the problem is almost correct; but it does not compile (or executes) and does not respect the constraints => 5;
  • if there is at least some readable lisp code relating to the problem => 1 to 4 depending.
  • if you have to implement a tail recursive function but you don't know how, you can implement it as a normal recursive function, but you lose 2 points.
  • depending on the code-style and its consistency throughout the code you could lose 1 to 2 points.


Ciprian Dorin Craciun

2007-04-15

ccraciun@info.uvt.ro