Because this is homework, I can't give you a straight answer. Instead, I'll give you some hints, you can find the answer to your own question filing-in the blanks. This is the standard way to implement append
:
(define (my-append l1 l2)
(cond (<???> ; if the first list is null
<???>) ; then return the second list
(<???> ; if the second list is null
<???>) ; then return the first list
(else ; otherwise `cons`
(cons <???> ; the first element of the first list
(my-append <???> l2))))) ; process the rest of the first list
The above solution uses cond
, null?
, cons
, car
and cdr
. If you can't use any of those and you're restricted to the procedures in the question, try this instead (assuming accumulate
is defined as a fold to the right):
(define (my-append l1 l2)
(accumulate
<???> ; what should be used for sticking list elements together?
<???> ; what should we return if the list being traversed is empty?
<???>)) ; this is the list that we want to traverse
The above solution only uses accumulate
and cons
, as requested in the question. The idea is: traverse the first list recreating it element by element, until the list is exhausted - at that point, the next element will be the second list.