Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Learning Scheme Programming: Lecture 23, Study notes of Programming Paradigms

A part of a university lecture series on scheme programming. It includes announcements, a scheme scheme, quotes about scheme, an introduction to scheme fundamentals, special forms, and a discussion on counting trees and lambda expressions. It also covers pairs and lists, symbolic programming, and scheme lists and quotation.

What you will learn

  • How are pairs and lists used in Scheme?
  • What are the fundamental concepts of Scheme programming?
  • What are special forms in Scheme?

Typology: Study notes

2021/2022

Uploaded on 09/27/2022

laskhminaran
laskhminaran 🇺🇸

4.7

(6)

224 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
61A Lecture 23
Wednesday, October 30
Announcements
Homework 7 due Tuesday 11/5 @ 11:59pm.
Project 1 composition revisions due Thursday 11/7 @ 11:59pm.
Midterm 2 is graded.
(And yes, it was very challenging.)
Mean: 30
Solutions will be posted and exams distributed soon.
2
Scheme
http://imgs.xkcd.com/comics/lisp_cycles.png
Scheme is a Dialect of Lisp
What are people saying about Lisp?
"The greatest single programming language ever designed."
-Alan Kay, co-inventor of Smalltalk and OOP
"The only computer language that is beautiful."
-Neal Stephenson, DeNero's favorite sci-fi author
"God's programming language."
-Brian Harvey, Berkeley CS instructor extraordinaire
4
Scheme Fundamentals
Scheme programs consist of expressions, which can be:
Primitive expressions: 2, 3.3, true, +, quotient, ...
Combinations: (quotient 10 2), (not true), ...
Numbers are self-evaluating; symbols are bound to values.
Call expressions include an operator and 0 or more operands in parentheses.
(Demo)
5
> (quotient 10 2)
5
> (quotient (+ 8 7) 5)
3
> (+ (* 3
(+ (* 2 4)
(+ 3 5)))
(+ (- 10 7)
6))
“quotient” names Scheme’s
built-in integer division
procedure (i.e., function)
Combinations can span
multiple lines
(spacing doesn’t matter)
Special Forms
pf3

Partial preview of the text

Download Learning Scheme Programming: Lecture 23 and more Study notes Programming Paradigms in PDF only on Docsity!

61A Lecture 23

Wednesday, October 30

Announcements

  • Homework 7 due Tuesday 11/5 @ 11:59pm.
  • Project 1 composition revisions due Thursday 11/7 @ 11:59pm.
  • Midterm 2 is graded.  (^) (And yes, it was very challenging.)  Mean: 30  (^) Solutions will be posted and exams distributed soon. 2

Scheme

http://imgs.xkcd.com/comics/lisp_cycles.png

Scheme is a Dialect of Lisp

What are people saying about Lisp?

  • "The -Alan greatest Kay, co-inventor single programming of Smalltalk language and OOPever designed."
  • "The only computer language that is beautiful." -Neal Stephenson, DeNero's favorite sci-fi author
  • "God's programming language." -Brian Harvey, Berkeley CS instructor extraordinaire 4

Scheme Fundamentals

Scheme programs consist of expressions, which can be:

  • Primitive expressions: 2 , 3.3, true, +, quotient, ...
  • Combinations: (quotient 10 2), (not true), ... Numbers are self-evaluating; symbols are bound to values. Call expressions include an operator and 0 or more operands in parentheses. (Demo) 5

5 (quotient 10 2) (quotient (+ 8 7) 5) (^3) > (+ (* 3 (+ (* (+ 23 4)5))) (+ (- 6)) 10 7) “quotient” built-in integer names Scheme’sdivision procedure (i.e., function) Combinations multiple linescan span (spacing doesn’t matter)

Special Forms

Special Forms

A combination that is not a call expression is a special form :

  • (^) If expression: (if ) - And and or : (and <e 1 > ... ), (or <e 1 > ... ) - Binding symbols: (define ) - New procedures: (define ( ) )

    (define pi 3.14) 6.28 (* pi 2) (define (abs x) (if (< (- xx) 0) x)) 3 (abs -3) The symbol “pi” global is bound frame to 3.14 in the A procedure is symbol created “abs” and bound to the 7 Evaluation : (1) predicate Evaluate expression. the (2) Evaluate either the alternative. consequent or (Demo)

Counting Trees

Example: Counting Binary Trees

so many trees exist 9 a long noun phrase a two word modifier some trees are balanced the other trees lean The structure of a sentence can be described by a tree. Each sub-tree is a constituent. W X Y Z (Demo) The number of trees over n leaves with k leaves in the left and n-k in the right is: (The number of trees with k leaves) * (The number of trees with n-k leaves)

Lambda Expressions

Lambda Expressions

Lambda expressions evaluate to anonymous procedures.

(lambda (<formal-parameters>) ) Two equivalent expressions: (define (plus4 x) (+ x 4)) (define plus4 (lambda (x) (+ x 4))) An operator can be a call expression too: ((lambda (x y z) (+ x y (square z))) 1 2 3) add-^ Evaluates x -&- y -&- z^^2 toprocedure^ the 11

Pairs and Lists