20-CS-4003-001 Organization of Programming Languages Fall 2017
Basic Operations

Lambda calculus, Type theory, Formal semantics, Program analysis

    Prev     Next     All lectures        Code

The let and let*

 
(let* ((p1 '(1 2 3 4 5 6))  -  Variable p1 is a List of 6 integers
1111111(p2 (list-ref p1 2))  -  p2 is 3 (show the third element starting the count at 1)
1111111(p3 (cddr p1))  -  p3 is '(3 4 5 6) (first two elements removed)
1111111(p4 (list (car p1) (cadr p1)))  -  p4 is '(1 2) (all but first two elements removed)
1111111(p5 (last p1))  -  p5 is 6 (all but first two elements removed)
1111111(p6 (cons -2 p1))  -  p6 is '(-2 1 2 3 4 5 6) (-2 placed at head of list)
1111111(p7 (cons '(1) '((2) (3) (4))))  -  p7 is '((1) (2) (3) (4)) (objects in list can be anything)
1111111(p8 (append '(1) '(2 3 4 5))))  -  p8 is '(1 2 3 4 5) (append the list '(2 3 4 5) to '(1))
111(list p1 p2 p3 p4 p5 p6 p7 p8))  -  output the results as a list