# Special Topics: Functional Languages I-II Lecture 23

## Functional languages

### Scheme (a LISP dialiect)

```; eval takes an expression and an environment to a value
(define (eval e env) (cond
((symbol? e)       (cadr (assq e env)))
((eq? (car e) 'λ)  (cons e env))
(else              (apply (eval (car e) env) (eval (cadr e) env)))))

; apply takes a function and an argument to a value
(define (apply f x)
(eval (cddr (car f)) (cons (list (cadr (car f)) x) (cdr f))))

; read and parse stdin, then evaluate:

(eval '((λ x . x) (λ a . a)) '())

(eval '(λ x . x) '())

(eval '(((λ f . (λ x . (f x))) (λ a . a)) (λ b . b)) '())

(eval '((λ f . (f f)) (λ f . (f f))) '())  ; hmmmmm
```

## notes

### Compiling Closures

comparison to turing machines equivalent more "mathy", "programming languagey"

intuitive lambda calculus

defining common math/pl notions (numbers, booleans, operations on them, etc.)

operational semantics of lambda calculus, call-by-value vs. call-by-name

turing equivalence when would it not halt? what about iteration?

Created: 2023-04-13 Thu 14:59