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)))]))