Creating examples will show you what you need to do. Check the examples 
below if I understood your intention.

; unique-right
; List<Any> -> List<Any>
; returns a list which has only the right most occurrences of the elements 
of lst
(check-expect (unique-right '()) '())
(check-expect (unique-right (list "a")) (list "a"))
(check-expect (unique-right (list "a" "b" "a")) (list "b" "a"))
(check-expect (unique-right (list "a" "b" "a" "c" "d" "c")) (list "b" "a" 
"d" "c"))
(define (unique-right lst)
  (cond
    [(empty? lst) '()]
    [else (if (mymember? (first lst) (rest lst))
              (unique-right (rest lst))
              (cons (first lst) (unique-right (rest lst))))]))

; mymember
; Any List<Any> -> Boolean
; is elt in list
(check-expect (mymember? "a" '()) #false)
(check-expect (mymember? "a" (list "a")) #true)
(check-expect (mymember? "c" (list "a" "b" "a")) #false)
(define (mymember? elt lst)
  (cond
    [(empty? lst) #false]
    [else (or (equal? elt (first lst))
              (mymember? elt (rest lst)))]))

On Friday, July 24, 2020 at 11:43:48 AM UTC+8, JJ C wrote:
>
> I am in a course where I have to use beginning student with list 
> abbreviation in Racket to do assignments. 
> Below is my code for unique-right, which is supposed to return a list 
> which has only the right most occurrences of the elements of list. 
> The restriction in doing the asisngment is that I cannot use any of the 
> built-in functions such as append or member. 
> I'd need to re name a function and define it as I was doing below. For 
> example, in the place where I need to use member? I renamed it as mymember.
> Now what I am trying to do is define the helper function mymember. I know 
> that that bold part is incorrect but I have no idea at the moment how to 
> make the code correct. 
>
>
>
>
> ; unique-right
> ; List<Any> -> List<Any>
> ; returns a list which has only the right most occurrences of the elements 
> of lst
>
> (define (unique-right lst)
>   (cond
>     [(empty? lst) lst]
>     [else (if (mymember? (first lst) (rest lst)) (unique-right (rest lst)) 
> (cons (first lst) (unique-right (rest lst))))]))
>
>
>
> *; mymember*
> *; List<Any> -> List<Any>*
> *; returns a list that has all of the elements of lst plus a non-occurring 
> elt*
>
> *(define (mymember elt lst)*
> *  (cond*
> *    [(empty? lst) lst]*
> *    [else (if (equal? elt (first lst))*
> *              lst*
> *              (cons (mymember elt (rest lst)))]))*
>              
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/1e2421da-4c5c-4d31-9d7d-8b2db15b9383o%40googlegroups.com.

Reply via email to