koekoek wrote:
Code: Select all
;; Edited the indentation to make some structural issues clearer.
(defun sorter A
(cond (null A) nil)
(eq (difference ((car a) (greatest A)) 0) (cons (car A) (sorter cdr A)))
(t ( sorter (cons (cdr A) (car A))))
;; Where did these guys below come from?
)))
Is it totally wrong?
I'm sorry to say that it is. Your parameter, A, needs to be in parentheses, since defun requires a list of parameters. Your cond form ends far to soon, with only (null A) and nil as its arguments. Your parentheses aren't balanced at all, and in many places are missing or duplicated.
It would be easy to blame Lisp for requiring you to get all those parentheses in place, but please try not to. If you aren't using an editor that will highlight matching parentheses for you, start using one. That will make it easier to balance them right away. Many Lispers use editors that will automatically keep the parentheses balanced, but if you don't plan on writing Lisp again it probably won't be a good use of your time to learn one of these.
Once you get your parens fixed, you need to take another look at the last line. You're not constructing a proper list. Look at this:
Code: Select all
(cons (cons '(1 2 3 ) 4) 7) => (((1 2 3) . 4) . 7)
That's what you've got happening. See what you can do with the append function here.
As far as I can tell, your logic is correct, except for the last line, but the structure of your code is mangled so badly it won't even run. In any language, it's important to make sure the code you've written corresponds to what you actually want it to mean.