This lab explores list which will be covered in detail this week. In order to complete the lab, you will need to know:
cons function with makes a pair of a car and cdr.car and cdr.cons to build the following lists:
'(3 4)
'(1 2 3)
'(a (b c))
'(1)
'(2 (3 (4)))
Use car and cdr to obtain the elements from the list.
; Example:
; (define L '(1 2 3 4 5))
;
; (car L)
; => 1
;
; (cdr L)
; => '(2 3 4 5)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Combine calls car and cdr to get the element 2, 3, 4 and 5 from the list L (4 solutions).
; (define L '(1 2 3 4 5))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Combine calls car and cdr to get the element 2 and 5 from the list LL (2 solutions).
; (define LL '(1 (2 3 4) (5)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Note that you can use shorthand commands such
; (cadr '(1 2))
; => 2
; (car (cdr '(1 2)))
; => 2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; The function takes two indices, i and k, and produces the integers
; between i and k including i and k.
;
; Example:
; (range 4 9)
; => (4 5 6 7 8 9)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Please hand-in the answer to this question on Virtual Campus during your lab session but at the latest by Friday 6:00pm! Remember, your submission will only count if you have signed the lab attendance sheet.
Give a single function to access the element a in the list Q.
(define Q '(1 2 (a 3 4 5)))
;;;;;;;;;;;;;;;;;;;;;
; (your_answer Q)
; => 'a
;;;;;;;;;;;;;;;;;;;