This should maybe be a simple task, but I do have some problem understanding the function and what to insert. Yes, this is an obligatory task I have to deliver by Friday this week, but I can ask anybody about help, except my teacher will of course not tell me the answer. Therefore I’ll try to ask on this LISP Forum.
This is how the task is:
Formulate a LISP function which compares the arrangement of a string pair, where the first element counts most. You can take a starting point with the function my.compare and my.compare2 below. Make sure the function is able to sort a list.
The list: ‘((a b) (b c) (b a) (a a))
And sort it to this list: ‘((a a) (a b) (b a) (b c))
In the function my.compare and my.compare2 you shall compare the arrange on the first element with this function:
(defun my.compare (x y)
(string< (car x) (car y))
)
And then arrange the pair on the second element with this function:
(defun my.compare2 (x y)
(string< (car (cdr x)) (car (cdr y)))
)
So basically the answer shall be like this: ‘((a a) (a b) (b a) (b c))
It is just that I don’t know how to type it in the function, so a little help would be really awesome.
Thanks Ceenth
This is how the task is:
Formulate a LISP function which compares the arrangement of a string pair, where the first element counts most. You can take a starting point with the function my.compare and my.compare2 below. Make sure the function is able to sort a list.
The list: ‘((a b) (b c) (b a) (a a))
And sort it to this list: ‘((a a) (a b) (b a) (b c))
In the function my.compare and my.compare2 you shall compare the arrange on the first element with this function:
(defun my.compare (x y)
(string< (car x) (car y))
)
And then arrange the pair on the second element with this function:
(defun my.compare2 (x y)
(string< (car (cdr x)) (car (cdr y)))
)
So basically the answer shall be like this: ‘((a a) (a b) (b a) (b c))
It is just that I don’t know how to type it in the function, so a little help would be really awesome.
Thanks Ceenth