61a extra lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-macros_1pp.pdf · (demo)...

56
61A Extra Lecture 8

Upload: others

Post on 19-Oct-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

61A Extra Lecture 8

Page 2: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Announcements

Page 3: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Homoiconicity

Page 4: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

A Scheme Expression is a Scheme List

4

Page 5: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

A Scheme Expression is a Scheme List

Scheme programs consist of expressions, which can be:

4

Page 6: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

A Scheme Expression is a Scheme List

Scheme programs consist of expressions, which can be:

•Primitive expressions: 2 3.3 true + quotient

4

Page 7: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

A Scheme Expression is a Scheme List

Scheme programs consist of expressions, which can be:

•Primitive expressions: 2 3.3 true + quotient•Combinations: (quotient 10 2) (not true)

4

Page 8: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

A Scheme Expression is a Scheme List

Scheme programs consist of expressions, which can be:

•Primitive expressions: 2 3.3 true + quotient•Combinations: (quotient 10 2) (not true)

4

The built-in Scheme list data structure (which is a linked list) can represent combinations

Page 9: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

A Scheme Expression is a Scheme List

Scheme programs consist of expressions, which can be:

•Primitive expressions: 2 3.3 true + quotient•Combinations: (quotient 10 2) (not true)

4

scm> (list 'quotient 10 2)

The built-in Scheme list data structure (which is a linked list) can represent combinations

Page 10: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

A Scheme Expression is a Scheme List

Scheme programs consist of expressions, which can be:

•Primitive expressions: 2 3.3 true + quotient•Combinations: (quotient 10 2) (not true)

4

scm> (list 'quotient 10 2)(quotient 10 2)

The built-in Scheme list data structure (which is a linked list) can represent combinations

Page 11: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

A Scheme Expression is a Scheme List

Scheme programs consist of expressions, which can be:

•Primitive expressions: 2 3.3 true + quotient•Combinations: (quotient 10 2) (not true)

4

scm> (list 'quotient 10 2)(quotient 10 2)

The built-in Scheme list data structure (which is a linked list) can represent combinations

Page 12: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

A Scheme Expression is a Scheme List

Scheme programs consist of expressions, which can be:

•Primitive expressions: 2 3.3 true + quotient•Combinations: (quotient 10 2) (not true)

4

scm> (list 'quotient 10 2)(quotient 10 2)

scm> (eval (list 'quotient 10 2))

The built-in Scheme list data structure (which is a linked list) can represent combinations

Page 13: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

A Scheme Expression is a Scheme List

Scheme programs consist of expressions, which can be:

•Primitive expressions: 2 3.3 true + quotient•Combinations: (quotient 10 2) (not true)

4

scm> (list 'quotient 10 2)(quotient 10 2)

scm> (eval (list 'quotient 10 2))5

The built-in Scheme list data structure (which is a linked list) can represent combinations

Page 14: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

A Scheme Expression is a Scheme List

Scheme programs consist of expressions, which can be:

•Primitive expressions: 2 3.3 true + quotient•Combinations: (quotient 10 2) (not true)

4

scm> (list 'quotient 10 2)(quotient 10 2)

scm> (eval (list 'quotient 10 2))5

The built-in Scheme list data structure (which is a linked list) can represent combinations

Page 15: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

A Scheme Expression is a Scheme List

Scheme programs consist of expressions, which can be:

•Primitive expressions: 2 3.3 true + quotient•Combinations: (quotient 10 2) (not true)

4

scm> (list 'quotient 10 2)(quotient 10 2)

scm> (eval (list 'quotient 10 2))5

The built-in Scheme list data structure (which is a linked list) can represent combinations

In such a language, it is straightforward to write a program that writes a program

Page 16: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

A Scheme Expression is a Scheme List

Scheme programs consist of expressions, which can be:

•Primitive expressions: 2 3.3 true + quotient•Combinations: (quotient 10 2) (not true)

4

scm> (list 'quotient 10 2)(quotient 10 2)

scm> (eval (list 'quotient 10 2))5

(Demo)

The built-in Scheme list data structure (which is a linked list) can represent combinations

In such a language, it is straightforward to write a program that writes a program

Page 17: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Homoiconic Languages

5

Page 18: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Homoiconic Languages

Languages have both a concrete syntax and an abstract syntax

5

Page 19: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Homoiconic Languages

Languages have both a concrete syntax and an abstract syntax

(Python Demo)

5

Page 20: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Homoiconic Languages

Languages have both a concrete syntax and an abstract syntax

(Python Demo)

A language is homoiconic if the abstract syntax can be read from the concrete syntax

5

Page 21: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Homoiconic Languages

Languages have both a concrete syntax and an abstract syntax

(Python Demo)

A language is homoiconic if the abstract syntax can be read from the concrete syntax

(Scheme Demo)

5

Page 22: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Homoiconic Languages

Languages have both a concrete syntax and an abstract syntax

(Python Demo)

A language is homoiconic if the abstract syntax can be read from the concrete syntax

(Scheme Demo)

Quotation is actually a combination in disguise

5

Page 23: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Homoiconic Languages

Languages have both a concrete syntax and an abstract syntax

(Python Demo)

A language is homoiconic if the abstract syntax can be read from the concrete syntax

(Scheme Demo)

Quotation is actually a combination in disguise

(Quote Demo)

5

Page 24: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Homoiconic Languages

Languages have both a concrete syntax and an abstract syntax

(Python Demo)

A language is homoiconic if the abstract syntax can be read from the concrete syntax

(Scheme Demo)

Quotation is actually a combination in disguise

(Quote Demo)

5

Page 25: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Macros

Page 26: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Macros Perform Code Transformations

7

Page 27: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Macros Perform Code Transformations

A macro is an operation performed on the source code of a program before evaluation

7

Page 28: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Macros Perform Code Transformations

A macro is an operation performed on the source code of a program before evaluation

Macros exist in many languages, but are easiest to define correctly in homoiconic languages

7

Page 29: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Macros Perform Code Transformations

A macro is an operation performed on the source code of a program before evaluation

Macros exist in many languages, but are easiest to define correctly in homoiconic languages

Scheme has a define-macro special form that defines a source code transformation

7

Page 30: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Macros Perform Code Transformations

A macro is an operation performed on the source code of a program before evaluation

Macros exist in many languages, but are easiest to define correctly in homoiconic languages

Scheme has a define-macro special form that defines a source code transformation

7

(define-macro (twice expr) (list 'begin expr expr))

Page 31: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Macros Perform Code Transformations

A macro is an operation performed on the source code of a program before evaluation

Macros exist in many languages, but are easiest to define correctly in homoiconic languages

Scheme has a define-macro special form that defines a source code transformation

7

(define-macro (twice expr) (list 'begin expr expr))

> (twice (print 2)) 2 2

Page 32: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Macros Perform Code Transformations

A macro is an operation performed on the source code of a program before evaluation

Macros exist in many languages, but are easiest to define correctly in homoiconic languages

Scheme has a define-macro special form that defines a source code transformation

7

(define-macro (twice expr) (list 'begin expr expr))

> (twice (print 2)) 2 2

Evaluation procedure of a macro call expression:

Page 33: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Macros Perform Code Transformations

A macro is an operation performed on the source code of a program before evaluation

Macros exist in many languages, but are easiest to define correctly in homoiconic languages

Scheme has a define-macro special form that defines a source code transformation

7

(define-macro (twice expr) (list 'begin expr expr))

> (twice (print 2)) 2 2

Evaluation procedure of a macro call expression:

• Evaluate the operator sub-expression, which evaluates to a macro

Page 34: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Macros Perform Code Transformations

A macro is an operation performed on the source code of a program before evaluation

Macros exist in many languages, but are easiest to define correctly in homoiconic languages

Scheme has a define-macro special form that defines a source code transformation

7

(define-macro (twice expr) (list 'begin expr expr))

> (twice (print 2)) 2 2

Evaluation procedure of a macro call expression:

• Evaluate the operator sub-expression, which evaluates to a macro

• Call the macro procedure on the operand expressions without evaluating them first

Page 35: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Macros Perform Code Transformations

A macro is an operation performed on the source code of a program before evaluation

Macros exist in many languages, but are easiest to define correctly in homoiconic languages

Scheme has a define-macro special form that defines a source code transformation

7

(define-macro (twice expr) (list 'begin expr expr))

> (twice (print 2)) 2 2

Evaluation procedure of a macro call expression:

• Evaluate the operator sub-expression, which evaluates to a macro

• Call the macro procedure on the operand expressions without evaluating them first

• Evaluate the expression returned from the macro procedure

Page 36: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Macros Perform Code Transformations

A macro is an operation performed on the source code of a program before evaluation

Macros exist in many languages, but are easiest to define correctly in homoiconic languages

Scheme has a define-macro special form that defines a source code transformation

7

(define-macro (twice expr) (list 'begin expr expr))

> (twice (print 2)) 2 2

Evaluation procedure of a macro call expression:

• Evaluate the operator sub-expression, which evaluates to a macro

• Call the macro procedure on the operand expressions without evaluating them first

• Evaluate the expression returned from the macro procedure

(Demo)

Page 37: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Problem 1

Define a macro that evaluates an expression for each value in a sequence

8

Page 38: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Problem 1

Define a macro that evaluates an expression for each value in a sequence

8

(define (map fn vals)

Page 39: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Problem 1

Define a macro that evaluates an expression for each value in a sequence

8

(define (map fn vals) (if (null? vals)

Page 40: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Problem 1

Define a macro that evaluates an expression for each value in a sequence

8

(define (map fn vals) (if (null? vals) ()

Page 41: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Problem 1

Define a macro that evaluates an expression for each value in a sequence

8

(define (map fn vals) (if (null? vals) () (cons (fn (car vals))

Page 42: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Problem 1

Define a macro that evaluates an expression for each value in a sequence

8

(define (map fn vals) (if (null? vals) () (cons (fn (car vals)) (map fn (cdr vals)))))

Page 43: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Problem 1

Define a macro that evaluates an expression for each value in a sequence

8

(define (map fn vals) (if (null? vals) () (cons (fn (car vals)) (map fn (cdr vals)))))

Page 44: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Problem 1

Define a macro that evaluates an expression for each value in a sequence

8

(define (map fn vals) (if (null? vals) () (cons (fn (car vals)) (map fn (cdr vals)))))

scm> (map (lambda (x) (* x x)) '(2 3 4 5))

Page 45: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Problem 1

Define a macro that evaluates an expression for each value in a sequence

8

(define (map fn vals) (if (null? vals) () (cons (fn (car vals)) (map fn (cdr vals)))))

scm> (map (lambda (x) (* x x)) '(2 3 4 5))(4 9 16 25)

Page 46: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Problem 1

Define a macro that evaluates an expression for each value in a sequence

8

(define (map fn vals) (if (null? vals) () (cons (fn (car vals)) (map fn (cdr vals)))))

scm> (map (lambda (x) (* x x)) '(2 3 4 5))(4 9 16 25)

scm> (for x (* x x) '(2 3 4 5)) (4 9 16 25)

Page 47: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Problem 1

Define a macro that evaluates an expression for each value in a sequence

8

(define (map fn vals) (if (null? vals) () (cons (fn (car vals)) (map fn (cdr vals)))))

scm> (map (lambda (x) (* x x)) '(2 3 4 5))(4 9 16 25)

scm> (for x (* x x) '(2 3 4 5)) (4 9 16 25)

(define-macro (for sym expr vals)

(list 'map _____________________________________________________________________________)

Page 48: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Problem 1

Define a macro that evaluates an expression for each value in a sequence

8

(define (map fn vals) (if (null? vals) () (cons (fn (car vals)) (map fn (cdr vals)))))

scm> (map (lambda (x) (* x x)) '(2 3 4 5))(4 9 16 25)

scm> (for x (* x x) '(2 3 4 5)) (4 9 16 25)

(define-macro (for sym expr vals)

(list 'map _____________________________________________________________________________)(list 'lambda (list sym) expr) vals)

Page 49: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Quasi-Quoting

(Demo)

Page 50: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Variable-Length Parameter Lists

(Demo)

Page 51: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Problem 2

Define a function nest that builds a nested list containing its arguments

11

Page 52: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Problem 2

Define a function nest that builds a nested list containing its arguments

11

(define (nest first . rest)

(if (null? rest)

________________________________________________________________

________________________________________________________________))

Page 53: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Problem 2

Define a function nest that builds a nested list containing its arguments

11

(define (nest first . rest)

(if (null? rest)

________________________________________________________________

________________________________________________________________))

scm> (nest 3) (3)

scm> (nest 3 4 5 6) (3 (4 (5 (6))))

Page 54: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Problem 2

Define a function nest that builds a nested list containing its arguments

11

(define (nest first . rest)

(if (null? rest)

________________________________________________________________

________________________________________________________________))

scm> (nest 3) (3)

scm> (nest 3 4 5 6) (3 (4 (5 (6))))

(list first)

Page 55: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Problem 2

Define a function nest that builds a nested list containing its arguments

11

(define (nest first . rest)

(if (null? rest)

________________________________________________________________

________________________________________________________________))

scm> (nest 3) (3)

scm> (nest 3 4 5 6) (3 (4 (5 (6))))

(list first)

(list first (apply nest rest))

Page 56: 61A Extra Lecture 8inst.eecs.berkeley.edu/~cs61a/fa15/assets/slides/e08-Macros_1pp.pdf · (Demo) The built-in Scheme list data structure (which is a linked list) can represent combinations

Temporary Symbols

(Demo)