

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A programming assignment for the university of central florida's school of computer science, where students are required to implement five functions in common lisp using only specified commands. Functions include simple-length, complex-length, swap, max-depth, and simple-merge.
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Homework 1 (LISP) Due on Thursday 03/02/06 by 11:59pm Instructions You must implement the following 5 functions in Common Lisp. For this homework you are restricted to only using the following Common Lisp commands.
Plagiary will not be tolerated. Feel free to discuss amongst yourselves, but do your own work. If you are not getting it, please make arrangements to see the TA (Chris), he can help explain things. The point of the homework is to learn to think recursively in Lisp. Functions to implement 1.- Write a function called SIMPLE-LENGTH that returns the number of items in the top level of a list. (SIMPLE-LENGTH '(a b c)) returns 3 (SIMPLE-LENGTH '(a (b c))) returns 2 (SIMPLE-LENGTH '(a b c (a (b c)))) returns 4 2.- Write a function called COMPLEX-LENGTH that returns the numbers of atoms in a list no matter how deeply nested they are. (COMPLEX-LENGTH '(a b c)) returns 3 (COMPLEX-LENGTH '(a (b c))) returns 3 (COMPLEX-LENGTH '(a b c (a (b c)))) returns 6 3.- Write a function called SWAP that accepts two atoms (A and B) and a list and replaces every instance of A with B in the list (SWAP 'a 'b '(a b c)) returns (b b c) (SWAP 'a 'b '(a b (a))) returns (b b (b)) 4.- Write a function called MAX-DEPTH that returns the level of the most deeply nested list in the input list. (MAX-DEPTH '(a b c)) returns 1 (MAX-DEPTH '(a (b) c)) returns 2 (MAX-DEPTH '(a b (((c))))) returns 4 (MAX-DEPTH '((a (b)) (c))) returns 3 5.- Write a function called SIMPLE-MERGE that accepts two presorted (low-to-high) lists and returns a list that is the sorted concatenation of the the two input lists. Be sure to handle repeated numbers. (SIMPLE-MERGE '(1 4 6) '(2 4 5)) returns (1 2 4 4 5 6) (SIMPLE-MERGE '(2 8 12) '(24)) returns (2 8 12 24) (SIMPLE-MERGE '(6 9 10) '(2 7 14)) returns (2 6 7 9 10 14)