Keys to Lisp – One

 

CIS447

 

Pieces of the fclean function:

Whether or not you plan to write the fclean function, the information here is important to the proper use of the full power of Lisp.

 

Key Functions:

atom – checks whether or not its argument is an atom.

listp – checks whether or not its argument is a list.

          Check out the appropriate sections of:

http://www.supelec.fr/docs/cltl/clm/node73.html#SECTION001022000000000000000

Equality predicates:

          eq, equal, equalp, eql, =

peruse this link from Steele: http://www.supelec.fr/docs/cltl/clm/node74.html#SECTION001030000000000000000

Notice the results of the following Lisp forms:

(eq ‘a ‘a)

(equal ‘a ‘a)

(eq ‘a ‘b)

(equal ‘a ‘b)

(eq ‘(a) ‘(a))

(equal ‘(a) ‘(a))

member – checks to see if its first argument is an element of its 2nd argument.

          Read the first page or so of this section of Steele’s book.

http://www.supelec.fr/docs/cltl/clm/node152.html#SECTION001950000000000000000

member with :test – uses specified membership test.

 

Exercise:

Write the following function (test):

neg-of:

(neg-of x y) – t, if x = –y

                   nil, otherwise

 

Write the following function using neg-of:

neg-member:

(neg-member elt list) – t, if –elt Ξ list, where elt and all the elements of list are integers.

                   nil, otherwise

 

Write the following function using neg-member:

neg-intersection:

(neg-intersection list1 list2) – returns those elements of list1 which are the negation of some element in list2, where are the elements of both lists are integers.

 

let, let* – used to establish local variables

          Read the initial section of this:

http://www.supelec.fr/docs/cltl/clm/node83.html#SECTION001150000000000000000

 

Exercise:

Write the following function:

pospogressionp:

(posprogressionp list) – t, if for all i, elti  < elti+1, where all the elements of list are integers and where elti and elti+1 are the ith and i+1st positive integers of list.

                   nil, otherwise

Write the following function using posprogressionp and let:

posprogressions-of:

(posprogressions-of lolist) – returns a new list consisting of all the posprogressions of lolist, where lolist is a list whose elements are lists of integers, and where a pospogression contains only positive integers.

 

Exercise:

Write the following functions:

same:

(same x y) – t, if x & y are both atoms & are eq OR x & Y are both sets & are sameset;

                   nil, otherwise

xsubset:

extended subset:

(xsubset list1 list2) – like the subset function, but does not require that lst1 & lst2 are flat lists.

 

The expansion paradox:

Sometimes it is easier to solve a more general problem than to solve a more specific problem, even when the solution to the more specific problem can be derived from the more general solution.

 

Question: How would this be applied to the fclean function?