From Scheme to Java. So far, we ve translated data definitions: ; A snake is ; (make-snake sym num sym) (define-struct snake (name weight food))
|
|
- Cora Heath
- 5 years ago
- Views:
Transcription
1 From Scheme to Java So far, we ve translated data definitions: ; A snake is ; (make-snake sym num sym) (define-struct snake (name weight food)) class Snake { String name; double weight; String food; Snake(String name, double weight, String food) { this.name = name; this.weight = weight; this.food = food; 1
2 Functions in Scheme ; A snake is ; (make-snake sym num sym) (define-struct snake (name weight food)) ; snake-lighter? : snake num -> bool ; Determines whether s is < n lbs (define (snake-lighter? s n) (< (snake-weight s) n)) (snake-lighter? (make-snake Slinky 10 rats) 10) (snake-lighter? (make-snake Slimey 5 grass) 10) 2
3 Functions in Java class Snake { String name; double weight; String food; Snake(String name, double weight, String food) { this.name = name; this.weight = weight; this.food = food; // Determines whether it s < n lbs return this.weight < n; new Snake("Slinky", 10, "rats").islighter(10) 3
4 Functions in Java class Snake { String name; double weight; String food; Snake(String name, double weight, String food) { this.name = name; this.weight = weight; A function this.food = food; becomes a method that is in the class // Determines whether it s < n lbs return this.weight < n; new Snake("Slinky", 10, "rats").islighter(10) 4
5 Methods in Java Comparing just the function and method: ; snake-lighter? : snake num -> bool ; Determines whether s is < n lbs (define (snake-lighter? s n) (< (snake-weight s) n)) // Determines whether it s < n lbs return this.weight < n; 5
6 Methods in Java Comparing just the function and method: ; snake-lighter? : snake num -> bool ; Determines whether s is < n lbs (define (snake-lighter? A method s n) in (< (snake-weight s) Snake n)) has an implicit Snake this // Determines whether argument it s < n lbs return this.weight < n; 6
7 Methods in Java Comparing just the function and method: ; snake-lighter? : snake num -> bool All other ; Determines whether s is < n lbs arguments are (define (snake-lighter? s n) explicit, and the (< (snake-weight s) n)) type is next to the name, as in double n // Determines whether it s < n lbs return this.weight < n; 7
8 Methods in Java Comparing just the function and method: ; snake-lighter? : snake num -> bool ; Determines whether s is < n lbs (define (snake-lighter? s n) (< (snake-weight s) n)) The result type is boolean // Determines whether it s < n lbs return this.weight < n; 8
9 Methods in Java Comparing just the function and method: ; snake-lighter? : snake num -> bool Since ; Determines the method takes whether a Snake s is < n lbs and (define double (snake-lighter? and produces a s n) boolean, (< (snake-weight the contract is s) n)) Snake double -> boolean and we don t write it as a comment // Determines whether it s < n lbs return this.weight < n; 9
10 Methods in Java Comparing just the function and method: ; snake-lighter? : snake num -> bool ; Determines whether s is < n lbs (define (snake-lighter? s n) Purpose comment is as (< (snake-weight in Scheme, s) n)) but comments start with // // Determines whether it s < n lbs return this.weight < n; 10
11 Methods in Java Comparing just the function and method: ; snake-lighter? : snake num -> bool ; Determines whether s is < n lbs (define (snake-lighter? s n) (< (snake-weight s) Instead n)) of (snake-weight s) use // Determines whether this.weight it s < n lbs return this.weight < n; 11
12 Methods in Java Comparing just the function and method: ; snake-lighter? : snake num -> bool ; Determines whether s is < n lbs (define (snake-lighter? s n) (< (snake-weight s) n)) Explicitly designate the result with // Determines returnwhether it s < n lbs return this.weight < n; 12
13 Inside the class declaration... Methods in Java, Step-by-Step // Determines whether it s < n lbs return this.weight < n; 13
14 Methods in Java, Step-by-Step Inside the class declaration... // Determines whether it s < n lbs return First this.weight the purpose, starting < n; with // 14
15 Inside the class declaration... Methods in Java, Step-by-Step // Determines whether it s < n lbs return this.weight < n; Then the result type 15
16 Inside the class declaration... Methods in Java, Step-by-Step // Determines whether it s < n lbs return this.weight < n; Then the method name (not capitalized, by convention) 16
17 Inside the class declaration... Methods in Java, Step-by-Step // Determines whether it s < n lbs return this.weight < n; Start arguments with ( 17
18 Inside the class declaration... Methods in Java, Step-by-Step // Determines whether it s < n lbs return this.weight < n; Arguments except for this use a type for each argument, and separate multiple arguments with, 18
19 Inside the class declaration... Methods in Java, Step-by-Step // Determines whether it s < n lbs return this.weight < n; End arguments with ) 19
20 Inside the class declaration... Methods in Java, Step-by-Step // Determines whether it s < n lbs return this.weight < n; Then a { 20
21 Inside the class declaration... Methods in Java, Step-by-Step // Determines whether it s < n lbs return this.weight < n; Body using Java notation, put return before a result 21
22 Inside the class declaration... Methods in Java, Step-by-Step // Determines whether it s < n lbs return this.weight < n; Put ; after a result 22
23 Inside the class declaration... Methods in Java, Step-by-Step // Determines whether it s < n lbs return this.weight < n; End with 23
24 Method Calls in Java Original tests: (snake-lighter? (make-snake Slinky 10 rats) 10) new Snake("Slinky", 10, "rats").islighter(10) 24
25 Method Calls in Java Equivalent, using constant definitions: (define SLINKY (make-snake Slinky 10 rats)) (snake-lighter? SLINKY 10) Snake slinky = new Snake("Slinky", 10, "rats"); slinky.islighter(10) 25
26 Method Calls in Java Equivalent, using constant definitions: (define SLINKY (make-snake Slinky 10 rats)) (snake-lighter? SLINKY 10) Snake slinky = new Snake("Slinky", 10, "rats"); Constant definition starts with the constant s type slinky.islighter(10) 26
27 Method Calls in Java Equivalent, using constant definitions: (define SLINKY (make-snake Slinky 10 rats)) (snake-lighter? SLINKY 10) Snake slinky = new Snake("Slinky", 10, "rats"); slinky.islighter(10) Then the name 27
28 Method Calls in Java Equivalent, using constant definitions: (define SLINKY (make-snake Slinky 10 rats)) (snake-lighter? SLINKY 10) Snake slinky = new Snake("Slinky", 10, "rats"); slinky.islighter(10) Then = 28
29 Method Calls in Java Equivalent, using constant definitions: (define SLINKY (make-snake Slinky 10 rats)) (snake-lighter? SLINKY 10) Snake slinky = new Snake("Slinky", 10, "rats"); Then an slinky.islighter(10) "should be" expression false 29
30 Method Calls in Java Equivalent, using constant definitions: (define SLINKY (make-snake Slinky 10 rats)) (snake-lighter? SLINKY 10) Snake slinky = new Snake("Slinky", 10, "rats"); slinky.islighter(10) End with ; 30
31 Method Calls in Java Equivalent, using constant definitions: (define SLINKY (make-snake Slinky 10 rats)) (snake-lighter? SLINKY 10) Snake slinky = new Snake("Slinky", 10, "rats"); slinky.islighter(10) Method call starts with an expression for the implicit this argument 31
32 Method Calls in Java Equivalent, using constant definitions: (define SLINKY (make-snake Slinky 10 rats)) (snake-lighter? SLINKY 10) Snake slinky = new Snake("Slinky", 10, "rats"); slinky.islighter(10) Then. 32
33 Method Calls in Java Equivalent, using constant definitions: (define SLINKY (make-snake Slinky 10 rats)) (snake-lighter? SLINKY 10) Snake slinky = new Snake("Slinky", 10, "rats"); slinky.islighter(10) Then the method name 33
34 Method Calls in Java Equivalent, using constant definitions: (define SLINKY (make-snake Slinky 10 rats)) (snake-lighter? SLINKY 10) Snake slinky = new Snake("Slinky", 10, "rats"); slinky.islighter(10) Then ( 34
35 Method Calls in Java Equivalent, using constant definitions: (define SLINKY (make-snake Slinky 10 rats)) (snake-lighter? SLINKY 10) Snake slinky = new Snake("Slinky", 10, "rats"); slinky.islighter(10) Then expressions for the explicit arguments separated by, 35
36 Method Calls in Java Equivalent, using constant definitions: (define SLINKY (make-snake Slinky 10 rats)) (snake-lighter? SLINKY 10) Snake slinky = new Snake("Slinky", 10, "rats"); slinky.islighter(10) Then ) 36
37 Templates In ; A snake is ; (make-snake sym num sym) (define-struct snake (name weight food)) ; func-for-snake : snake ->... (define (func-for-snake s)... (snake-name s)... (snake-weight s)... (snake-food s)...) 37
38 Templates Same idea works for class Snake { String name; double weight; String food; Snake(String name, double weight, String food) { this.name = name; this.weight = weight; this.food = food;... methodforsnake(...) {... this.name... this.weight... this.food... 38
39 More Examples Implement a feed method for Snake which takes an amount of food in pounds and produces a fatter snake Implement a feed method for Dillo and Ant Implement a feed method for Animal 39
40 Lists in Java Translate the list-of-num data definition to Java and implement a length method 40
Functions in Scheme. From Scheme to Java. Functions in Java. Functions in Java. method that is in the class // Determines whether it s < n lbs
From Scheme to Java So far, we ve translated data definitions: ; A snake is ; (make-snake sym num sym) (define-struct snake (name weight food)) class Snake { String name; double weight; String food; Snake(String
More informationClass Diagrams Nesting Variants to Refine Contracts Common Functionality in Abstract Classes Nesting without Abstract
Class Diagrams Nesting Variants to Refine Contracts Common Functionality in Abstract Classes Nesting without Abstract 1 Animal Classes Animal boolean islighter(double) boolean islight() Snake String name
More informationAnimal Classes. Door Classes. Some Maze Classes. Class Diagrams. Nesting Variants to Refine Contracts. Common Functionality in Abstract Classes
Animal Classes Class Diagrams Nesting Variants to Refine Contracts Common Functionality in Abstract Classes Animal boolean islight() Nesting without Abstract Snake String food boolean likesfood(string)
More informationFrom FP to OOP. Start with data: class Posn { int x; int y; Posn(int x, int y) { this.x = x; this.y = y; } }
From FP to OOP Start with data: ; A posn is ; (make-posn num num) (define-struct posn (x y)) class Posn { int x; int y; Posn(int x, int y) { this.x = x; this.y = y; 1 From FP to OOP Start with data: ;
More informationIntroduction to Typed Racket. The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples
Introduction to Typed Racket The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples Getting started Find a machine with DrRacket installed (e.g. the
More informationWednesday, November 5
Possible Date Change for Mid-Term 2 Can we shift Mid-Term 2 to Wednesday, November 5 instead of Friday, November 7? 1 Outline Encapsulation and Objects Vectors and Identity 2 Encapsulation Two lectures
More informationLoops in Scheme, II. (early slides assume map/filter)
Loops in Scheme, II (early slides assume map/filter) c. Kathi Fisler, 2001 Recap: filter and map filter and map are Scheme s loops filter : (α! boolean) list[α]! list[α] extract list of elts that satisfy
More informationTracking Rumors. Suppose that we want to track gossip in a rumor mill
Tracking Rumors Suppose that we want to track gossip in a rumor mill 1 Tracking Rumors Suppose that we want to track gossip in a rumor mill Seiichi 2 Tracking Rumors Suppose that we want to track gossip
More informationObjec,ves. Review: Object-Oriented Programming. Object-oriented programming in Java. What is OO programming? Benefits?
Objec,ves Object-oriented programming in Java Ø Encapsula,on Ø Access modifiers Ø Using others classes Ø Defining own classes Sept 16, 2016 Sprenkle - CSCI209 1 Review: Object-Oriented Programming What
More informationObject Oriented Programming in C#
Introduction to Object Oriented Programming in C# Class and Object 1 You will be able to: Objectives 1. Write a simple class definition in C#. 2. Control access to the methods and data in a class. 3. Create
More informationFunctional abstraction. What is abstraction? Eating apples. Readings: HtDP, sections Language level: Intermediate Student With Lambda
Functional abstraction Readings: HtDP, sections 19-24. Language level: Intermediate Student With Lambda different order used in lecture section 24 material introduced much earlier sections 22, 23 not covered
More informationFunctional abstraction
Functional abstraction Readings: HtDP, sections 19-24. Language level: Intermediate Student With Lambda different order used in lecture section 24 material introduced much earlier sections 22, 23 not covered
More informationChapter 20: Binary Trees
Chapter 20: Binary Trees 20.1 Definition and Application of Binary Trees Definition and Application of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two other
More informationormap, andmap, and filter
ormap, andmap, and filter CS 5010 Program Design Paradigms Bootcamp Lesson 6.3 Mitchell Wand, 2012-2015 This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
More informationHow to Design Programs
How to Design Programs How to (in Racket): represent data variants trees and lists write functions that process the data See also http://www.htdp.org/ 1 Running Example: GUIs Pick a fruit: Apple Banana
More informationWhy OO programming? want but aren t. Ø What are its components?
9/21/15 Objec,ves Assign 1 Discussion Object- oriented programming in Java Java Conven,ons: Ø Constructors Ø Default constructors Ø Sta,c methods, variables Ø Inherited methods Ø Class names: begin with
More informationCSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2017 Lecture 8 C: Miscellanea Control, Declarations, Preprocessor, printf/scanf 1 The story so far The low-level execution model of a process (one
More informationThe Design Recipe Fall 2017
CS17 Integrated Introduction to Computer Science Hughes The Design Recipe Fall 2017 Contents 1 Design Recipe Steps 1 2 An OCaml Example 6 1 Design Recipe Steps This PDF outlines the steps to writing the
More informationLists. Readings: HtDP, sections 9 and 10. Avoid 10.3 (uses draw.ss). CS 135 Winter : Lists 1
Lists Readings: HtDP, sections 9 and 10. Avoid 10.3 (uses draw.ss). CS 135 Winter 2018 05: Lists 1 Introducing lists Structures are useful for representing a fixed amount of data. But there are many circumstances
More informationFRAC: Language Reference Manual
FRAC: Language Reference Manual Justin Chiang jc4127 Kunal Kamath kak2211 Calvin Li ctl2124 Anne Zhang az2350 1. Introduction FRAC is a domain-specific programming language that enables the programmer
More informationCS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University
9/5/6 CS Introduction to Computing II Wayne Snyder Department Boston University Today: Arrays (D and D) Methods Program structure Fields vs local variables Next time: Program structure continued: Classes
More informationGraphs. Directed graphs. Readings: Section 28
Graphs Readings: Section 28 CS 135 Winter 2018 12: Graphs 1 Directed graphs A directed graph consists of a collection of vertices (also called nodes) together with a collection of edges. An edge is an
More informationClasses. Logical method to organise data and functions in a same structure. Also known as abstract data type (ADT).
UNITII Classes Logical method to organise data and functions in a same structure. Also known as abstract data type (ADT). It s a User Defined Data-type. The Data declared in a Class are called Data- Members
More informationOutline. Helper Functions and Reuse. Conditionals. Evaluation Rules for cond. Design Recipe with cond. Compound Data
Outline Helper Functions and Reuse Conditionals Evaluation Rules for cond Design Recipe with cond Compound Data 1 Designing Programs Design recipe As outlined last lecture 2 Designing Programs Design recipe
More informationChapter 2: Using Data
Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that
More informationGraphs. Readings: Section 28. CS 135 Fall : Graphs 1
Graphs Readings: Section 28 CS 135 Fall 2018 12: Graphs 1 Directed graphs A directed graph consists of a collection of vertices (also called nodes) together with a collection of edges. An edge is an ordered
More informationCS111: PROGRAMMING LANGUAGE II
CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1(c): Java Basics (II) Lecture Contents Java basics (part II) Conditions Loops Methods Conditions & Branching Conditional Statements A
More information3. Java - Language Constructs I
Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks
More informationModule 5: Lists. Readings: HtDP, Sections 9, 10.
Module 5: Lists Readings: HtDP, Sections 9, 10. Lists are the main tool used in Racket to work with unbounded data. As with conditional expressions and structures, the data definition for lists leads naturally
More informationThe Design Recipe Fall 2018
CS17 Integrated Introduction to Computer Science Klein The Design Recipe Fall 2018 Contents 1 Design Recipe Steps 1 2 Another Racket Example 6 3 An OCaml Example 6 4 Another OCaml Example 8 1 Design Recipe
More informationCOMP520 - GoLite Type Checking Specification
COMP520 - GoLite Type Checking Specification Vincent Foley March 5, 2017 1 Introduction This document presents the typing rules for all the language constructs (i.e. declarations, statements, expressions)
More informationOutline. Data Definitions and Templates Syntax and Semantics Defensive Programming
Outline Data Definitions and Templates Syntax and Semantics Defensive Programming 1 Data Definitions Question 1: Are both of the following data definitions ok? ; A w-grade is either ; - num ; - posn ;
More informationModule 3: New types of data
Module 3: New types of data Readings: Sections 4 and 5 of HtDP. A Racket program applies functions to values to compute new values. These new values may in turn be supplied as arguments to other functions.
More informationConversions and Overloading : Overloading
Conversions and Overloading : First. Java allows certain implicit conversations of a value of one type to a value of another type. Implicit conversations involve only the primitive types. For example,
More informationClass Hierarchy and Interfaces. David Greenstein Monta Vista High School
Class Hierarchy and Interfaces David Greenstein Monta Vista High School Inheritance Inheritance represents the IS-A relationship between objects. an object of a subclass IS-A(n) object of the superclass
More informationVisual C# Instructor s Manual Table of Contents
Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms
More informationProgramming with Math and Logic
.. Programming with Math and Logic an invitation to functional programming Ed Morehouse Wesleyan University The Plan why fp? terms types interfaces The What and Why of Functional Programming Computing
More informationBasic Object-Oriented Concepts. 5-Oct-17
Basic Object-Oriented Concepts 5-Oct-17 Concept: An object has behaviors In old style programming, you had: data, which was completely passive functions, which could manipulate any data An object contains
More informationCSSE 220. Interfaces and Polymorphism. Check out Interfaces from SVN
CSSE 220 Interfaces and Polymorphism Check out Interfaces from SVN Interfaces What, When, Why, How? What: Code Structure used to express operations that multiple class have in common No method implementations
More informationThe design recipe. Readings: HtDP, sections 1-5. (ordering of topics is different in lectures, different examples will be used)
The design recipe Readings: HtDP, sections 1-5 (ordering of topics is different in lectures, different examples will be used) Survival and Style Guides CS 135 Winter 2018 02: The design recipe 1 Programs
More informationJustification for Names and Optional Parameters
Justification for Names and Optional Parameters By Bill Wagner March 2012 Many developers ask why named and optional parameters were not added earlier to the C# language. As other languages have shown,
More informationEnums. In this article from my free Java 8 course, I will talk about the enum. Enums are constant values that can never be changed.
Enums Introduction In this article from my free Java 8 course, I will talk about the enum. Enums are constant values that can never be changed. The Final Tag To display why this is useful, I m going to
More informationPIC 20A The Basics of Java
PIC 20A The Basics of Java Ernest Ryu UCLA Mathematics Last edited: November 1, 2017 Outline Variables Control structures classes Compilation final and static modifiers Arrays Examples: String, Math, and
More informationPrinciples of Object Oriented Programming. Lecture 4
Principles of Object Oriented Programming Lecture 4 Object-Oriented Programming There are several concepts underlying OOP: Abstract Types (Classes) Encapsulation (or Information Hiding) Polymorphism Inheritance
More informationA First Book of ANSI C Fourth Edition. Chapter 12 Structures
A First Book of ANSI C Fourth Edition Chapter 12 Structures Objectives Single Structures Arrays of Structures Passing and Returning Structures Unions (Optional) Common Programming and Compiler Errors A
More informationA Fast Review of C Essentials Part I
A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types
More information1B1b Classes in Java Part I
1B1b Classes in Java Part I Agenda Defining simple classes. Instance variables and methods. Objects. Object references. 1 2 Reading You should be reading: Part I chapters 6,9,10 And browsing: Part IV chapter
More informationHaskell Programs. Haskell Fundamentals. What are Types? Some Very Basic Types. Types are very important in Haskell:
Haskell Programs We re covering material from Chapters 1-2 (and maybe 3) of the textbook. Haskell Fundamentals Prof. Susan Older A Haskell program is a series of comments and definitions. Each comment
More informationCOMP520 - GoLite Type Checking Specification
COMP520 - GoLite Type Checking Specification Vincent Foley April 8, 2018 1 Introduction This document presents the typing rules for all the language constructs (i.e. declarations, statements, expressions)
More informationTopic 5: Higher Order Functions
Topic 5: Higher Order Functions 1 Recommended Exercises and Readings From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10,
More informationTopic 5: Higher Order Functions
Topic 5: Higher Order Functions 1 Recommended Exercises and Readings From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10,
More informationWeb Application Development
Web Application Development Produced by David Drohan (ddrohan@wit.ie) Department of Computing & Mathematics Waterford Institute of Technology http://www.wit.ie JavaScript JAVASCRIPT FUNDAMENTALS Agenda
More informationGOLD Language Reference Manual
GOLD Language Reference Manual Language Guru: Timothy E. Chung (tec2123) System Architect: Aidan Rivera (ar3441) Manager: Zeke Reyna (eer2138) Tester: Dennis Guzman (drg2156) October 16th, 2017 1 Introduction
More informationCOMP322 - Introduction to C++ Lecture 02 - Basics of C++
COMP322 - Introduction to C++ Lecture 02 - Basics of C++ School of Computer Science 16 January 2012 C++ basics - Arithmetic operators Where possible, C++ will automatically convert among the basic types.
More informationCS115 - Module 3 - Booleans, Conditionals, and Symbols
Fall 2017 Reminder: if you have not already, ensure you: Read How to Design Programs, sections 4-5 Booleans (Bool) , and = are new functions, each of which produces a boolean value (Bool). (< 4 6)
More informationCS115 - Module 8 - Binary trees
Fall 2017 Reminder: if you have not already, ensure you: Read How to Design Programs, Section 14. Binary arithmetic expressions Operators such as +,,, and take two arguments, so we call them binary operators.
More informationData Structures. Data structures. Data structures. What is a data structure? Simple answer: a collection of data equipped with some operations.
Data Structures 1 Data structures What is a data structure? Simple answer: a collection of data equipped with some operations. Examples Lists Strings... 2 Data structures In this course, we will learn
More informationCS115 - Module 4 - Compound data: structures
Fall 2017 Reminder: if you have not already, ensure you: Read How to Design Programs, sections 6-7, omitting 6.2, 6.6, 6.7, and 7.4. Compound data It often comes up that we wish to join several pieces
More information"Good" vs. "Bad" Expressions. ; interp-expr FAE... -> FAE-Value
"Good" vs. "Bad" Expressions ; interp-expr FAE... -> FAE-Value 1 "Good" vs. "Bad" Expressions ; interp-expr FAE... -> FAE-Value Does interp-expr produce a value for all expressions? 2 "Good" vs. "Bad"
More informationCS1102: What is a Programming Language?
CS1102: What is a Programming Language? Kathi Fisler, WPI September 13, 2007 1 The Design and Programming Perspectives To start to understand what comprises a programming language, let s consider sample
More informationUnit 4: Client View of a Component Methods
Unit 4: Client View of a Component Methods Preview of Coming Attractions In this unit be sure to look for method/operation parameters/formal parameters arguments/actual parameters method header/method
More informationCSE 431S Type Checking. Washington University Spring 2013
CSE 431S Type Checking Washington University Spring 2013 Type Checking When are types checked? Statically at compile time Compiler does type checking during compilation Ideally eliminate runtime checks
More informationPreliminaries. Part I
Part I Preliminaries Chapters 1 through 4 present an introduction to C++ that provides the basis for understanding the rest of the material in this book. This part also provides professional programmers
More information1d: tests knowing about bitwise fields and union/struct differences.
Question 1 1a: char ptr[] = Hello World ; char a = ptr[1], b = *(ptr+6); Creates an array of 12 elements, 11 visible letters and a character value 0 at the end. i true ii true iii false iv false v true
More informationFull file at
Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional
More informationClasses, Objects, and OOP in Java. June 16, 2017
Classes, Objects, and OOP in Java June 16, 2017 Which is a Class in the below code? Mario itsame = new Mario( Red Hat? ); A. Mario B. itsame C. new D. Red Hat? Whats the difference? int vs. Integer A.
More informationAbout Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals
More informationQuiz. Question #1: What is the value of the following expression? {+ 1 2} Wrong answer: 0 Wrong answer: 42. Answer: 3 1-4
Quiz Question #1: What is the value of the following expression? Wrong answer: 0 Wrong answer: 42 Answer: 3 {+ 1 2} 1-4 Quiz Question #2: What is the value of the following expression? Wrong answer: error
More informationIntroduction to Programming, Aug-Dec 2006
Introduction to Programming, Aug-Dec 2006 Lecture 3, Friday 11 Aug 2006 Lists... We can implicitly decompose a list into its head and tail by providing a pattern with two variables to denote the two components
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2016 Lecture 7a Andrew Tolmach Portland State University 1994-2016 Values and Types We divide the universe of values according to types A type is a set of values and a
More informationCS 31: Intro to Systems C Programming. Kevin Webb Swarthmore College September 13, 2018
CS 31: Intro to Systems C Programming Kevin Webb Swarthmore College September 13, 2018 Reading Quiz Agenda Basics of C programming Comments, variables, print statements, loops, conditionals, etc. NOT the
More informationObject Oriented Programming
Object Oriented Programming Objectives To review the concepts and terminology of object-oriented programming To discuss some features of objectoriented design 1-2 Review: Objects In Java and other Object-Oriented
More informationSolution sheet 1. Introduction. Exercise 1 - Types of values. Exercise 2 - Constructors
Solution sheet 1 Introduction Please note that there can be other solutions than those listed in this document. This is a literate Haskell file which is available as PDF, as well as literate Haskell source
More informationDistributed Programming and Remote Procedure Calls (RPC): Apache Thrift. George Porter CSE 124 February 19, 2015
Distributed Programming and Remote Procedure Calls (RPC): Apache Thrift George Porter CSE 124 February 19, 2015 End-to-end RPC protocol RPC Components Defines messages, message exchange behavior, Programming
More informationTopics. bool and string types input/output library functions comments memory allocation templates classes
C++ Primer C++ is a major extension of c. It is similar to Java. The lectures in this course use pseudo-code (not C++). The textbook contains C++. The labs involve C++ programming. This lecture covers
More informationArrays. Lecture 11 CGS 3416 Fall October 26, 2015
Arrays Lecture 11 CGS 3416 Fall 2015 October 26, 2015 Arrays Definition: An array is an indexed collection of data elements of the same type. Indexed means that the array elements are numbered (starting
More informationCSU211 Exam 2 Fall 2007
CSU211 Exam 2 Fall 2007 Name: Student Id (last 4 digits): Instructor s Name: Write down the answers in the space provided. You may use the usual primitives and expression forms, including those suggested
More information17. Classes. Overloading Functions. Operator Overloading. Function Overloading. operatorop
Overloading Functions 17. Classes Overloading Functions and Operators, Encapsulation, Classes, Member Functions, Constructors Functions can be addressed by name in a scope It is even possible to declare
More informationLecture 2: Variables & Assignments
http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 2: Variables & Assignments (Sections 2.1-2.3,2.5) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner,
More informationChapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics
Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional
More informationRepetition. Add in Objects. Position Objects. Monkey Eat Bananas Repetition Simple Loops and Conditional Loops for Alice 3
Monkey Eat Bananas Repetition Simple Loops and Conditional Loops for Alice 3 Jonathon Kuo Under the Direction of Dr. Susan Rodger Duke University Repetition We first illustrate simple looping using count,
More informationMonkey Eat Bananas Repetition Simple Loops and Conditional Loops for Alice 3
Monkey Eat Bananas Repetition Simple Loops and Conditional Loops for Alice 3 Jonathon Kuo Under the Direction of Dr. Susan Rodger Duke University June 2017 Adapted from Dr. Rodger s Alice 2 Tutorial, Bunny
More informationObjective-C. Stanford CS193p Fall 2013
New language to learn! Strict superset of C Adds syntax for classes, methods, etc. A few things to think differently about (e.g. properties, dynamic binding) Most important concept to understand today:
More information(13-2) Dynamic Data Structures I H&K Chapter 13. Instructor - Andrew S. O Fallon CptS 121 (November 17, 2017) Washington State University
(13-2) Dynamic Data Structures I H&K Chapter 13 Instructor - Andrew S. O Fallon CptS 121 (November 17, 2017) Washington State University Dynamic Data Structures (1) Structures that expand and contract
More informationArrays. Lecture 11 CGS 3416 Spring March 6, Lecture 11CGS 3416 Spring 2017 Arrays March 6, / 19
Arrays Lecture 11 CGS 3416 Spring 2017 March 6, 2017 Lecture 11CGS 3416 Spring 2017 Arrays March 6, 2017 1 / 19 Arrays Definition: An array is an indexed collection of data elements of the same type. Indexed
More informationCS 403/503 Exam 4 Spring 2015 Solution
CS 403/503 Exam 4 Spring 2015 Solution Each problem initially scored out of 10 points possible. CS 403 Best 5 answers doubled. (5*20 + 2*10 = 120 possible) CS 503 Best 4 answers doubled. (4*20 + 3*10 =
More informationType checking of statements We change the start rule from P D ; E to P D ; S and add the following rules for statements: S id := E
Type checking of statements We change the start rule from P D ; E to P D ; S and add the following rules for statements: S id := E if E then S while E do S S ; S Type checking of statements The purpose
More informationComputational Expression
Computational Expression Variables, Primitive Data Types, Expressions Janyl Jumadinova 28-30 January, 2019 Janyl Jumadinova Computational Expression 28-30 January, 2019 1 / 17 Variables Variable is a name
More informationQuiz 1: Functions and Procedures
Quiz 1: Functions and Procedures Outline Basics Control Flow While Loops Expressions and Statements Functions Primitive Data Types 3 simple data types: number, string, boolean Numbers store numerical data
More information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationLecture 4: Inheritence and Abstract Classes
Integrated Introduction to Computer Science Fisler, Nelson Contents 1 Abstracting over Common Methods in Different Classes 1 2 Inheritence 2 2.1 Simplifying the Boa/Dillo Classes.............................
More informationCSCI-1200 Data Structures Spring 2018 Lecture 14 Associative Containers (Maps), Part 1 (and Problem Solving Too)
CSCI-1200 Data Structures Spring 2018 Lecture 14 Associative Containers (Maps), Part 1 (and Problem Solving Too) HW6 NOTE: Do not use the STL map or STL pair for HW6. (It s okay to use them for the contest.)
More informationQUark Language Reference Manual
QUark Language Reference Manual Daria Jung (djj2115), Jamis Johnson (jmj2180), Jim Fan (lf2422), Parthiban Loganathan (pl2487) Introduction This is the reference manual for QUark, a high level language
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a
More informationOnion Language Reference Manual. By: Andrew Aday, (aza2112) Amol Kapoor (ajk2227), Jonathan Zhang (jz2814)
Onion Language Reference Manual By: Andrew Aday, (aza2112) Amol Kapoor (ajk2227), Jonathan Zhang (jz2814) Introduction 3 Types 3 Lexical Conventions 4 Identifiers 4 Keywords 4 Comments 4 Expressions 5
More informationFunctional programming in mainstream languages. CS 3110 Lecture 26 Andrew Myers
Functional programming in mainstream languages CS 3110 Lecture 26 Andrew Myers Some functional language features Higher-order functions Freedom from side effects Polymorphism Pattern matching Modules (structures,
More informationCMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics
Recall Architecture of Compilers, Interpreters CMSC 330: Organization of Programming Languages Source Scanner Parser Static Analyzer Operational Semantics Intermediate Representation Front End Back End
More informationContents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance
Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass
More informationIntroduction to C++ General Rules, Conventions and Styles CS 16: Solving Problems with Computers I Lecture #2
Introduction to C++ General Rules, Conventions and Styles CS 16: Solving Problems with Computers I Lecture #2 Ziad Matni Dept. of Computer Science, UCSB Administrative This class is currently FULL and
More informationHaskell Scripts. Yan Huang
Haskell Scripts Yan Huang yh33@indiana.edu Last Quiz Objectives Writing Haskell programs in.hs files Note some differences between programs typed into GHCi and programs written in script files Operator
More information