I've attempted to use a recursive function to return pairs from a list of lists by using a combination of car/cdr functions.
y is an empty list that will store the pairs from ev-lst, then be returned to the console and ev-lst is the list of lists that I will be use to access the pairs. Each sublist in ev-lst has the format: (integer, integer, pair)
From the first to second-to-last sub-lists the program should append the pair from the "first" sublist to y in that particular iteration.
Afterwards it should pass the rest of the sub-lists as a parameter to the function so it will iterate again. When it finishes its final iteration each iteration's y will be returned and then appended to the previous iteration's y until the end is reached at which point the final y will be returned to the console with all pairs.
When only 1 sub-list remains, a different car/cdr function is used to access the pair there and return it but that produces an error saying that a contract violation has been committed. I've tried changed the car/cdr function but it unfortunately produces the same result. I have no idea how to fix it.
The code is:
(define (event-params-lst ev-lst)
(let ((y (list '() )))
(if (< 1 (length ev-lst))
(append y (cddar ev-lst)
append y (event-params-lst (cdr ev-lst)))
(
(caddr ev-lst)
)
)
(y))
)
It is very difficult to understand from your description what the intended result is.
I think the main problem is that you're thinking in terms of loops and mutation, as if you're programming in some other language where those are the fundamental building blocks, and you're describing that code rather than the problem it's intended to solve.
However, it sounds like your actual problem is extracting the third element from each element of a list of triples.
That is,
This is just
or, in Racket and more readable,
If you desperately want to use explicit recursion, follow the "transform a list into another list with the same structure" pattern,
like this: