Lists

Table of Contents

1. Review on Lists

1.1. Cons vs. List

CONS

        (cons 10(cons 20(cons 30 '())))

LIST

        (list 10 20 30)

^ lists is inherently using cons

returns > ’(10 20 30)

BIGGER EXAMPLE:

        (list 7
                (list 8 9 (list 10))
                (list 11 12)
                (list)
                13)

returns > ’(7 (8 9(10)) (11 12) () 13))

1.2. Permeating Quotes

Making lists wherever there are quotes

= (list 7 ’(8 9 (10) ’(11 12) ’() 13)

= list 7 (list 8 9 ’(10) (list 11 12) (list) 13)

= list 7 (list 8 9 (list 10) (list 11 12) (list) 13)

Simple Error with symbols and lists

(define x 4)

(list 1 2 3 x) -> (1 2 3 4)

’(1 2 3 x) -> ’(1 2 3 x) because it permates ’x as a symbol

What is the length of this list ?

(cons ’(1 2) ’(3 4))

(cons (cons 1(cons 2 ’()))

(cons 3(cons 4 ’()))

return > ’((1 2) 3 4)

The length is 3

2. Program Languages

Program -> [magic box] -> Result

SPLIT THE MAGIC BOX

program -> [Parser] -> Abstract Syntax Tree (AST) -> [Interp] -> Result

2.1. Abstract Syntax Tree

2 * ( 3 + 4 )

(define-type ExprC (U NumC PlusC MultC))

(struct NumC([n : Real]))
(struct PlusC([l: ExprC]
              [r: ExprC]))
(struct MultC([l: ExprC]
              [r: ExprC]))

(MultC (NumC 2)
        (PlusC (NumC 3)
                (NumC 4)))

Date: 2024-09-30 Mon 00:00

Author: Anthony Rossi

Created: 2024-10-02 Wed 11:26