so i’m trying to write a procedure known as sort-nums so that i can get all the numbers and sort them like this
(define (sort-nums lst)
(if (null? lst) null
(if (number? (car lst)
i want this part to keep the number and then delete anything that isnt a number
(sort (cons (car lst) (sort-nums (cdr lst))))))
if possible would this work or would i need to write it in a different way an example to prove that it works would be like
(sort-nums (list ‘a ‘c 24 ‘f ‘g 16))
(16 24)
You can make your life easier by sorting and stripping numbers separately. Try
First we select only those things that are numbers (using
list-transform-positive), then we sort them ascending (usingsort).As a general tip, you will find lisp much easier to work with if you indent intelligently.