Documents Found!
As seen in
Less Work, Better Grades
Join
Course Hero
Access
best resources
Ace
your classes
Ace your courses with Course Hero!

Limited, unformatted preview (showing 87 of 2411 words):
...Lecture CS611 14 State and mutable variables 23 September 2007 Lecturer: Andrew Myers 1 Some thoughts about state State refers to the ability to have mutation: a change in value over time. The functional languages we have studied so far, such as the -calculus and uML, have not had state, in the sense that once a value is created, it is impossible to change that value, and once a variable is bound it cannot be rebound to a new value (except by creating a new variable). Although state is not a...
Study Smarter, Score Higher
 
Document Content (unformatted)
Course Hero has millions of student submitted documents similar to the one below including study guides, homework solutions, papers, exam answer keys and textbook solutions.
Lecture CS611 14 State and mutable variables 23 September 2007 Lecturer: Andrew Myers 1 Some thoughts about state State refers to the ability to have mutation: a change in value over time. The functional languages we have studied so far, such as the -calculus and uML, have not had state, in the sense that once a value is created, it is impossible to change that value, and once a variable is bound it cannot be rebound to a new value (except by creating a new variable). Although state is not a necessary feature of a programming language (e.g. -calculus is Turing complete but does not have a notion of state), it is a feature of most languages in common use today. We distinguish between functional languages and imperative languages primarily on the basis of whether they are organized primarily around a stateless paradigm (with higher-order functions), or an stateful paradigm of mutable variables and data structures. It might be more useful, in fact, to distinguish between stateless and stateful languages, since stateful languages usually have functions too. Why do many programmers like stateful programming languages? Perhaps because it matches how we think of the world. We view the world as being composed of entities (such as people or objects) with intrinsic unchanging identities. These entities change their state over time while maintaining the same underlying identity. If a programming language matches our mental model of the world, it s more comfortable for programmers to think about. Thus, stateful languages always come equipped with an underlying notion of identity, such as variable identity or object identity. In these languages, the binding between identities and their current states can change over time. Stateful languages intrinsically have a notion of time, unlike pure functional languages such as uML or lambda calculus, which take an essentially timeless view of computation. In stateless languages, it doesn t matter exactly when something happens, because the outcome will be the same regardless. In stateful languages with multiple concurrent threads, it matters a great deal when something happens. It can be argued that our perception of underlying identity is an illusion. In physics, identity does not exist: particles are identi ed by their state, not by any intrinsic identity. If two electrons in di erent states are swapped, no change has happened to the universe, because an electron is really the same thing as its state. Time is arguably an illusion as well: the universe is a multidimensional object in which physics says that time is much more symmetric to the other dimensions than we perceive. Being made of particles ourselves, we are only able to sense a single moment in time. Arguably, the universe is purely functional, and our minds deceive us. In fact, the idea that we are deceived into thinking that objects have an underlying identity dates back to Buddhist and even earlier Vedantic philosophy (the Upanishads). The mismatch between reality and our perceptions becomes pragmatically relevant when we look at the di culties in programming multiprocessor/multicore systems. Our consciousness is single-threaded, so it makes perfect sense to us to think about state evolving along a single timeline. But when with multiple simultaneous threads of computation, and communication delays, it is infeasible to give all threads a single, consistent view of the state evolution of the system. We nd it very di cult to reason about how such multithreaded systems work and to write correct programs for them in a stateful language. Designing workable programming languages for multicore systems is currently an active research topic. In sidestepping the intrinsic problems with state, a stateless language may be a better match for such systems than the stateful languages we commonly use! 2 First-class references We extend uML with state, and call the new language uML! . We use a construct called a reference cell that allows a value to be rebound to di erent values over time. We can then use reference cells to model language features such as mutable variables. Reference cells are rst-class values in this language, like in ML. The syntax of uML! is as follows: 1 e ::= | | | | ... ref e !e e1 := e2 e1 ; e2 (create a reference cell with initial value from e) (evaluation or dereference) (assignment or mutation) (sequential composition) Informally, the meaning of these new expressions is as follows. Evaluating the expression ref e creates a new reference cell having the initial value e. The expression !e evaluates to the current value of the reference cell e. The assignment e1 := e2 assigns the value of e2 to the reference cell e1 , and in our semantics returns the value null. Other design choices could have been made. For example, the assignment operator could have returned the value of e2 so that expressions like e0 := (e1 := e2 ) would make sense and could be used to assign the same value to multiple variables. In this treatment, reference cells are rst-class objects. This is more powerful than simple mutable variables as in C. It is also more dangerous, because it introduces aliasing, as the following example demonstrates: let x = ref 1 in let y = x in let z = (x := 2) in !y Here y is an alias for x. Dereferencing y gives us the value of x, which in this case has changed from 1 to 2. The expression therefore evaluates to 2. In other words, if you kick x, y jumps! Aliasing is a constant source of errors in stateful programming. A classic example is a procedure that is supposed to multiply two matrices a and b and write the result imperatively into a third matrix c. The programmer writes the obvious code, then later wants to set a to the product of a and b. This makes the matrix multiply compute something completely di erent from what was intended, and is very hard to debug! 2.1 Operational semantics We now give an operational semantics for reference cell expressions in uML! . To do this, we de ne a con guration as a pair e, , where e is an expression and is a function mapping reference cells to values. Reference cells are denoted generically by . We extend the grammar of expressions and values to include reference cells. e ::= . . . | v ::= . . . | We inherit the existing reductions from uML, lifting them to apply to uML! expressions. All these reductions have no side e ects, so the state is unchanged by them: e e e, uML! e , ref v, := v, ! , null; e, , [v ] null, [v ] ( ), e, (where (where (where dom( )) / dom( )) dom( )) 2 where [v ] is the same function as , except that the value on input is changed to v. The language has eager, left-to-right evaluation, so the evaluation contexts are given by this grammar: E ::= . . . | ref E | ! E | E := e | := E | E; e The structural congruence rule is adapted to take into account the current state: e, e , E[ e ], E[ e ], 2.2 Translation semantics [[e]] is an expression that computes a pair (e , ) in a naming environment and state , where e is the resulting expression and is the store. [[n]] [[x]] [[if eb then e1 else e2 ]] [[ref e]] [[ !e]] [[e1 := e2 ]] = (n, ) = ( x , ) = let (b, )1 = [[eb ]] in if b then [[e1 ]] else [[e2 ]] = let (x, ) = [[e]] in MALLOC x = let (x, ) = [[e]] in (LOOKUP x, ) = let (x1 , ) 1 = [[e1 ]] in let (x2 , 2 ) = [[e2 ]] 1 in (null, UPDATE 2 x1 x2 ) = let (x, 1 ) = [[e1 ]] in [[e2 ]] 1 = (null, ) = let (y, ) = [[e1 ]] in [[e2 ]](EXTEND x y) = y dyn . [[e]] (EXTEND lex x y) dyn = let (f, 1 ) = [[e1 ]] dyn dyn in let (v, 2 ) = [[e2 ]] dyn 1 in f v 2 [[e1 ; e2 ]] [[null]] [[let x = e1 in e2 ]] [[ x. e]] lex lex [[e1 e2 ]] dyn dyn Here, we rely on certain abbreviations (MALLOC, UPDATE, and LOOKUP), for manipulating stores. The function MALLOC allocates a new memory location; LOOKUP reads the contents of a memory location; UPDATE produces a new store with one location changed. Further, we will need an initial store EMPTY-STORE. We don t care exactly how these terms are implemented, as long as they obey certain equations (the notion of equality here is equivalence after evaluation): LOOKUP EMPTY-STORE = error LOOKUP (#1 (MALLOC v)) = error LOOKUP (#2 (MALLOC v)) (#1 (MALLOC v)) = v LOOKUP (#2 (MALLOC v)) = LOOKUP LOOKUP (UPDATE v) = v LOOKUP (UPDATE v) = LOOKUP (if = #1 (MALLOC v)) (if = ) Implementing terms with these properties is left as an exercise to the reader. 1 let (b, ) = [[eb ]] in e here is syntactic sugar for let p = [[eb ]] in let b = #1 p in let = #2 p in e . 3 3 Mutable variables Let s take a closer look at what happens in a language like C, where variables themselves are mutable. 3.1 Syntax e ::= . . . uML . . . | e1 = e2 | e | &e | e1 ; e2 where we think of the constructs respectively as: e1 = e2 is assignment where e1 is an assignable variable name, for instance, an array reference. e is used to dereference a pointer e (acts sort of like ! in UML! ). &e gives a pointer to the location of e. 3.2 Translation semantics The target language is again uML. Since variables are mutable, we need to change the naming environment to be a mapping from variable names to store locations. Each variable is bound to the identity of its reference cell. The translation we de ne takes into account the fact that C has two kinds of values: lvalues, values which can appear in the left-hand side of an assignment; and rvalues, values that cannot appear on the LHS. To capture this in the target language, for each expression e of C, we de ne [[e]]L (the lvalue of e) and [[e]]R (the rvalue of e). As before, we need to keep track of the state of the computation so the results of the translations are pairs. To summarize: [[e]]L = (location of e, ) [[e]]R = (value of e, ). The translation is de ned inductively on the structure of C programs. Note that some lvalue translations are not de ned, corresponding to invalid expressions that a C compiler would catch. For instance, [[n]]L is not de ned. This prevents reassigning of, say, the integer 5 to have the value 3. [[n]]R [[x]]L [[e]]R For assignment: [[e1 = e2 ]]R Comments: This forces left-to-right evaluation. It allows a chain of assignments. For example, e1 = e2 = e3 = e4 = 5 will assign 5 to each ei in our translation, just as in C. 4 = let( , ) = [[e1 ]]L in let(v, ) = [[e2 ]]R in (v, UPDATE = (n, ) = ( x , ) = let ( , ) = [[e]]L in (LOOKUP , ) (if [[e]]L is de ned) v) An assignment statement is not an lvalue in C, nor is it here. Addressing: [[ e]]L [[&e]]R = = [[e]]R [[e]]L So the two operations, , &, are inverses of each other; their function is to shift the view of a value rather than to do computation. For example, the semantics de ned above let us write & & &x = 2. This will have the same e ect as x = 2. Another example (written in C): int y = 0; int x = &y; *x = 1; This piece of code assigns 1 to y. Note that it would be illegal to include a line &y = 0x1002; because we can t change the address of a variable. Functions: [[ x.e]]R [[e1 e2 ]]R Discussion: Choices we made: function applications don t a ect state, in function application use left to right evaluation. In de ning function application, the allocation is required because variables must be bound to locations, whereas the argument of the function is a value (C is call-by-value). The value that a function returns is an rvalue rather than an lvalue. Why? Returning an lvalue whould mean we could assign new values to locations allocated during computation, e.g. bo 5 = 1;. We choose a semantics where we get back the value of a computation rather than its location. Note that we do not need to explicitly de ne the store in the translation of function application because f v returns a pair of a location and a store. = y dyn . let ( , ) = MALLOC dyn y in [[e]]R (EXTEND x ) , = let (f, ) = [[e1 ]]R in let (v, ) = [[e2 ]]R in f v 4 Pass (call) by Reference It is conceivable to de ne a language where arguments to functions are lvalues. In this case, the body of functions can update the argument and therefore change the value stored in the location passed in. Examples of such languages are PASCAL, MODULA, Ada, Matlab (sort of), FORTRAN. Consider a simple syntax for pass-by-reference: e ::= . . . | r x. e | rcall e1 e2 Note that we are explicitly saying when we pass by reference because we do not have a type system that distinguishes between the two cases. Example program: let let x = 1 in f = r y. y = y + 1 in rcall f x 5 In this program, y is an alias for x, so the value at the location of x is updated to 2. To incorporate pass-by-reference into the semantics, we just need to change the rules for functions: [[ r x.e]]R [[rcall e1 e2 ]]R = y dyn .[[e]]R (EXTEND x y) dyn , = let (f, ) = [[e1 ]]R in let ( , ) = [[e2 ]]L in f Since we are given a location, we don t need to allocate new memory. 5 Objects 5.1 De nition Objects combine naming and the notion of state. We can think of objects as naming environments. For instance, we might have: class C int x; int y; int m (int z) . . . x . . . y . . . this . . . z ; where x, y are elds (which are mutable) and m is a method ( immutable). Each of the elds and methods may be public or private, and the class itself might be mentioned using the keyword this This is reminiscent of modules (recall: modules are non-hierarchical scope which introduces names that may or may not be accessible outside the scope). Let s try to encode objects using module constructs: e ::= . . . uML . . . | ( elds x1 = e1 , . . . , xn = en ; methods f1 = y1 .e1 , . . . , fm = ym .em ) | e.x where the rst new clause de nes the object and the second clause selects components of the object. 5.2 Translation We will translate objects to a naming environment. [[( elds = e, methods f = y.e )]] = x let z = [[e]] in Y( . x . if x = x1 then z1 else if x = x2 then z2 else . . . if x = f1 then z1 .[[e1 ]](EXTEND (EXTEND y z1 ) this ) . . .) Note that we used the Y combinator to allow method bodies to talk about the object itself, i.e. the naming environment de ned by the object. 5.3 Problem Objects as recursive records breaks when we try to implement inheritance, because the name this is bound in the methods of the super-object to the wrong xed point. 6
Find millions of documents here - Study Guides, Homework Solutions, Papers, Exam Answer Keys and more. Course Hero has millions of course related materials that will enable you to learn better, faster and get an A in all your courses.
Below is a small sample set of documents:

Cornell >> CS >> 611 (Fall, 2001)
CS611 Lecture 12 Modules and State 25 September 2006 Lecturer: Dexter Kozen 1 Introduction In the last two lectures, we studied the static and dynamic approaches to variable scoping. These scoping disciplines are mechanisms for binding names to va...
Cornell >> CS >> 611 (Fall, 2001)
CS611 Lecture 12 State-passing and mutable variables 24 September, 2004 Lecturer: Andrew Myers Scribe: Yejin Choi, Krzysztof Ostrowski 1 State-passing style translations In the previous class we extended our untyped functional language uML with M...
Cornell >> CS >> 611 (Fall, 2001)
CS611 Lecture 11 Modules and State 22 September 2004 Lecturer: Andrew Myers Scribe: Krishnaprasad Vikram, David Crandall 1 Introduction The last lecture introduced the static and dynamic approaches to variable scoping. Both of these approaches ar...
Cornell >> CS >> 611 (Fall, 2001)
CS611 Lecture 12 Scribe: Kevin Markman and Jon Guarino State & References 23 September, 2005 Lecturer: Andrew Myers Todays lecture introduced the idea of mutable state and the side eects caused by the evaluation of commands. The following topics a...
Cornell >> CS >> 611 (Fall, 2001)
CS611 Lecture 37 Scribe: Yejin Choi, Bryan Silverthorn Axiomatic semantics 29 November, 2004 Lecturer: Andrew Myers 1 Introduction In this lecture, we will learn techniques for reasoning about the behavior of programs when applied to sets of state...
Cornell >> CS >> 611 (Fall, 2001)
CS611 Lecture 20 Scribe: Abhinandan Das and Bo Pang Axiomatic Semantics 10/11/00 Lecturer: Dexter Kozen 1 Recap The domain of computation that we (Winskel) have been using (for IMP terms or Aexps) is the number theory domain N . In general, we may...
Cornell >> CS >> 611 (Fall, 2001)
CS611 Lecture 1 Introduction to the IMP Programming Language 8/25/00 Scribe: Vicky Weissman and Daniel Marques Lecturer: Andrew Myers General course information was given at the beginning of lecture. For details, please refer to the web site at ...
Cornell >> CS >> 611 (Fall, 2001)
CS 611 Advanced Programming Languages Andrew Myers Cornell University Goals Deeper understanding of PLs Broader exposure to PLs Not a survey course Lecture 1: Introduction 25 Aug 00 CS 611 Fall \'00 Lecture 1 - Andrew Myers 2 Why study PL? El...
Cornell >> CS >> 481 (Fall, 2004)
CS481F01 HW 3 Non-Regular Sets and State Minimization A. Demers 26 Sep due 3 Oct Please remember to turn in each problem on a separate page. This week, please remember to put your name on each page, and turn in the pages in three separate piles! 1...
Cornell >> CS >> 481 (Fall, 2004)
CS481F01 Notes on DPDAS A. Demers 31 Oct The construction given in Chapter F of the text seems strange in just the way you all noticed in lecture. Heres my proposal to x it up. Def: A triple (p, , A) is stuck for M if (q, )(p, , A) ;M (q, ) That is,...
Cornell >> CS >> 481 (Fall, 2004)
Quiz 4 Solutions Friday, November 18, 2004 Name (and cornell.edu login) 1. Consider the following TM M with input alphabet {a, b}, left endmarker , blank symbol , start state s, accept state f , and reject state r. a b s s, , R s, b, R r, a, L f, , ...
Cornell >> CS >> 481 (Fall, 2004)
CS481F01 Homework 1 FAs and Regular Sets A. Demers 10 Sep due 17 Sept In all the following problems, let = {0, 1}. 1. Let L be the set of all strings in which the third symbol from the right end is 1; that is, L = { x1ab | x a, b } For exa...
Cornell >> CS >> 481 (Fall, 2004)
CS481F01 Final Study Notes December 14, 2001 The Exam is scheduled for Tues, 18 Dec, 12:00-2:30 in PH 403. As usual, the Exam is open book, open notes. I am hoping it should take about 90 minutes, but you have the full 150 minutes if you want it. Y...
Cornell >> CS >> 414 (Spring, 2008)
Assignment 5 Reliable networking with minisockets Ari Rabkin A lesystem postmortem Its hard, we know. We arent out to get you; grading wont be too brutal. Late submission until 3am tonight without penalty. Also, well drop lowest project score Rememb...
Cornell >> CS >> 414 (Spring, 2008)
OS and Architectures Architectural Support for Operating Systems Emin Gun Sirer What an OS can do is dictated, at least in part, by the architecture. Architecture support can greatly simplify (or complicate) OS tasks Example: PC operating syst...
Cornell >> CS >> 414 (Spring, 2008)
University of Washington Motivation Extensibility Extensibility, Safety and Performance in the SPIN Operating System MS -D OS ch Ma Emin Gun Sirer Performance UNIX Safety Approach ? ? ? A SPIN extension Application User Kernel Extensibility ...
Cornell >> CS >> 212 (Fall, 2008)
A % % \' ! ! \" $\' FDE C DB ( % 8 \' ! # % 1 \" \" ) 4\" \" 6 # ) \'\" ! ! 9 G % % \" \" % 8 \"5 % \" % 8 ) ( 8 $ $ ( ( $ ( \" ( 3 \" \' % 7 \'\" % 8 \"1 % ( ) ) ( 3 \' ...
Cornell >> CS >> 212 (Fall, 2008)
SaM 1. Introduction Have you ever heard the Java mantra, write once, run everywhere? So, how does that work? When you compile a Java program, you generate a binary le that contains byte-code. Byte-code is a collection of instructions that resemble ma...
Cornell >> CS >> 212 (Fall, 2008)
Some Abstract Syntax Trees for Bali ex) e1+e2 tree for e1 tree for e2 Figure 1: Expression ex) x = e; x tree for e Figure 2: Assignment Statement ex) { S1 ; S2 ; ; Sn } tree for S1 tree for S2 tree for Sn Figure 3: Statement Block ex) if ( c ...
Western Michigan >> I >> 5 (Fall, 2009)
Econ 201: Principles of Microeconomics Spring 2009 INSTRUCTOR: OFFICE: OFFICE PHONE: EMAIL: WEBPAGE: OFFICE HOURS: Ivan A. Duran 5303 Friedmann Hall 269 387-5552 i5durandiaz@wmich.edu http:/homepages.wmich.edu/~i5durandiaz Monday/Wednesday 3 - 5 P.M....
Western Michigan >> I >> 5 (Fall, 2009)
Econ 202: Principles of Macroeconomics Fall 2008 INSTRUCTOR: OFFICE: OFFICE PHONE: EMAIL: WEBPAGE: OFFICE HOURS: Ivan A. Duran 5303 Friedmann Hall 269 387-5552 i5durandiaz@wmich.edu http:/homepages.wmich.edu/~i5durandiaz Monday 4:30-6:30pm, Tuesday 4...
Cornell >> CS >> 114 (Fall, 2008)
CS 114 - Fall 2004 Lecture 3 - Friday, October 1, 2004 Editors: Comparative Religion 101 In this lecture, we finally create and modify files, a process known as editing. A file is just a sequence of bytes. Text files are just sequences of characters ...
Cornell >> CS >> 114 (Fall, 2008)
Unix Tools CS114 Fall 2002 Homework 2 Due Date: Wednesday, October 16, 2002 (at noon) You should do all the work yourself, without any assistance from other people. If you need help, post your question to cornell.class.cs114 newsgroup or if you wan...
Cornell >> CS >> 214 (Spring, 2008)
Basic Perl Scripting March 9, 2005 Intro Perl=Practical Extraction and Report Language not shell programming use version 5.6 Simple Perl script test.pl #!/usr/local/bin/perl print This is a test \ Option 1: >chmod +x test.pl >test.pl Option 2: >pe...
Cornell >> CS >> 421 (Fall, 2005)
CS 421: Numerical Analysis Fall 2005 Problem Set 3 Handed out: Wed., Oct. 5. Due: Mon., Oct. 17. 1. In the weighted least squares problem, one is given an m n matrix A of rank n, an m-vector b, and a positive denite diagonal m m matrix D called the...
Cornell >> CS >> 214 (Spring, 2008)
Advanced Unix Tools CS214 Spring 2004 Homework 2 Due Date: Friday, March 12, 2004 This homework looks forbidding, but its much easier than it looks. Start early anyways, to make sure you know whats going on. You have a large script to write, but it...
Cornell >> CS >> 421 (Fall, 2005)
CS 421: Numerical Analysis Fall 2002 Problem Set 3 Handed out: Wed., Oct. 9. Due: Fri., Oct. 18. 1. Let L1 and L2 be two lines in Rn . Assume that L1 is written in parametric form as L1 = {v1 + t1 w1 : t1 R} where v1 , w1 are given, and assume L2 ha...
Cornell >> CS >> 100 (Fall, 2008)
CS100M Fall 2007 Grading Guide: Project 5 April 14, 2008 The coded items below (e.g., c1e, s2a) indicate what a student\'s solution should accomplish. Codes that begin with the letter c deals with correctness; codes that begin with s deals with style...
Cornell >> CS >> 100 (Fall, 2008)
CS 100M: Section Exercises for February 15-16 1. Copy the following script o of the website and run it. % Fibonacci Numbers and Golden Ratio clc disp( j j-th Fibonacci# j-th Ratio) disp(-) N = 12; x = 0; y = 1; for j=1:N % x is the (j-2)nd Fibonacci ...
Cornell >> CS >> 100 (Fall, 2008)
CS100M Section - Week 6 March 8, 9 2005 Vectors, vectorized code, and matrices 1 New vectors from old ones Write a function interleave that receives as input two vectors v and w of the same length and returns a new vector interleaved consisting of...
Cornell >> CS >> 7 (Fall, 2008)
CS100M Section - Week 6 March 8, 9 2005 Vectors, vectorized code, and matrices 1 New vectors from old ones Write a function interleave that receives as input two vectors v and w of the same length and returns a new vector interleaved consisting of...
Cornell >> CS >> 100 (Fall, 2008)
Chapter 2 Numerical Exploration 2.1 Discovering Limits The for-loop and the while-loop 2.2 Floating Point Terrain The oating point representation, exponent, mantissa, overow, underow, machine precision, eps, inf, realmax, roundo error 2.3 Conrming...
Cornell >> CS >> 100 (Fall, 2008)
More Matrices Lecture 15 (Mar 11) CS100M Spring 2008 Announcements Prelim 2 is onThursday, March 13 Time: 7:30-9:00 pm Includes material through Wednesday, March 5 Includes functions and vectors No matrices on prelim 2 There is an document on the ...
Cornell >> CS >> 100 (Fall, 2008)
CS100M Lecture 28 May 5, 2005 Announcements P6 due today at 6pm Final exam: 5/13, noon-2:30pm Email Kelly Patwell with your exam info if you have an exam conflict Please fill out course evaluation on-line Pick up papers from consultants at Carpenter...
Cornell >> CS >> 100 (Fall, 2008)
CS100M Lecture 9 2005/2/22 Announcements: Prelim 1 on Thurs, 2/24, 7:30-9p. Check course website for locations Section this week in classrooms (not labs) Read over project solutions & grading guides Evaluate your TA on-line! Previous Lecture: User-...
Cornell >> CS >> 100 (Fall, 2008)
Scores c and s stand for correctness and style Each item marked * counts as two items Score Correctness errors Style errors 0 1 2 3 4 5 0. General (s0a) Variable names are appropriately chosen (s0b) Code lines are properly indented (s0c) All ext...
Cornell >> CS >> 100 (Fall, 2008)
CS100 M Lecture 15 Mar 14, 2005 Previous Lecture: Matrices in MATLAB Java Program Structure In the Java programming language: A program is made up of one or more classes A class contains one or more methods A method contains program statements Tod...
Cornell >> CS >> 100 (Fall, 2008)
CS100M Lab 1 January 25, 26, 2005 When you have completed the lab, show this sheet and any associated programs to your lab instructor, who will record that you have completed the lab. If you do not nish this exercise during the lab, show the instru...
Cornell >> CS >> 100 (Fall, 2008)
CS 100M: Prelim 2 Review Questions 1. (Lec 7) Change this function so that the initial guess and nSteps are input parameters. function y = MySqrt1(x) % Post: y is the square root of x % Pre: x is a real number that satisfies 1 <= x <= 4 nSteps = 4; y...
Cornell >> CS >> 2 (Spring, 2001)
CS 100M: Prelim 2 Review Questions 1. (Lec 7) Change this function so that the initial guess and nSteps are input parameters. function y = MySqrt1(x) % Post: y is the square root of x % Pre: x is a real number that satisfies 1 <= x <= 4 nSteps = 4; y...
Cornell >> CS >> 100 (Fall, 2008)
Chapter 4 Exponential Growth 4.1 Powers User-dened function, function declarations, preconditions and post conditions, parameter lists, formal and actual parameters, functions that call other functions, scope rules, development through generalizatio...
Cornell >> CS >> 100 (Fall, 2008)
CS100M Lecture 10 2008/2/21 Previous lecture User-defined functions Accessing your functions For now*, put your related functions and scripts in the same directory. MyDirectory dotsInCircles.m randDouble.m polar2xy.m drawColorDot.m Today\'s lecture...
Cornell >> CS >> 114 (Fall, 2008)
CS 114 - Fall 2004 Lecture 8 - Friday, October 15, 2004 Shell scripts Last time, we saw that a file can be made into a program by first making it executable (chmod +x) and then prepending a #! line: #!command The #! is called a hash bang or sh-bang. ...
Cornell >> CS >> 114 (Fall, 2008)
CS 114 - Fall 2004 Lecture 5 - Monday, October 5, 2004 I/O redirection In Unix, a job normally has at least 3 I/O channels it can use to communicate: stdin - the standard input channel, where it reads its input stdout - the standard output channel, w...
Cornell >> CS >> 114 (Fall, 2008)
CS 114 - Fall 2004 Lecture 6 - Friday, October 8, 2004 Regular expressions Text files are the primary way of storing data in Unix. A consequence of this is that you\'ll often need to search for something in text files. For example, you are editing a f...
Cornell >> CS >> 114 (Fall, 2008)
CS 114 Unix Tools Fall 2004 Assignment 4: mvsed Handed out: Wed, 20 Oct Due: Fri, 5 Nov, 5pm This assignment asks you to write one shell script. Theres tons of time to do this assignment, but dont procrastinate. Ill be out of town from 23 Oct to 31 ...
Cornell >> CS >> 114 (Fall, 2008)
Unix Tools CS114 Fall 2003 Lecture 5 Wednesday, October 8, 2003 Regular expressions As youll notice, text les turn out to be important under Unix. One consequence of this is that youll often need to search for something in text les. For example, yo...
Cornell >> CS >> 114 (Fall, 2008)
Line-oriented programming: awk Three versions of awk (named after its authors Aho, Weinberger and Kernighan): nawk (new awk) is more powerful than awk and gawk (GNU awk) is even more powerful. I will focus on gawk. Starting gawk gawk options progra...
Cornell >> CS >> 114 (Fall, 2008)
Unix Tools CS114 Fall 2003 Lecture 4 Monday, October 6, 2003 Finally, after a week of dreary le and directory manipulations, we get to actually create and modify les, a process known as editing. Whats a le? A (text) le is just a sequence of charact...
Western Michigan >> L >> 3 (Fall, 2009)
Name: _ WIN: _ Date: _ Problem set: Ch 4 Multiple Choice Identify the letter of the choice that best completes the statement or answers the question. _ 1. In a market economy, supply and demand are important because they a. play a critical role in t...
Cornell >> JRZ >> 3 (Fall, 2009)
...
Cornell >> NELS >> 39 (Fall, 2009)
Clausal Comparatives and Cross-linguistic Variation Junko Shimoyama, McGill University Cross-linguistic variation in comparative constructions has attracted much attention in recent years. There has been much discussion, for instance, on how the phra...
Cornell >> NELS >> 39 (Fall, 2009)
A psycholinguistic investigation of MaxElide in variable-binding contexts Margaret Grant, UMass Amherst The study of ellipsis has provided much insight into the nature of the syntax-semantics interface. Recently, a proposal by Merchant (2008) introdu...
Western Michigan >> STAT >> 160 (Fall, 2008)
Stat1600 1. (a) Two of a kind: trials 2, 3, 4, and 6. So, P (A) = (b) error(A ) = 2 p (c) Trials without a 2: trials 1, 4, 5, 7, and 10. So, P (C) = (d) error(C ) = 2 p (e) Two of a kind without a 2: trial 4 only. So P (A and C) est. est. est. Par...
Western Michigan >> STAT >> 160 (Fall, 2008)
Stat1600 1. (a) Switch. Partial Solution to Group Activity #4 (b) Stay: 1 out of 3 (the only chance to win with this strategy is to choose correctly and stay) Switch: 2 out of 3 (the only chance to lose with this strategy is to choose correctly and...
Western Michigan >> STAT >> 160 (Fall, 2008)
Stat1600 1. The tree diagram shows: Partial Solution to Group Activity #5 3/6 O 3/6 E 3/6 3/6 O q 3/6 E 3/6 O 3/6 E 3/6 E 3/6 3/6 O O3/6 E 3/6 3/6 3/6 EO EO 3 3 3 P(B) = P(A) = 3 6 6 6 (a) P (A) = 3 (b) B is equivalent to A, so P (B) = 3...
Western Michigan >> STAT >> 560 (Fall, 2009)
Stat560 Solution to HW#3 P ROBLEM 1 (4.12 ) Denote (x, y) a player holds up x ngers and guesses the opponent holds up y ngers. a. The amount the player collect can be tabulated as following according to his and his opponents hold-guess combinations...
Western Michigan >> STAT >> 560 (Fall, 2009)
Stat560 Solution to HW#1 P ROBLEM 1 (1.4 ) 4! = 24 without restriction; 2!2! = 4 with restriction. P ROBLEM 2 (1.7 ) a. 6! = 720. b. 2 (3! 3!) = 72. c. 4! 3! = 144. d. 2 (3! 3!) = 72. P ROBLEM 3 (1.8 ) c. There are 4 Ss, 4 Is, 2 Ps, and 1 M. T...
Jackson State >> FORM >> 1 (Fall, 2009)
Reproductive History Form ID NUMBER: LAST NAME: CONTACT YEAR: 0 1 FORM CODE: RHX VERSION A 11/29/2000 INITIALS: INSTRUCTIONS: This form should be completed for FEMALE participants only. It should be completed during the interview portion of the par...
Jackson State >> FORM >> 2 (Fall, 2009)
COHORT EVENT ELIGIBILITY FORM INSTRUCTIONS, CEL, VERSION A, 12/09/1999 PREPARED 01/31/2000 I. General Instructions The Cohort Event Eligibility Form is completed during the participant\'s clinic visit. The technician must be certified and should have...
Jackson State >> FORM >> 1 (Fall, 2009)
Medication Survey Form FORM CODE: MSR ID NUMBER: LAST NAME: CONTACT YEAR: 0 1 VERSION A 09/25/2000 INITIALS: INSTRUCTIONS: This form is completed during the participants clinic visit in several stages by appropriately trained persons at the wo...
Jackson State >> FORM >> 1 (Fall, 2009)
Personal and Family Health History Form FORM CODE: PFH ID NUMBER: LAST NAME: CONTACT YEAR: 0 1 VERSION A 10/06/2000 INITIALS: I would like to ask you a few questions about your health and that of your parents. 1. Compared to other people your ...
Jackson State >> FORM >> 1 (Fall, 2009)
Hassles and Moods B ID NUMBER: LAST NAME: CONTACT YEAR: INITIALS: FORM CODE: CES VERSION A 08/08/2000 Circle the number for each statement which best describes how often you felt this way during the past week. Occasionally or a Moderate Amount of th...
Jackson State >> FORM >> 1 (Fall, 2009)
Hassles and Moods C ID NUMBER: LAST NAME: CONTACT YEAR: INITIALS: FORM CODE: CHO VERSION A 08/08/2000 For each of the following items, please indicate whether the statement is mostly true or mostly false for you. TRUE 1. I have had to take orders fr...
Jackson State >> FORM >> 1 (Fall, 2009)
Stress FORM CODE: STS VERSION A 05/03/2000 ID NUMBER: LAST NAME: CONTACT YEAR: 0 1 INITIALS: We are interested in the amount of stress that you have experienced over the past 12 months. Over the past 12 months, how much stress did you experienc...
Jackson State >> FORM >> 1 (Fall, 2009)
1 Alphabetic List of Variables and Attributes # Variable 3 ENTRY_DATETIME 2 ENTRY_ID 20 FTRA1 21 FTRA2 15 FTRA5 16 FTRA6 17 FTRA7 18 FTRA8 10 FTRA3A 11 FTRA3B 12 FTRA4A 13 FTRA4B 14 FTRA4C 19 FTRAflag 9 INITIALS 8 LASTNAME 6 PAGE 7 PAGREPEAT 1 STATU...
Jackson State >> FORM >> 1 (Fall, 2009)
Fasting Form ID NUMBER: LAST NAME: CONTACT YEAR: 0 1 FORM CODE: FTR VERSION A 09/22/2000 INITIALS: INSTRUCTIONS: This form is to be completed during the participants clinic visit. ID Number, Contact Year, and Name must be entered above. Whenever nu...
Jackson State >> FORM >> 1 (Fall, 2009)
Anthropometry Form ID NUMBER: LAST NAME: CONTACT YEAR: 0 1 FORM CODE: ANT VERSION A 09/25/2000 INITIALS: INSTRUCTIONS: This form is to be completed during the participants clinic visit. ID Number, Contact Year, and Name must be entered above. Whene...
Jackson State >> FORM >> 1 (Fall, 2009)
Health Practices: Tobacco Use FORM CODE: TOB ID NUMBER: LAST NAME: CONTACT YEAR: 0 1 VERSION A 07/05/2000 INITIALS: Now I have a series of questions about your health habits. These first questions will be about tobacco use. 1. Have you smoked...
Cornell >> INFO >> 2040 (Spring, 2009)
Networks: Spring 2009 David Easley and Jon Kleinberg Homework 1 Due in Class February 4, 2009 Homework will be due at the start of class on the due date. We cannot accept late homework except for University-approved excuses (which include illness w...
What are you waiting for?