Here's my code:
(define step1_list1 '(1 3 (5 7) 9))
(car (cdr (cdr (step1_list1))))
(define step1_list2 '((7)))
(car (step1_list2))
(define step1_list3 '(1 (2 (3 (4 (5 (6 7)))))))
(car (cdr (cdr (cdr (cdr (cdr step1_list3))))))
))
Running this code causes an error:
(1 3 (5 7) 9) is not applicable
What is the problem?
Start small.
(define mylist '(1 2 3))
(display mylist)
(display (car mylist))
(display (car (mylist)))
Run each of those in turn, and see what you get at each step. Once you understand why you get the output you do, then you should be able to fix the code in your question.
In Scheme, (non-quoted) parentheses mean function application. So (car (step1_list2)) tries to execute step1_list2 as a procedure (and then take the car of the result). Instead, you want:
(car step1_list2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With