list - Racket - Separate Even and Odd Numbers? -


i'm trying build function in racket/scheme, given list of integers, , has sort them 2 sublists, 1 numbers, , 1 odd numbers. i'm new racket, , have of basics down manipulating lists, can't seen figure out how define 2 sublists , put numbers in each one.

this have far:

    (define (segregate lst)       (if (empty? lst)           '()           (if (even? (car lst))               (append (car alst) (segregate (cdr alst)))) 

and there i'm stuck. if condition, numbers sorted 1 list. need odd numbers too. else statement in condition give odd numbers, have no idea how them separate list.

this first time i've asked question on site, because professor not in office reason.

so, function needs return 2 lists, right? base case needs return 2 empty lists, , in recursive cases, fill in relevant 1 depending. here's skeletal code (fill in <???>):

(define (odds-and-evens lst)   (if (null? lst)       (values '() '())       (let-values (((odds evens) (odds-and-evens (cdr lst))))         (cond ((odd? (car lst)) (values (cons <???> <???>) <???>))               ((even? (car lst)) (values <???> (cons <???> <???>)))               (else (values odds evens)))))) 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -