CSC302 2007S, Class 06: Hoare's Examples Admin: * Assigned: Homework 3: Removing Recursion. * Due: Homework 2: Permutation with Repetitions. * I do not have Wednesday's reading yet. Sorry. * Grr ... few reflections on Hoare, revisited. Overview: * Examples from Hoare. * Choosing a language. * Key design criteria. * More notes from the readings. /Examples from Hoare/ //Fortran Syntax// DO 17 I = 1,10 vs. DO 17 I = 1 10 vs. DO17I = 110 Moral: Ignoring whitespace is bad. //Case Statement// switch SS = L1,L2,L3; ... go to SS[i]; L1: Q1; goto L; L2: Q2; goto L; L3: Q3; L: case i { Q1, Q2, Q3 } //Assignment in Algol// x := y; ALWAYS changes X x := y+1; NEVER changes X, if X is a reference variable problem 1: we have pointers explicit in the language critique of coercion: int i; float f; ... f = i * 2; Fun in C char *c; c = 1; printf("%s", c); In algol, c := 1 interpreted as ... * Store 1 in the thing c points to In algol, x := y+1 interpreted as * Store the sum of y and 1 in the thing c points to /Detour on Coercion/ * What are the numeric coercion rules in C/Java * Types: int,long,float,double * Operation: Assignment i = l; // Won't accept; need to cast b/c possible loss of info i = f; // Won't accept; need to cast. b/c possible loss of info i = d; // Won't accept; need to cast b/c possible loss of info l = i; l = f; l = d; f = i; // Probably won't have to cast b/c no loss of info f = l; // Probably won't have to cast b/c no loss of info f = d; d = i; d = l; d = f; /Last Hoare Example/ Suppose matrixmuliply(X,Y,Z) means "X = Y * Z" matrximultiply(A,A,A) Problem is "Aliasing"