I'm very sorry for such a simple question. It's so trivial, I haven't been able to find someone online with this problem. So I'd appreciate some help.
I want to write a very simple function that takes a list and an item, and appends that item to the end of the list.
The function I wrote recursively goes to the end of the list and returns the new item. It's so frustrating that this isn't working. It's the simplest function I've ever seen
(define (my-append lst item)
(if (null? lst)
item
(cons (car lst) (my-append (cdr lst) item))))
(display (my-append (list 1 2 3 4) 5))
This displays
(1 2 3 4 . 5)
I don't know why that dot is there, and it's extremely frustrating. I haven't come across it in any previous SO questions.
I just want to see
(1 2 3 4 5)
I would really really appreciate some help, because I'm extremely frustrated with this. If it helps, I'm running this code using an online compiler https://repl.it/languages/scheme