I'm trying to build a function in Racket/Scheme, where you are given a list of integers, and then it has to sort them into two sublists, one for even numbers, and one for odd numbers. I'm very new to racket, and I have some of the basics down with manipulating lists, but I can't seen to figure out how to define two sublists and put numbers in each one.
This is what I have so far:
(define (segregate lst)
(if (empty? lst)
'()
(if (even? (car a lst))
(append (car alst) (segregate (cdr alst))))
And from there I'm stuck. So with that if condition, even numbers will be sorted into one list. But I need the odd numbers too. The else statement in this condition will give you those odd numbers, but I have no idea how to get them into a separate list.
This is the first time I've actually asked a question on this site, because my professor is not in his office for some reason.
carexpects exactly one argument, but you've got(car a lst). You've also got(car alst)and(cdr alst), but no variablealst. - Joshua Taylor