CSC 160 Computer Programming for Non-Majors Lecture #3a: Stepper, Words, Sentences Prof. Adam M. Wittenstein

Slides:



Advertisements
Similar presentations
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Advertisements

Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
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
VBA Modules, Functions, Variables, and Constants
CSC 160 Computer Programming for Non-Majors Lecture #5c: Functions with Images Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #8: Animations I Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #1: What is Programming? 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 Lecture #11: Conditionals II Prof. Adam M. Wittenstein
CS100J 11 September 2003 Course Management System for CS100J is now populated with students who were pre-registered. Look at course web page to see how.
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
CSC 160 Computer Programming for Non-Majors Draft Chapter: The UFO Example Prof. Adam M. Wittenstein
Section 1.1: Flying a UFO (continued). Conversion recipe 1)Expand abbreviations 2)Parenthesize all subexpressions that have an operator. Should end up.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
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 Section 1.2: Drawing a UFO 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
Introduction to a Programming Environment
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
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 #6: Function Composition 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
1 Lecture 3  Lexical elements  Some operators:  /, %, =, +=, ++, --  precedence and associativity  #define  Readings: Chapter 2 Section 1 to 10.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
MJ3 Ch 1.2 – Variables, Expressions & Properties.
Comp. Eng. SW Lab II: FP with Scheme 1 Computer Eng. Software Lab II , Semester 2, Who I am: Andrew Davison CoE, WiG Lab Office.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
EXPRESSIONS AND ASSIGNMENT CITS1001. Scope of this lecture Assignment statements Expressions 2.
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
CSC 160 Computer Programming for Non-Majors Chapter 8: Scheme Language Review Prof. Adam M. Wittenstein
What does a computer program look like: a general overview.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
CPS120: Introduction to Computer Science Decision Making in Programs.
Introduction to Programming with RAPTOR
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter read appendix B (3 pages on DOS) and and.
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
Data And Variables Chapter Names vs. Values Michael Jordan name (the letter sequence used to refer to something) value (the thing itself)
MLA Formatting. MLA- What is it? MLA stands for the Modern Language Association Outlines standards to follow for parenthetical citations Allows us to.
CS 330 Programming Languages 11 / 15 / 2007 Instructor: Michael Eckmann.
Computer Eng. Software Lab II , Semester 2, Who I am: Andrew Davison CoE, WiG Lab Office Functional Programming.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
More Selections BIS1523 – Lecture 9.
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 12/25/2018.
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.
Chapter 5 Decisions.
Lecture 3: Rules of Evaluation CS200: Computer Science
Modern Programming Languages Lecture 18 Fakhar Lodhi
Introduction to the Lab
Presentation transcript:

CSC 160 Computer Programming for Non-Majors Lecture #3a: Stepper, Words, Sentences Prof. Adam M. Wittenstein

A preview… Last time we called numeric functions, like +, -, *, /, and sqrt. Today, we will see that Scheme treats other types of data, like words and sentences, in the same way that it treats numbers. Again, we have not learned how to define our own functions yet, we will just call predefined functions today, knowing that user-defined functions are called in exactly the same way.

I. The Stepper

Using the stepper If you are not getting the answers that you expect, then use DrScheme’s Stepper tool. You need to change the “language” to How to Design Programs Beginner Student. It shows you how a complex expression is evaluated, step-by-step. For example, take the expression (+ 2 (* 3 4)) Just as with PEMDAS, DrScheme must evaluate the (* 3 4) expression first to get 12. Then, it can evaluate (+ 2 12) to get 14.

Using the stepper To use the Stepper tool, put the expression(s) you want to evaluate into DrScheme's top area, the definitions window, then click the Step button:

Using the stepper Click next and you will get the answer of 14.

Example 2: Name the little people From page 35 in the Simply Scheme textbook, (+ (* 3 (sqrt 49) (/ 12 4))) First write it on several lines, (+ (* 3 (sqrt 49) (/ 12 4) ) ) ;Error: You cannot add a single number.

Example 3: Name the little people Similar to page 35 in the Simply Scheme textbook, (+ (* 3 (sqrt 49) (/ 12 4) 1)) Then assign names, (+ Adam (* 3Brian (sqrt 49)Christina (/ 12 4)Dawn ) 1)

Example 3: The little people get to work Christina: (sqrt 49) = 7 Dawn: (/ 12 4) = 3 Brian: (* 3 7 3) = 63 Adam: (+ 63 1) = 64

Example 4: Step through an expression Expression:(- ( + 5 8) (+ 2 4)) Step 1 (Bernie):(- 13 (+ 2 4)) Step 2 (Cordelia):(- 13 6) Step 3 (Alice):7

II. The “Quote” Function

Example 1: quote To print out a word, use the quote function. For example, (quote square) should return SQUARE. What will (quote (class on thursday)) return?

Example 1: quote To print out a word, use the quote function. For example, (quote square) should return square. What will (quote (class on thursday)) return? It returns class on thursday. An abbreviation: (quote square) can also be written as ‘square.

Why bother with quoting? While it seems nonsensical here, its actually common in English. For example, compare the following: -- a book is a bunch of pieces of paper. -- “a book” is an article and a noun Also, compare the following: is “2+3” is an arithmetic expression.

Why bother with quoting? When you see words inside quotation marks, think about the word itself, rather than its meaning. When the word is not in quotation marks, think about its actual meaning. This difference between a thing and its name is fundamental to computer programming.

III. Selector and Constructor Functions

Example 2: Last Week’s Functions Using the previous notes and readings: Calling a Selector Function Type something that takes the word hello and returns the first letter. Calling a Constructor Function Type something that takes two parts of a sentence and puts them together.

Example 3: Two “first” functions First returns the first letter of a word. For example, (first ‘because) = b. First also returns the first word in a sentence. For example, (first ‘(because)) = because. Notice the use of a ‘ and ( ) for a sentence.

Example 4: The “item” functions Just as with the first function, it works in two ways: 1) Nth letter in a word: (item 4 ‘Thursday) = R 2) Nth word in a sentence: (item 4 ‘(Today is Thursday September Seven)) = SEPTEMBER

Example 5: The sentence function There is one sentence function that takes just words, just sentences, or a combination of both and turns them into a sentence. Example of just words: (sentence ‘carry ‘that ‘weight) = (carry that weight)

Example 5: The sentence function Example of just sentences: (sentence ‘(john paul) ‘(george ringo)) = (john paul george ringo) Example of combining words & sentences: (sentence ‘(Today is Thursday) ‘the ‘seventh) = (Today is Thursday the seventh)

IV. First-Class Words and Sentences

In other programming languages… A word is a collection of letters and punctuation. A sentence is a collection of letters, punctuation, and spaces. Programmers call both of these strings. Scheme (and almost every other programming language) have such data types as numbers, strings, and booleans. However, we are actually using the Simply Scheme language, which is the Scheme language with some additions, like the data types for words and sentences.

What are objects? An object is a specific instance of a data type. Some objects of type number are: 5, -3, 4.7, ½. The only objects of type boolean are: true and false. Some objects of type word are: ‘hello & ‘a. Some objects of type sentence are: ‘(because) & ‘(Computers are fun!).

How can objects be used? In programming, a specific object can: 1)Be an argument to a function (also called procedure). For example, in (sqrt 49), the function is sqrt and the argument is our specific object, 49. 2)Be the value returned by a function. For example, (sqrt 49) returns the specific object called 7. 3)Be given a name. (We will see how in a few weeks.) 4)On compound data. (We will hopefully get to this at the end of the semester.)

Be very careful with punctuation We have defined the symbol ‘ as an abbreviation for quote. Scheme (and Simply Scheme) treats some English language punctuation the same way it would treat the letter g or the digit 5. However, some English language punctuation is also used as Scheme punctuation like ‘ and ( ). To avoid problems, we do not use any of this “overlapping punctuation”, even when using functions like word and sentence that apply to the English language.

V. Preparing for Next Time

A word of caution… Unless otherwise noted, we will use the Simply Scheme “language”. When using the Stepper though, we switch to the Beginner Student “language”. Two differences between these: -- A sentence is written with ‘(…) in Simply Scheme but “…” in Beginner Student. -- In Beginner Student, symbols correspond to words and strings correspond to sentences.

In summary… Today, we saw that functions are called the same way regardless of what type the data is. We also defined objects and listed the 4 ways they are used in programming. Next time… We will call functions involving pictures. We will see how to define variables (and time permitting, functions).

Reading assignments past due Online Textbook –Preface (the parts given in class on Tuesday 9/5) –Section 1 –Section 2 (through first subsection) Simply Scheme –Forward and Preface –Chapter 1 (through page 7) –Chapters 2, 3, and 5 *No new reading assignments for next time.