CSC 160 Computer Programming for Non-Majors Chapter 8: Scheme Language Review Prof. Adam M. Wittenstein

Slides:



Advertisements
Similar presentations
Clauses: Building Blocks for Sentences
Advertisements

Telecooperation/RBG Technische Universität Darmstadt Copyrighted material; for TUD student use only Introduction to Computer Science I Topic 4: Evaluation.
Chapter Two Symbolizing in Sentential Logic This chapter is a preliminary to the project of building a model of validity for sentential arguments. We.
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
Syntax. Definition: a set of rules that govern how words are combined to form longer strings of meaning meaning like sentences.
Clauses Building Blocks for Sentences Adapted by Algonquin College from content provided by Capital Community College and Professor Charles Darling.
Conditional statements and Boolean expressions. The if-statement in Java (1) The if-statement is a conditional statement The statement is executed only.
Grammars.
CSC 160 Computer Programming for Non-Majors Lecture #3a: Stepper, Words, Sentences (continued) Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #9: Booleans Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #4: Defining Variables Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #5: Defining Functions Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Chapter 2: Numbers, Expressions, and Simple Programs Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Chapter 6: Structures Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Introduction Prof. Adam M. Wittenstein
© 2006 Pearson Addison-Wesley. All rights reserved6-1 Chapter 6 Recursion as a Problem- Solving Technique.
CSC 160 Computer Programming for Non-Majors Lecture #3: Calling Functions Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #3c: Working with Pictures (continued) Prof. Adam M. Wittenstein
Section 4.3: Conditions and Conditional Functions.
CSC 160 Computer Programming for Non-Majors Lecture #10: Conditionals I Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Introduction Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Chapter 4: Conditional Expressions and Functions Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #5b: Designing Programs Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #7: Variables Revisited Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Chapter 3: Programs are Functions Plus Variable Definitions Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #2: What are Functions? Prof. Adam M. Wittenstein
Introduction to C Programming
CSC 160 Computer Programming for Non-Majors Lecture #3a: Stepper, Words, Sentences Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #5a: Defining Functions on Words and Sentences Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #3b: Working with Pictures Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #5 (continued): More on Writing Functions Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #12: Syntax and Semantics Prof. Adam M. Wittenstein
Exam 3 Material Formulas, Proportions, Linear Inequalities
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
Grammars.
Punctuations.
Dr. Monira Al-Mohizea MORPHOLOGY & SYNTAX WEEK 11.
1. Sentences and clauses. Starting assumption The following presentation assumes that you have a basic idea about what the following grammar terms mean:
The Language of Math Punctuation. Punctuation is used in English and other languages to give meaning to what is written. Periods and question marks end.
The Language of Mathematics Basic Grammar. A word to the wise The purpose of this tutorial is to get you to understand what equations and inequalities.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Chapter Four In the Community.
Chapter 1 Section 1.1 Objective: to write algebraic expressions.
Introduction to programming in the Java programming language.
Copyright © Curt Hill Languages and Grammars This is not English Class. But there is a resemblance.
Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions.
EXPRESSIONS. Vocabulary A variable is a symbol, usually a letter, used to represent a number. –Example: 4x (x is the variable) A coefficient is the number.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Functional Programming Language 1 Scheme Language: part 2.
Chapter 1 Section 3. Objectives 1 Copyright © 2012, 2008, 2004 Pearson Education, Inc. Evaluate algebraic expressions, given values for the variables.
Writing Basics. Things you should already know… 0 You should always write an essay in blue or blank ink – the only exception to this is writing with a.
Java Programming Fifth Edition Chapter 5 Making Decisions.
Chapter 5: Making Decisions. Objectives Plan decision-making logic Make decisions with the if and if…else structures Use multiple statements in if and.
Chapter 1: Variables in Algebra
VARIABLES AND EXPRESSIONS. Definitions: Algebra – Is a language of symbols, including variables. Variable - Is a letter or symbol that represents a quantity.
Functional Programming Language 1 Scheme Language: part 3.
1 Sections 3.1 – 3.2a Basic Syntax and Semantics Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Part # 1: Due October 10th Part # 2: Due January 16th
Variables and Expressions
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Four Types of Sentences
Variables and Primative Types
L1-6 Notes: Algebra: Variables and Expressions
Writing Complex Sentences
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 2/23/2019.
Let's Play "What's the Question"
Chapter 1 Section 3.
Learn to identify and evaluate expressions.
Key Stage 1 Grammar.
Presentation transcript:

CSC 160 Computer Programming for Non-Majors Chapter 8: Scheme Language Review Prof. Adam M. Wittenstein

REVIEW: Vocabulary of Languages English languageProgramming language Verb (action) go, eat, buy, give Function +, string-append, under-21?, distance Proper noun (specific thing) Adelphi, Adam, Rover Literal 3, “hello there”, true, (make-posn 3 4) Pronoun (thing in context) him, her, it Variable x, greeting, age, a-posn Improper noun (kind of thing) college, professor, dog, picture Data type number, string, image, boolean, posn Noun phrase (specific thing, not by name) Adam’s mother Expression (+ 3 (* 4 5)), (cube 7)

Syntax of the English Language --Start each sentence with a capital letter. --End each sentence with a period. --Include at least one noun in a sentence. --Include at least one verb in a sentence. --Etc.

Syntax of the Scheme Language --Calling a function (function-name argument[s]) --Defining a variable (define VAR-NAME value) --Defining a function (define (function-name param-name[s]) …body including param-name[s]…) --Conditional Expressions (cond [question…answer] [question…answer]) --That’s it!

Similarities of English and Scheme They both share the characteristics of language: --They have vocabulary and syntax. In English, syntax is called grammar. --They both have phrases. In Scheme, they are called expressions. --They both have sentences. In Scheme, they are called functions.

Similarities of English and Scheme They both have simple data: numbers, words (in Scheme, symbols), etc. They both have compound data: social security records, shopping, lists, etc. (We only had a brief taste with compound data this semester, in studying Posns.)

Similarities of English and Scheme They both have meaningful sentences. --English: The sky is blue. --Scheme: (define (square num) (* num num)) They both have meaningless sentences. --English: The brick is a car. --Scheme: (define (sum x y) (- x y))

Section 8.1: Scheme Vocabulary

Scheme’s Vocabulary Scheme's basic vocabulary consists of five categories of words: --literals (often called constants) --variables --data types --expressions --functions (predefined functions are often called primitives)

Scheme’s punctuation In English, we have periods, commas, colons, semicolons, etc. In Scheme, the punctuation consists of: --parentheses (one for every function call) --keywords (define, draw, produce, else, cond)

Section 8.2: Scheme Grammar

Scheme’s Grammar It is well known that English has a more complicated grammar than most spoken languages (e.g. Spanish, French, etc.) However, Scheme has a far simpler grammar than most programming languages. In fact, you have gone through a whole semester using only 4 syntax rules. (Most of us used 4 grammar rules in English before we finished preschool.)

Syntax Rule #3: Defining Functions A function definition is formed by: --Using ( --Followed by the keyword define --Followed by another ( --Followed by a non-empty sequence of variables, the first being the function’s name, and the rest being the parameter’s name[s]. --Followed by `) --Followed by an expression --And closed by a )' that matches the very first one. The keyword define distinguishes functions definitions from expressions (function calls).

Types of Expressions Literals: 5, “blue”, true, etc. Variables: ORIGIN, PI, etc. Calling primitive functions: (+ 3 4), etc. Calling defined functions: (cube 5), etc. Conditionals without an else clause Conditionals with an else clause

These are not expressions. Why not? (f define) (cond x) ()

These are not expressions. Why not? (f define) Although it partially matches the shape of a function application but it uses define as if it were a variable. (cond x) ()

These are not expressions. Why not? (f define) Although it partially matches the shape of a function application but it uses define as if it were a variable. (cond x) it contains a variable as the second item and not a pair of expressions (question and answer) surrounded by brackets ()

These are not expressions. Why not? (f define) Although it partially matches the shape of a function application but it uses define as if it were a variable. (cond x) it contains a variable as the second item and not a pair of expressions (question and answer) surrounded by brackets () there must be the same number of pairs of parentheses as functions, so since there are no functions, there cannot be any parentheses

Lab #6 Complete exercises and from the textbook on paper. Complete exercises and from the textbook on paper.

Exercise Solution (x) (+ 1 (not x)) ( )

Exercise Solution (x) ILLEGAL, sets of parentheses = 1 and number of functions = 0 (+ 1 (not x)) ( )

Exercise Solution (x) ILLEGAL, sets of parentheses = 1 and number of functions = 0 (+ 1 (not x)) ILLEGAL, the addition operator requires two numbers, but it is given a number 1 and a boolean (not x). ( )

Exercise Solution (x) ILLEGAL, sets of parentheses = 1 and number of functions = 0 (+ 1 (not x)) ILLEGAL, the addition operator requires two numbers, but it is given a number 1 and a boolean (not x). ( ) LEGAL, sets of parentheses= 1 and number of functions = 1. Also, follows the contract of +.

Exercise Solution (define (f x) 'x) (define (f 'x) x) (define (f x y) (+ 'y (not x)))

Exercise Solution (define (f x) 'x) LEGAL, it has a header, body, and a right parenthesis at the end. (define (f 'x) x) (define (f x y) (+ 'y (not x)))

Exercise Solution (define (f x) 'x) LEGAL, it has a header, body, and a right parenthesis at the end. (define (f 'x) x) ILLEGAL, a constant like ‘x cannot be in the header (define (f x y) (+ 'y (not x)))

Exercise Solution (define (f x) 'x) LEGAL, it has a header, body, and a right parenthesis at the end. (define (f 'x) x) ILLEGAL, a constant like ‘x cannot be in the header (define (f x y) (+ 'y (not x))) ILLEGAL, parameter names do not have their own set of parentheses

In conclusion… Although any language, whether its English, Spanish, or Scheme has its rules to contend with, believe or not, we have avoided having to learn the many rules that ordinary programming languages require. You have only had to learn FOUR rules the entire semester, compared with the tens, if not hundreds, of rules required in a first semester collegiate Java or C++ course. The essence of what I tried to convey during the course is two things: one, relating one quantity to another quantity, and two, evaluating a relationship by substituting values for names.

On computing… From elementary school to high school we learn to compute with one form of data: numbers. Computing with software is algebra for all kinds of data, not just numbers. Nowadays, computer programs process representations of music, molecules, law cases, electrical diagrams, architectures of houses, and poems. In this book we have studied the laws of basic operations and the laws of operation combination. Because the computer is extremely fast and good at using these laws, it can perform such evaluations for more data and for larger programs than we can do with paper and pencil.

On Programming… Programs consist of definitions and expressions. Large programs consist of hundreds and thousands of definitions and expressions. Programmers design functions, use other programmer's functions, leave, start on the project. Without a strong discipline we cannot hope to produce software of high quality. The key to programming discipline is to understand the design of programs as a means to describe computations, which are the manipulate of data through combinations of operations.