This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Ordering a list depending on the order of elements in anothe

4 posts · 4900 views

I have a list
(SetQ L '(1 j 3 k 4 h 5 n 6 w))
I have to do a function Order that has a list with 'n' atoms at entry, it must check if each atom of that list is contained in list L and order them according to the order specified in list L, if the atom is not part of the list L then the result will be displayed
(Defun Order lst)

(SetQ L2'(w o 5 j 3))
I want to verify this:
(Order L2)
result should return:
(J 3 5 W)

Re: Ordering a list depending on the order of elements in an

Sorry, but this forum is not called "we make your homework".

Re: Ordering a list depending on the order of elements in an

I moved the topic to the homework forum. The source language is CL.

Re: Ordering a list depending on the order of elements in an

So this problem is designed to step through one list and at each atom check if it exists in the other.

This problem is asking you to make two recursive tasks, one based on L and one on L2. I suggest you start with L as it defines your order.

L's function:
If null, return nil
else If L2 contains car L return car L
else call L's function with cdr L.

L2's funciton:
If L2 null, return nil
else if car L equals car L2 return car L2
else call L2's function with cdr L2

Put those two together and there you go.