This recursive function seems to work properly, adding to the result list the exact letters I want it to, B and C, and then when it finishes, it correctly sees that the last element has been reached.
It then executes the base case, and an error occurs which I cannot explain. What is causing this error?
(define(preceding-R X Vector result)
(if (eq? '() (cdr (vector->list Vector)))
result
(helper X Vector result)))
(define (helper X Vector result)
(if(eqv? X (cadr (vector->list Vector))) ((set! result (cons result (car (vector->list Vector)))) (preceding-R X (list->vector (cdr (vector->list Vector))) result))
(preceding-R X (list->vector (cdr (vector->list Vector))) result)))
(preceding-R 'a #(b a c a) '()))
The error:
procedure application: expected procedure, given: #; arguments were: ((() . b) . c)