Issue with Implementing PrimeSieve() in Go
|
|
- Lawrence Ball
- 6 years ago
- Views:
Transcription
1 Slices
2 Issue with Implementing PrimeSieve() in Go func PrimeSieve(n int) [n+1]bool { var iscomposite [n+1]bool //ERROR! biggestprime := 2 for biggestprime < n for i:=2; i<=n/biggestprime; i++ { iscomposite[i+biggestprime] = true biggestprime++ for biggestprime<n &&iscomposite[biggestprime]{ biggestprime++ return iscomposite Go only allows us to create an array of constant size.
3 Slices: Everything Arrays Should Be A slice variable is declared by not specifying a size in [] var a []int // at this point a has the special value nil // and can t be used as an array a = make([]int, 10, 20) Creates an array of size 20 with a slice of size 10 inside it. 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 1! 2! 3! 4! 5! 6! 7! 8! 9! 10! 11! 12! 13! 14! 15! 16! 17! 18! 19! Length of this slice is 10! Underlying array has size 20!
4 Omitting the Third Parameter var a []int a = make([]int, 10) // this is the same as make([]int, 10, 10)
5 We Can Still Change Items var a []int a = make([]int, 10) a[3] = -18 a[9] = 100 a[10] = 1 //error: out of range
6 Passing a Variable as Slice Length m := 100 var b []string b = make([]string, m) // this is OK!
7 Defining a Slice in One Line m := 100 b := make([]string, m) // this is OK!
8 Recall: Literals... The Other Side of = Integer literals: a sequence of digits String literals: a sequence of characters between Hi there 1+ = Unicode strings are supported. bool (Boolean) literals: either true or false true false
9 Array and Slice Literals We can manually create slices (useful if you have a short list of data that may change): var a = []float64{3.2, -30.1, 84.72, 62.0 var prime = []int{2,3,5,7,11 We can also use array literals (useful for a short list of data that is fixed): var b = [3]float64{2.8, -30.1, 13.2 var odds = [4]int{1,3,5,7
10 Fixing PrimeSieve func PrimeSieve(n int) []bool { iscomposite := make([]bool, n+1) //Fixed! biggestprime := 2 for biggestprime < n for i:=2; i<=n/biggestprime; i++ { iscomposite[i+biggestprime] = true biggestprime++ for biggestprime<n && iscomposite[biggestprime]{ biggestprime++ return iscomposite
11 Issue #2: Arrays Copied in Function Calls func Max(A [ ]int) int { m := 0 for i := range A { if i == 0 A[i] > m { m = A[i] return m func main() { var numbers [ ]int // fill numbers with random integers for i := range numbers { numbers[i] = rand.int() fmt.println(max(numbers)) A new array A is created and the contents from numbers is copied over (wasteful of memory).
12 Passing a Slice as an Argument We can also pass a slice (of unknown length) as a function argument. func Max(list []int) int { var m int = list[0] for i := range list { if list[i] > m { m = list[i] return m
13 Passing a Slice as an Argument func Fudge1(list []int) { list[0] = 1 func Fudge2(list [100]int) { list[0] = 1
14 Passing a Slice as an Argument func Fudge1(list []int) { list[0] = 1 Exercise: What is printed in main()? func Fudge2(list [100]int) { list[0] = 1 func main() { list1 := make([]int, 100) var list2 [100]int Fudge1(list1) Fudge2(list2) fmt.println(list1[0], list2[0])
15 Passing a Slice as an Argument func Fudge1(list []int) { list[0] = 1 Exercise: What is printed in main()? func Fudge2(list [100]int) { list[0] = 1 Answer: 1 0 func main() { list1 := make([]int, 100) var list2 [100]int Fudge1(list1) Fudge2(list2) fmt.println(list1[0], list2[0])
16 Looping Over Both Indices and Elements range also lets us loop over both the index and the elements of a slice. func Max(list []int) int { var m int for j, v := range list { if j == 0 v > m { m = v return m
17 The Blank Identifier func Sum(A []int) int { var result int for i, val := range A { result = result + val return result Think: What is the issue here?
18 The Blank Identifier func Sum(A []int) int { var result int for i, val := range A { result = result + val return result Error! Variable i declared and never used.
19 The Blank Identifier func Sum(A []int) int { var result int for i, val := range A { result = result + val return result Error! Variable i declared and never used. func Sum(A []int) int { var result int for _, val := range A { result = result + val return result Blank identifier _ (single underscore) is useful when declaring a variable that is never used.
20 Recall: Substrings in Go s := Hi There! fmt.println(s[3:5]) // prints Th fmt.println(s[1:]) // prints i There! fmt.println(s[:4]) // prints Hi T var str string = s[3:6] fmt.println(str) fmt.println(str[0]) // prints The // prints T H i T h e r e! Subslicing works in the same way.
21 Subslices: A Picture s := make([]int, 10, 20) for i:=1; i<10; i++ { s[i] = -i - 1 s! array! start! 0! end! 9! -1! -2! -3! -4! -5! -6! -7! -8! -9! -10! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 1! 2! 3! 4! 5! 6! 7! 8! 9! 10! 11! 12! 13! 14! 15! 16! 17! 18! 19!
22 Subslices: A Picture s := make([]int, 10, 20) for i:=1; i<10; i++ { s[i] = -i - 1 var q []int = s[8:15] s! q! array! array! start! 0! start! 8! end! 9! end! 14! -1! -2! -3! -4! -5! -6! -7! -8! -9! -10! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 1! 2! 3! 4! 5! 6! 7! 8! 9! 10! 11! 12! 13! 14! 15! 16! 17! 18! 19!
23 Subslices: A Picture s := make([]int, 10, 20) for i:=1; i<10; i++ { s[i] = -i - 1 var q []int = s[8:15] s! q! array! array! start! 0! start! 8! end! 9! end! 14! -1! -2! -3! -4! -5! -6! -7! -8! -9! -10! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 1! 2! 3! 4! 5! 6! 7! 8! 9! 10! 11! 12! 13! 14! 15! 16! 17! 18! 19! Both slices refer to the same underlying array. len(q) == 7 fmt.println(q[0]) // -9 fmt.println(q[6]) // -15 fmt.println(q[15]) // ERROR s[8] == q[0] s[9] = 12 // now q[1] == 12 too!
24 The append() and copy() Operations s := make([]int, 10) s = append(s, 5) 0! 0! 0! 0! 0 0! 0! 0! 0 0! 5 0! 1! 2! 3! 4! 5! 6! 7! 8! 9! 10 s! c := make([]int, 11) copy(c, s) 0! 0! 0! 0! 0 0! 0! 0! 0 0! 5! 0! 1! 2! 3! 4! 5! 6! 7! 8! 9! 10! c!
Arrays and Strings
Arrays and Strings 02-201 Arrays Recall: Fibonacci() and Arrays 1 1 2 3 5 8 13 21 34 55 a Fibonacci(n) a ß array of length n a[1] ß 1 a[2] ß 1 for i ß 3 to n a[i] ß a[i-1] + a[i-2] return a Declaring Arrays
More informationMore on Strings & Arrays
More on Strings & Arrays 02-201 Indexing Strings Strings work like arrays in some ways: Strings have fixed length. You can find the length of string s with len(s). You can access elements of string s with
More informationArrays/Slices Store Lists of Variables
Maps 02-201 Arrays/Slices Store Lists of Variables H i T h e r e! 0 1 2 3 4 5 6 7 8 1 1 2 3 5 8 13 21 34 55 89 0 1 2 3 4 5 6 7 8 9 10 ACG TTA GAG CCT TAA GGG CAT 0 1 2 3 4 5 6 What if Indices Aren t Integers?
More informationLecture 9: Lists. Lists store lists of variables. Declaring variables that hold lists. Carl Kingsford, , Fall 2015
Carl Kingsford, 0-0, Fall 0 Lecture : Lists Terminology: Go uses a non-standard term slice to refer to what we are calling lists. Others use the term array for the same concept. Unfortunately, Go uses
More informationA Slice of Life
A Slice of Life 02-201 More on Slices Last Time: append() and copy() Operations s := make([]int, 10)! s = append(s, 5)! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 5! 0! 1! 2! 3! 4! 5! 6! 7! 8! 9! 10! s! c := make([]int,
More informationFrom Last Time... Given a bacterial genome (~3 Mbp), where is ori?
From Last Time... Given a bacterial genome (~3 Mbp), where is ori? Given ori (~500 bp), what is the hidden message saying that replication should start here? From Last Time... Frequent Words Problem. Find
More informationConditionals !
Conditionals 02-201! Computing GCD GCD Problem: Compute the greatest common divisor of two integers. Input: Two integers a and b. Output: The greatest common divisor of a and b. Exercise: Design an algorithm
More informationConditionals & Loops /
Conditionals & Loops 02-201 / 02-601 Conditionals If Statement if statements let you execute statements conditionally. true "then" part condition a > b false "else" part func max(a int, b int) int { var
More informationFundamentals: Expressions and Assignment
Fundamentals: Expressions and Assignment A typical Python program is made up of one or more statements, which are executed, or run, by a Python console (also known as a shell) for their side effects e.g,
More informationSummary of Go Syntax /
Summary of Go Syntax 02-201 / 02-601 Can declare 1 or more variables in same var statement Variables Can optionally provide initial values for all the variables (if omitted, each variable defaults to the
More informationLecture 10: Lindenmayer Systems
Carl Kingsford, 0-01, Fall 015 Lecture 10: Lindenmayer Systems (Stacks, Queues, append, and list literals) Lindenmayer systems or L-systems are a way to model complex shape contruction simply. They are
More informationGo Cheat Sheet. Operators. Go in a Nutshell. Declarations. Basic Syntax. Hello World. Functions. Comparison. Arithmetic. Credits
Credits Go Cheat Sheet Most example code taken from A Tour of Go, which is an excellent introduction to Go. If you're new to Go, do that tour. Seriously. Original HTML Cheat Sheet by Ariel Mashraki (a8m):
More informationOverview of List Syntax
Lists and Sequences Overview of List Syntax x = [0, 0, 0, 0] Create list of length 4 with all zeroes x 4300112 x.append(2) 3 in x x[2] = 5 x[0] = 4 k = 3 Append 2 to end of list x (now length 5) Evaluates
More informationAdvanced Systems Programming
Advanced Systems Programming Introduction to C++ Martin Küttler September 19, 2017 1 / 18 About this presentation This presentation is not about learning programming or every C++ feature. It is a short
More informationVARIABLES AND TYPES CITS1001
VARIABLES AND TYPES CITS1001 Scope of this lecture Types in Java the eight primitive types the unlimited number of object types Values and References The Golden Rule Primitive types Every piece of data
More informationMaps /
Maps 02-201 / 02-601 Arrays Store Lists of Variables 3 12 3 3 7 8 10-2 30 6 11 11 11 32 64 80 99-1 0 12 A list of filenames A list of prime numbers A column of data from a spreadsheet A collection of DNA
More informationLast Time: Objects and Abstraction. If it walks like a circle, swims like a circle, and quacks like a circle...!
Pointers 02-201 Last Time: Objects and Abstraction If it walks like a circle, swims like a circle, and quacks like a circle...! Bird s Eye View of Object-Oriented Programming http://null-byte.wonderhowto.com!
More informationGo for Java Developers
Go for Java Developers Stoyan Rachev May 26-27 16, Sofia 1 Agenda Introduction Variables and Control Flow Types and Data Structures Functions Methods and Interfaces Concurrency Conclusion 2 What is Go?
More informationCS 320: Concepts of Programming Languages
CS 320: Concepts of Programming Languages Wayne Snyder Computer Science Department Boston University Lecture 04: Basic Haskell Continued o Polymorphic Types o Type Inference with Polymorphism o Standard
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 informationSwift. Introducing swift. Thomas Woodfin
Swift Introducing swift Thomas Woodfin Content Swift benefits Programming language Development Guidelines Swift benefits What is Swift Benefits What is Swift New programming language for ios and OS X Development
More informationLecture Overview Methods and Interfaces Methods review Interfaces Example: using the sort interface Anonymous fields in structs
1 Lecture Overview Methods and Interfaces Methods review Interfaces Example: using the sort interface Anonymous fields in structs Generic printing using the empty interface Maps Creating a map Accessing
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Type Inference Some statically typed languages, like ML (and to a lesser extent Scala), offer alternative
More informationPointers /
Pointers 02-201 / 02-601 Complex Literal Data Example func main() { company := make(map[string]teaminfo) company["applewatch"] = TeamInfo{ teamname: "applewatch", meetingtime: 10, members: []Employee{
More informationArray Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)
Array Basics: Outline Arrays (Savitch, Chapter 7) TOPICS Array Basics Arrays in Classes and Methods Programming with Arrays Searching and Sorting Arrays Multi-Dimensional Arrays Static Variables and Constants
More informationLecture 2 Tao Wang 1
Lecture 2 Tao Wang 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common programming errors
More informationAdvanced Python. Executive Summary, Session 1
Advanced Python Executive Summary, Session 1 OBJECT: a unit of data of a particular type with characteristic functionality (i.e., methods and/or use with operators). Everything in Python is an object.
More informationGO IDIOMATIC CONVENTIONS EXPLAINED IN COLOR
GO IDIOMATIC CONVENTIONS EXPLAINED IN COLOR REVISION 1 HAWTHORNE-PRESS.COM Go Idiomatic Conventions Explained in Color Published by Hawthorne-Press.com 916 Adele Street Houston, Texas 77009, USA 2013-2018
More informationCSC324- TUTORIAL 5. Shems Saleh* *Some slides inspired by/based on Afsaneh Fazly s slides
CSC324- TUTORIAL 5 ML Shems Saleh* *Some slides inspired by/based on Afsaneh Fazly s slides Assignment 1 2 More questions were added Questions regarding the assignment? Starting ML Who am I? Shems Saleh
More informationExercise: Inventing Language
Memory Computers get their powerful flexibility from the ability to store and retrieve data Data is stored in main memory, also known as Random Access Memory (RAM) Exercise: Inventing Language Get a separate
More informationStudent Number: Comments are not required except where indicated, although they may help us mark your answers.
CSC 108H5 F 2018 Midterm Test Duration 90 minutes Aids allowed: none Student Number: utorid: Last Name: First Name: Do not turn this page until you have received the signal to start. (Please fill out the
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 informationVariable initialization and assignment
Variable initialization and assignment int variable_name; float variable_name; double variable_name; String variable_name; boolean variable_name; Initialize integer variable Initialize floating point variable
More informationCS558 Programming Languages
CS558 Programming Languages Winter 2018 Lecture 7b Andrew Tolmach Portland State University 1994-2018 Dynamic Type Checking Static type checking offers the great advantage of catching errors early And
More informationCOMP 202 Java in one week
COMP 202 Java in one week... Continued CONTENTS: Return to material from previous lecture At-home programming exercises Please Do Ask Questions It's perfectly normal not to understand everything Most of
More informationWeek 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7.
Week 3 Functions & Arrays Gaddis: Chapters 6 and 7 CS 5301 Fall 2015 Jill Seaman 1 Function Definitions! Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements... Where
More informationSWIFT - CLOSURES. Global Functions Nested Functions Closure Expressions. Have a name. Capture values from enclosing function
http://www.tutorialspoint.com/swift/swift_closures.htm SWIFT - CLOSURES Copyright tutorialspoint.com Closures in Swift are similar to that of self-contained functions organized as blocks and called anywhere
More informationarray Indexed same type
ARRAYS Spring 2019 ARRAY BASICS An array is an indexed collection of data elements of the same type Indexed means that the elements are numbered (starting at 0) The restriction of the same type is important,
More informationCOMP520 - GoLite Type Checking Specification
COMP520 - GoLite Type Checking Specification Vincent Foley February 26, 2015 1 Declarations Declarations are the primary means of introducing new identifiers in the symbol table. In Go, top-level declarations
More informationAnnouncement. Overview. LISP: A Quick Overview. Outline of Writing and Running Lisp.
Overview Announcement Announcement Lisp Basics CMUCL to be available on sun.cs. You may use GNU Common List (GCL http://www.gnu.org/software/gcl/ which is available on most Linux platforms. There is also
More informationIntroduction to Swift. Dr. Sarah Abraham
Introduction to Swift Dr. Sarah Abraham University of Texas at Austin CS329e Fall 2018 What is Swift? Programming language for developing OSX, ios, WatchOS, and TvOS applications Best of C and Objective-C
More informationOverview. Arrays and their properties Creating arrays Accessing array elements Modifying array elements Loops and arrays. Initialization Searching
Arrays Overview Arrays and their properties Creating arrays Accessing array elements Modifying array elements Loops and arrays Initialization Searching Arrays and Their Properties Hold several values of
More informationGetting started with Java
Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving
More informationCSC148 Fall 2017 Ramp Up Session Reference
Short Python function/method descriptions: builtins : input([prompt]) -> str Read a string from standard input. The trailing newline is stripped. The prompt string, if given, is printed without a trailing
More informationENGI 1020 Introduction to Computer Programming J U L Y 5, R E Z A S H A H I D I
ENGI 1020 Introduction to Computer Programming J U L Y 5, 2 0 1 0 R E Z A S H A H I D I Passing by value Recall that it is possible to call functions with variable names different than the parameters in
More informationLanguage Reference Manual
TAPE: A File Handling Language Language Reference Manual Tianhua Fang (tf2377) Alexander Sato (as4628) Priscilla Wang (pyw2102) Edwin Chan (cc3919) Programming Languages and Translators COMSW 4115 Fall
More informationCSc Introduction to Computing
CSc 10200 Introduction to Computing Lecture 2 Edgardo Molina Fall 2011 - City College of New York Thursday, September 1, 2011 Introduction to C++ Modular program: A program consisting of interrelated segments
More informationCS205: Scalable Software Systems
CS205: Scalable Software Systems Lecture 4 September 14, 2016 Lecture 4 CS205: Scalable Software Systems September 14, 2016 1 / 16 Quick Recap Things covered so far Problem solving by recursive decomposition
More informationCOMP-520 GoLite Tutorial
COMP-520 GoLite Tutorial Alexander Krolik Sable Lab McGill University Winter 2019 Plan Target languages Language constructs, emphasis on special cases General execution semantics Declarations Types Statements
More informationHelp Topic: MOOS-IvP String Utilities
Help Topic: MOOS-IvP String Utilities Spring 2018 Michael Benjamin, mikerb@mit.edu Department of Mechanical Engineering, CSAIL MIT, Cambridge MA 02139 MOOS-IvP String Utilities The below describe a set
More informationPython allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:
1 STRINGS Objectives: How text data is internally represented as a string Accessing individual characters by a positive or negative index String slices Operations on strings: concatenation, comparison,
More informationGaE Graphs Ain t Easy. Andrew Jones (adj2129) Kevin Zeng (ksz2109) Samara Nebel (srn2134)
GaE Graphs Ain t Easy Andrew Jones (adj2129) Kevin Zeng (ksz2109) Samara Nebel (srn2134) Introduction Graphs Complex data structure Ubiquitous and fundamental Goal: We want to provide the end user a streamlined
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 informationTypes, Variables, and Constants
, Variables, and Constants What is a Type The space in which a value is defined Space All possible allowed values All defined operations Integer Space whole numbers +, -, x No divide 2 tj Why Types No
More informationGood Luck! CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none. Student Number:
CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none Student Number: Last Name: Lecture Section: L0101 First Name: Instructor: Horton Please fill out the identification section above as well
More informationChapter 6 Single-dimensional Arrays
Chapter 6 Single-dimensional s 1. See the section "Declaring and Creating s." 2. You access an array using its index. 3. No memory is allocated when an array is declared. The memory is allocated when creating
More informationOpen2Test Test Automation Framework for SilkTest - Coding Standards for Developers
Open2Test Test Automation Framework for SilkTest - Coding Standards for Developers Version 1.0 January 2010 DISCLAIMER Verbatim copying and distribution of this entire article is permitted worldwide, without
More informationBTE2313. Chapter 2: Introduction to C++ Programming
For updated version, please click on http://ocw.ump.edu.my BTE2313 Chapter 2: Introduction to C++ Programming by Sulastri Abdul Manap Faculty of Engineering Technology sulastri@ump.edu.my Objectives In
More informationProgramming Languages
CSE 130 : Winter 2009 Programming Languages News PA 2 out, and due Mon 1/26 5pm Lecture 5: Functions and Datatypes t UC San Diego Recap: Environments Phone book Variables = names Values = phone number
More informationConditionals. For exercises 1 to 27, indicate the output that will be produced. Assume the following declarations:
Conditionals For exercises 1 to 27, indicate the output that will be produced. Assume the following declarations: final int MAX = 25, LIMIT = 100; int num1 = 12, num2 = 25, num3 = 87; 1. if (num1 < MAX)
More informationUse of scanf. scanf("%d", &number);
Use of scanf We have now discussed how to print out formatted information to the screen, but this isn't nearly as useful unless we can read in information from the user. (This is one way we can make a
More informationProblem Solving for Intro to Computer Science
Problem Solving for Intro to Computer Science The purpose of this document is to review some principles for problem solving that are relevant to Intro to Computer Science course. Introduction: A Sample
More informationLecture 5: Variables and Functions
Carl Kingsford, 0-0, Fall 05 Lecture 5: Variables and Functions Structure of a Go program The Go program is stored in a plain text file A Go program consists of a sequence of statements, usually per line
More informationIntro. Scheme Basics. scm> 5 5. scm>
Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if
More information. p.1/23. Today. 1. Questions and discussion from lecture. 2. Type-checking Functions Arrays Records (maybe)
. p.1/23 Today 1. Questions and discussion from lecture. 2. Type-checking Functions Arrays Records (maybe) . p.2/23 Type-checking functions Aspects: Overview of checks 6, 7 Declaration header Declaration
More informationcs1114 REVIEW of details test closed laptop period
python details DOES NOT COVER FUNCTIONS!!! This is a sample of some of the things that you are responsible for do not believe that if you know only the things on this test that they will get an A on any
More informationCS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016
CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016 In this course you will start by building a compiler for a language called Xi. This is an imperative,
More informationWeek 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7. CS 5301 Spring 2018
Week 3 Functions & Arrays Gaddis: Chapters 6 and 7 CS 5301 Spring 2018 Jill Seaman 1 Function Definitions l Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements...
More informationPHP. Interactive Web Systems
PHP Interactive Web Systems PHP PHP is an open-source server side scripting language. PHP stands for PHP: Hypertext Preprocessor One of the most popular server side languages Second most popular on GitHub
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 informationCSCE 110 Dr. Amr Goneid Exercise Sheet (7): Exercises on Recursion (Solutions)
CSCE 110 Dr. Amr Goneid Exercise Sheet (7): Exercises on Recursion (Solutions) Consider the following recursive function: int what ( int x, int y) if (x > y) return what (x-y, y); else if (y > x) return
More informationCommon LISP Tutorial 1 (Basic)
Common LISP Tutorial 1 (Basic) CLISP Download https://sourceforge.net/projects/clisp/ IPPL Course Materials (UST sir only) Download https://silp.iiita.ac.in/wordpress/?page_id=494 Introduction Lisp (1958)
More informationOperational Semantics of Cool
Operational Semantics of Cool Key Concepts semantics: the meaning of a program, what does program do? how the code is executed? operational semantics: high level code generation steps of calculating values
More informationLecture 16: Object-oriented Programming
Carl Kingsford, 0-0, Fall 05 Lecture 6: Object-oriented Programming Programming languages provide many ways to help you organize your code. Functions are the most important and we've seen a lot of examples
More informationCSE 143. Linked Lists. Linked Lists. Manipulating Nodes (1) Creating Nodes. Manipulating Nodes (3) Manipulating Nodes (2) CSE 143 1
CSE 143 Linked Lists [Chapter 4; Chapter 6, pp. 265-271] Linked Lists A linked list is a collection of dynamically allocated nodes Each node contains at least one member (field) that points to another
More informationExercise: Using Numbers
Exercise: Using Numbers Problem: You are a spy going into an evil party to find the super-secret code phrase (made up of letters and spaces), which you will immediately send via text message to your team
More informationCSCI Test 1.Spring 2004 Student Id: Grading: Undergrads, you are responsible for 110 points. Grads: you are responsible for 120 points
1a.Define Programming Language. (3 b. From the point of view of development of software packages, list the kinds of activities that a programming language ought to support. (4 b. List the 3 factors in
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 informationCOS 126 General Computer Science Fall Written Exam 1
COS 26 General Computer Science Fall 27 Written Exam This exam has 7 questions (including question ) worth a total of 7 points. You have 5 minutes. Write all answers inside the designated spaces. Policies.
More informationComp Exam 1 Overview.
Comp 170-400 Exam 1 Overview. Resources During the Exam The exam will be closed book, no calculators or computers, except as a word processor. In particular no Python interpreter running in a browser or
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 informationProgramming with Java
Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules
More informationCS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find
CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS
More informationStudent Number: Comments are not required except where indicated, although they may help us mark your answers.
CSC 108H5 F 2014 Midterm Test Duration 50 minutes Aids allowed: none Last Name: Student Number: First Name: Lecture Section: L0101 Instructor: Dan Zingaro (9:00-10:00) Lecture Section: L0102 Instructor:
More informationThe type of all data used in a C (or C++) program must be specified
The type of all data used in a C (or C++) program must be specified A data type is a description of the data being represented That is, a set of possible values and a set of operations on those values
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 informationIntroduction to Python
Introduction to Python Why is Python? Object-oriented Free (open source) Portable Powerful Mixable Easy to use Easy to learn Running Python Immediate mode Script mode Integrated Development Environment
More informationCSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York
CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this
More informationBİL200 TUTORIAL-EXERCISES Objective:
Objective: The purpose of this tutorial is learning the usage of -preprocessors -header files -printf(), scanf(), gets() functions -logic operators and conditional cases A preprocessor is a program that
More informationFall 2017 CISC124 9/16/2017
CISC124 Labs start this week in JEFF 155: Meet your TA. Check out the course web site, if you have not already done so. Watch lecture videos if you need to review anything we have already done. Problems
More informationANSWERS. Birkbeck (University of London) Software and Programming 1 In-class Test Feb Student Name Student Number. Answer all questions
Birkbeck (University of London) Software and Programming 1 In-class Test 1.1 8 Feb 2018 Student Name Student Number Answer all questions 1. Consider the following sequence of Java statements: int i = 3;
More information\n is used in a string to indicate the newline character. An expression produces data. The simplest expression
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationTYPES, VALUES AND DECLARATIONS
COSC 2P90 TYPES, VALUES AND DECLARATIONS (c) S. Thompson, M. Winters 1 Names, References, Values & Types data items have a value and a type type determines set of operations variables Have an identifier
More informationRuby: Objects and Dynamic Types
Ruby: Objects and Dynamic Types Computer Science and Engineering College of Engineering The Ohio State University Lecture 5 Primitive vs Reference Types Recall Java type dichotomy: Primitive: int, float,
More informationRecap from last time. Programming Languages. CSE 130 : Fall Lecture 3: Data Types. Put it together: a filter function
CSE 130 : Fall 2011 Recap from last time Programming Languages Lecture 3: Data Types Ranjit Jhala UC San Diego 1 2 A shorthand for function binding Put it together: a filter function # let neg = fun f
More informationDaMPL. Language Reference Manual. Henrique Grando
DaMPL Language Reference Manual Bernardo Abreu Felipe Rocha Henrique Grando Hugo Sousa bd2440 flt2107 hp2409 ha2398 Contents 1. Getting Started... 4 2. Syntax Notations... 4 3. Lexical Conventions... 4
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 informationViolations of the contract are exceptions, and are usually handled by special language constructs. Design by contract
Specification and validation [L&G Ch. 9] Design patterns are a useful way to describe program structure. They provide a guide as to how a program fits together. Another dimension is the responsibilities
More informationComputers and Programming Section 450. Lab #1 C# Basic. Student ID Name Signature
Lab #1 C# Basic Sheet s Owner Student ID Name Signature Group partner 1. Identifier Naming Rules in C# A name must consist of only letters (A Z,a z), digits (0 9), or underscores ( ) The first character
More informationA First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1
A First Look at ML Chapter Five Modern Programming Languages, 2nd ed. 1 ML Meta Language One of the more popular functional languages (which, admittedly, isn t saying much) Edinburgh, 1974, Robin Milner
More information