| | ;; make a list and bind it to the symbol ls
guile> (define ls (list 1 2 3 4 5 6 7))
=>
;; display the list
guile> ls
=> (1 2 3 4 5 6 7)
;; ask if ls is a vector; #f means it is not
guile> (vector? ls)
=> #f
;; ask if ls is a list; #t means it is
guile> (list? ls)
=> #t
;; ask for the length of ls
guile> (length ls)
=> 7
;; pick out the first element of the list
guile> (car ls)
=> 1
;; pick the rest of the list without the first element
guile> (cdr ls)
=> (2 3 4 5 6 7)
;; this should pick out the 3rd element of the list
guile> (car (cdr (cdr ls)))
=> 3
;; a shorthand for doing the same thing
guile> (caddr ls)
=> 3
;; append the given list onto ls, print the result
;; NOTE: the original list ls is not modified
guile> (append ls (list 8 9 10))
=> (1 2 3 4 5 6 7 8 9 10)
guile> (reverse ls)
=> (10 9 8 7 6 5 4 3 2 1)
;; ask if 12 is in the list --- it obviously is not
guile> (memq 12 ls)
=> #f
;; ask if 4 is in the list --- returns the list from 4 on.
;; Notice that the result will behave as true in conditionals
guile> (memq 4 ls)
=> (4 5 6 7)
;; an if statement using the aforementioned result
guile> (if (memq 4 ls)
(display "hey, it's true!\n")
(display "dude, it's false\n"))
@print{hey, it's true!}
=>
guile> (if (memq 12 ls)
(display "hey, it's true!\n")
(display "dude, it's false\n"))
@print{dude, it's false}
=>
guile> (memq 4 (reverse ls))
=> (4 3 2 1)
;; make a smaller list ls2 to work with
guile> (define ls2 (list 2 3 4))
;; make a list in which the function sin has been
;; applied to all elements of ls2
guile> (map sin ls2)
=> (0.909297426825682 0.141120008059867 -0.756802495307928)
;; make a list in which the squaring function has been
;; applied to all elements of ls
guile> (map (lambda (n) (expt n n)) ls)
=> (1 4 27 256 3125 46656 823543)
|