CA341 - Comparative Programming Languages

Size: px
Start display at page:

Download "CA341 - Comparative Programming Languages"

Transcription

1 CA341 - Comparative Programming Languages and David Sinclair Data, Values and Types In 1976 Niklaus Wirth (inventor of Pascal, Modula, Oberon, etc) wrote a book called Algorithms + Data Structures = Programs which is one of the most influential books on programming and computer science. Data, how we store it and manipulate it, is at the heart of any computer program. A value is any entity that can be manipulated by a program. It can be evaluated, stored, passed as a parameter to a function or procedure and returned from a function. Different languages support different kinds of values.

2 Types and Operations Most programming languages group values in to types. A type is a set of values. Hence, if we say that v is a value of type T, we are simply saying v T. If an expression E is of type T, the we are saying that the result of evaluating E is a value of type T. We place one restriction of the kind of sets that can be used to form types. Each operation associated with a type must act uniformly when applied to all values of the type. {..., 2, 1,0,1,2,...} is a type since addition, subtraction, multiplication, etc., can be applied uniformly over all the values. {false, true} is a type since conjunction, disjunction and negation can be applied uniformly over all the values. {false,13,sunday} is not a type since there are no operations that can be applied uniformly to the values of this set. Types are sets that defined by the values the set contains and the operations on these values. Primitive Types A primitive value is one that cannot be decomposed into simpler values. A primitive type is a set of primitive values with a set of uniform operations. Every programming language has built-in primitive types, and some languages allow the user to define new primitive types. Depending on the targeted application domain, different languages support different built-in primitive types. Languages aimed at the commercial data processing domain (such as Cobol) have built-in primitive types that support fixed length string and fixed-point numbers. Languages aimed at scientific computations (such as FORTRAN) tend to have built-in types that support real numbers (possibly of arbitrary precision) and complex numbers. Languages aimed at string processing (such as Snobol) have built-in types that support arbitrary length strings.

3 Primitive Types (2) The most common built-in types are Boolean, Character, Integer and Floating, though they have different type names among the different programming languages. The Boolean type has 2 values, either denoted by the literals true and false, or by predefined values (e.g. in C, 0 is false and any non-zero numeric value is true). The Character type is a language defined or implementation defined set of characters, typically ASCII (128 characters), ISO Latin (256 characters) or UNICODE (65,536 characters). The Integer type is a language defined or implementation defined range of whole numbers, typically defined by the target computer s word size and integer arithmetic capabilities. On a 32-bit machine with 2s complement arithmetic, the range is { 2,147,483,648,...,0,...,+2,147,483,647}. Primitive Types (3) The Floating type is a language defined or implementation defined subset of real numbers. The range and precision is determined by the target computer s word size and floating-point arithmetic capabilities. The Character, Integer and Floating types are usually implementation-defined, however some languages, such as Java, precisely defines all its types. The cardinality of a type T, denoted #T, is the number of distinct values in the type. For example, #Boolean = 2. Not all languages have distinct Boolean and Character types. In C++, the Boolean type bool is actually just small numbers. Similarly, in C, C++ and Java the Character type char are just small integers. There is no difference between character A and the value 65.

4 Primitive Types (4) Many languages have different sizes of integers. They even have the same names, such as short, int and long in Java, C and C++. But be very careful! Consider the following Java snippet. int countrypop ; long worldpop; While this is fine for Java, since no country at the moment has a population more that 2 billion, the same declarations in C/C++ would generally cause a problem as the int type in C/C++ only ranges up to 32,767 on a 16-bit machine. On a 32-bit machine an int might range up to 2,147,483,647, but it is implementation specific and not covered by the language standard. Primitive Types (5) Some languages allow the programmer to define the ranges of integer and floating-point types to avoid the type of portability issues we have just seen. type Popoulation is range 0.. 1e10 ; countrypop : Population ; worldpop: Population ; Aside: What is #Population? Ada also allows a programmer to define a new primitive type by completely enumerating the identifiers denotes its values. This is called an enumeration type and its values are called enumerands. type Month is (jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec );

5 Primitive Types (6) A discrete primitive type has a one-to-one mapping with the range of integers. In Ada, the types Boolean, Character and enumerated types are discrete primitive types. This can be very useful. freq : array( Character ) of Natural ; for ch in Character loop freq (ch) := 0; end loop ; type Month is (jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec ); length : array(month) of Natural := (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); for mth in Month loop put( length (mth)); end loop ; Composite Types A composite value is a value composed from simpler values. It is a fancy name for a data structure. A composite type is a type whose values are composite values. The variety of composite types among different programming languages is vast, but we can group them into the following categories. Cartesian products such as tuples and records. Mappings such as arrays. Disjoint unions such as algebraic types, discriminated records and objects. Recursive types such as lists and trees.

6 Cartesian Products In a Cartesian product, the values from several types are grouped into a tuples. The notation (x,y) denotes a pair whose first value is x and second value is y. We can use the same notation to represent a triple, (x,(y,z)), an extend it further to represent any size tuple. The notation S T represents the set of all pairs. S T = {(x,y) x S,y T} The basic operations on pairs are: construction of a pair from its values selection of either the first (fst) or second (snd) component of the pair. The cardinality of a Cartesian product S T is #(S T) = #S #T Cartesian Products (2) C++ structures can be understood in terms of Cartesian products. enum Month {jan, feb,mar, apr, may, jun, jul, aug, sep, oct, nov, dec}; struct Date { Month m; byte d; }; This structure type has the values: Date = Month byte = {jan,feb,...,nov,dec} {0,1,...,255} The following code snippets show the construction and selection operations. struct Date today = {sep, 12}; printf ( %d%d, today.m+1, today.d); today.m = mar; today.d = 17;

7 Cartesian Products (3) Ada s records are another example of Cartesian products. type Month is (jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec ); type DayNumber is range ; type Date is record m: Month; d: DayNumber; end record ; The following code snippets show the construction and selection operations. today : Date := (m => sep, d => 12); put(today.d); put( / ); put(today.d); today.m := mar; today.d := 17; Cartesian Products (4) A special case of Cartesian products is when all the tuple components are from the same set. In these cases the tuples are said to be homogeneous. For pairs and more generally: The cardinality is: S 2 = S S S n = S S... S #(S n ) = #S #S... #S = (#S) n The special case of n = 0, says the cardinality of S 0 is 1, the empty tuple Unit. Unit corresponds to the type void in C, C++ and Java; and to type null record in Ada.

8 Mappings The concept of a mapping from one set to another set is very important in programming languages and underlies to important features in programming languages, arrays and functions. The notation m : S T represents a mapping m from set S to set T, i.e. every value in S is mapped to a value in T. If m maps the value x in S to the value y in T, we write y = m(x), and say that y is the image of x under m. The notation S T represents the set of all mapping from S to T. S T = {m x S m(x) T} The cardinality of a mapping is Mappings (2) #(S T) = (#T) #S since each element of S has #T possible values and there are #S of these values in S. An array is an indexed sequence of elements with one element of T for each index (from S). Also the index is finite, so therefore, an array is of type S T and is a finite mapping. Usually the elements of S are consecutive and have a lower bound and an upper bound. The basic operation on arrays are: construction of an array from its elements indexing which selects an given element from an array based on its index.

9 Mappings (3) In C++, an array s index must be integer whose lower bound is 0. The C++ declaration bool flags [3]; is a mapping {0,1,2} {true,false}. The following code snippets show the construction and indexing operations. bool flags = {true, false, true }; flags [ i ] = flags [ i ] & flags [ i 1]; Arrays in Java looks similar in that they have integer indexes whose lower bound is 0, but in fact they are actually objects. Arrays in Python are actually lists that can contain mixed datatypes and hence are not mappings. Multi-dimensional arrays in Python are lists of lists, and hence can be jagged, i.e. each row can be of different sizes. Mappings (4) Arrays in Ada are more flexible than C, C++ and Java in that the index range can be chosen by the programmer and the only restriction on the type of the index is that it is a discrete primitive type. For example, type Colour is (red, green, blue ); type Pixel is array (Colour ) of Boolean ; Hence, Pixel : Colour Boolean Pixel : {red,green,blue} {true,false} and the operations of construction and indexing are implemented as: p1: Pixel := (red => false, green => true, blue => true ); p2: Pixel := (true, false, false ); p1( i ) := not p2( i );

10 Mappings (5) Many programming languages support multi-dimensional arrays. We can think of multi-dimensional arrays as having a single index that is a tuple. Hence, a multi-dimensional array is a mapping from a tuple to a set of values. The following Ada 2-dimensional array type XRange is range ; type YRange is range ; type Window is array (XRange, YRange) of Pixel ; is the mapping Window : {{1,...,512} {1,...,256}} {true,false} Window : {(1,1),(1,2),...,(512,255),(512,256)} {true,false} Mappings (6) Function procedures, supported by some programming languages, are also mappings. For example, in C++ bool is even ( int i ) { return ( i % 2 == 0); } is a mapping Integer Boolean. Even if we change the implementation of is even, it still is the same mapping. Functions with multiple parameters are mappings from a tuple to a set of possible return values. The C++ function float power ( float x, int i ) {... } is a mapping Floating Integer Floating, e.g. (3.0,2) 9.0 and (1.5,3)

11 Disjoint Unions In a disjoint union a value is selected from one of several, possibly different, sets. Let the notation S + T represent the disjoint union of sets S and T. Each element of S +T consists of a tag which identifies which original set the element came from and a variant which is the value from the original set. left S +right T = {left x x S} {right y y T} Where the tags are irrelevant we can leave them out. S +T = {left x x S} {right y y T} The cardinality of a disjoint union is #(S +T) = #S +#T Disjoint Unions (2) The basic operations on disjoint unions are: construction by appropriately tagging each element from both sets. tag test to determine if a variant was from S or T. projection to recover the variant is S or the variant in T. Disjoint unions can be used to understand Haskell s algebraic types, Ada s discriminated records, the set of objects in a Java program and C s unions when declared inside structures.

12 Disjoint Unions (3) Algebraic types in Haskell are declared as follows: data Number = Exact Integer Inexact Float The following code snippet illustrated construction. let pi = Inexact in... The following code snippet illustrated tag test and projection. rounded num = case num of Exact i => i Inexact i => round i round pi will result in the value 3. Disjoint Unions (4) Discriminated records in Ada can be modelled as disjoint unions. type Form is (point, circle, rectangle ); type Figure ( f : Form) is record x, y: Float case f is when point => null ; when circle => r : Float ; when rectangle => w, h: Float end case ; end record ; Figure = point(floating Floating) + circle(floating Floating Floating) +rectangle(floating Floating Floating Floating) Examples are point(2.0, 3.0), circle(0.0, 1.0, 0.5) and rectangle(0.0, 0.0, 3.0, 2.0).

13 Disjoint Unions (5) Consider the following class declarations. class Point { float x, y; }... // methods class Circle extends Point { float radius ; }... // methods class Rectangle extends Point { float width, height ; }... // methods Disjoint Unions (6) The set of objects in this Java program is: Point(Floating Floating) +Circle(Floating Floating Floating) +Rectangle(Floating Floating Floating Floating) +... The +... represents that additional classes can be declared later in the Java program. C unions in themselves are not disjoint unions as there is no tags. Typically C programmers declared unions inside structures, and this can be modelled by disjoint unions. enum Accuracy {exact, inexact }; struct Number { Accuracy acc ; union { int i ; / used when acc = exact / float f ; / used when acc = inexact / } content ; };

14 Recursive Types A recursive type is a type that is defined in terms of itself. The typical recursive types that occur in programming languages are lists and strings. Lists A list a sequence of values. If all the elements of a list are the same type the list is homogeneous, otherwise it is hetrogeneous. The number of elements in a list is called its length. A list with no elements is an empty list. The typical operation on a list are: construction, add a new element as the head of the new list length empty test head selection, select the list s first element tail selection, select all the list other than the first element concatenation, joining two lists Lists In some programming languages lists are called sequences. The equation for finite lists of type T is: T = Unit +(T T ) For integer lists the set of values is: {nil} {cons(i,nil) i Integer} {cons(i,cons(j,nil)) i,j Integer} {cons(i,cons(j,cons(k,nil))) i,j,k Integer} +... In imperative programming languages, like C, C++ and Ada, recursive type are implemented using pointers, but in functional and some object-oriented programming languages, they can be define and implemented directly.

15 An example of Java lists is: class IntList { public IntNode first ; Lists (2) } public IntList (IntNode firtst ) { this. first = first ; } class IntNode { public int elem ; public IntNode succ ; } public IntNode ( int elem, IntNode succ) { this. elem = elem ; this. succ = succ ; } IntList primes = new IntList ( new IntNode (2, new IntNode (3, new IntNode (5, null )))); Lists (3) Haskell has a built-in list type, e.g. [] [1] [1,2,3] but if it didn t, we could define integer lists as data IntList = Nil Cons Int IntList and the above lists can be written as Nil Cons 1 Nil Cons 1 (Cons 2 (Cons 3 Nil ))

16 Strings A string is a sequence of characters. The number of characters in a string is the length of the string. A string with no characters is called the empty string. The typical string operations are: length equality test lexicographical comparison in order to order two strings character selection substring selection concatenation, joining two strings Strings (2) There is no common way to represent strings among the different programming languages. Some languages treat strings as a built-in type and therefore must provide basic string operations. ML adopts this approach. Some programming languages treat strings as an array of characters. The standard array operations, such as index selection, can be applied to strings. Usually common string operations are also provided, e.g. lexicographical comparison. A consequence of this approach is that, once constructed, the string is of fixed-length. Ada adopts this approach. A slightly more versatile approach is to represent a string as a pointer to a character array. This is the approach that C and C++ adopt.

17 Strings (3) In languages that have built-in support for lists, a common approach is to represent a string as a list of characters. Using this approach means that the standard list operations can be applied to strings. This approach is adopted by Python, Haskell and Prolog. Object-oriented languages, such as Java, treat string as objects. These string object have methods that implement all the string operations. General Recursive Types Some languages, such as Haskell, support general recursive types. These are defined by the set equation: R =...+(...R...R) Recursive set equations can have many solutions, but we are just interested in the least solution which is built by starting with R equal to the empty set and solving for R, and then plugging this new value for R back into the equation to get a better approximation. We keep repeating this to get better and better approximations of R. In general, the cardinality of a recursive type is infinite, even though the elements of the recursive type are finite.

18 General Recursive Types (2) Binary Trees in Haskell data BinIntTree = Empty BinIntTree Int BinIntTree BinIntTree BinIntTree 8 Empty Empty BinIntTree 8 ( BinIntTree 5 Empty Empty) ( BinIntTree 12 ( BinIntTree 10 Empty Empty) ( BinIntTree 14 ( BinIntTree 12 Empty Empty ) Empty ) ) Type Systems A type system allows a programming language to group values into types. A type system prevent a programmer from performing stupid operations such as multiplying a string by a boolean. Such operations will generate a type error. In a statically typed language each variable and expression has a fixed type. This type is either explicitly defined or inferred, but before every operation the complier can check that the operand have the correct type at compile time. In a dynamically typed language, values are typed, but variables and expressions are not. Every time an operand is computed it may result in a value of a different type. Therefore, operands can only be type checked at run time as they are computed but before the operation is performed. Most high-level languages are statically typed. Python, Prolog, Lisp, Perl and Smalltalk are dynamically typed.

19 Type Systems (2) Static typing is: More efficient than dynamic typing. Dynamic typing requires (possibly repeated) run time checks of all operands each time an operation/procedure is invoked, for example in a loop. This slows down execution. Also all values have to be tagged with their type and this requires additional memory storage. More secure. A compiler can verify that a program has no type errors. Type errors are responsible for a significant proportion of programming errors. Dynamic typing is: More flexible and necessary in applications where the type of the data is not known in advance. Type Systems (3) Python s dynamic typing in action. def respond (prompt) try : response = raw input (prompt) return int ( response ) except ValueError : return response m = respond ( Enter month: )... if m = Jan : m = 1... if m = Dec : m = 12 elif! ( isinstance (m, int ) and 1 <= m <= 12): raise DataError, month is not valid string or value

20 Type Equivalance In order to type check, we need to ask if the types of two operands, T 1 and T 2 are equivalent. There are two commonly used definitions of type equivalence. name equivalence structural equivalence T 1 is name equivalent to T 2, T 1 T 2, if T 1 and T 2 are defined in the same place. struct Date {int d, m}; struct Date yesterday ; struct Date today, tomorrow ; The variables today, yesterday and tomorrow are name equivalent in most languages. In some languages, today and tomorrow are name equivalent, though today and yesterday are not as they are defined on different lines. Java and Ada use name equivalence. Type Equivalance (2) T 1 is structurally equivalent to T 2, T 1 T 2, if T 1 and T 2 consist of the same components. struct Date {int d, m}; struct OtherDate {int d, m}; struct OtherDate yesterday ; struct Date today, tomorrow ; The variables today, yesterday and tomorrow are structurally equivalent. Algol-68, ML, C and Modula-3 use structural equivalance.

21 Expressions An expression is a programming construct that evaluates to a value. A literal denotes a fixed value of some type. For example, 2.5, false and "hello" denote a real number, a boolean and a string. A construction is an expression that build a composite value from its components. C++ structure construction enum Month {jan, feb,mar, apr, may, jun, jul, aug, sep, oct, nov, dec}; struct Date { Month m; byte d; }; struct Date today = {mar, 17}; Expressions (2) Ada array construction size : array (Month) of Integer := (feb => 28, apr jun sep nov => 30, others => 31); Haskell list construction [31, if isleapyear (year ) then 29 else 28, 31, 30, 31, 30, 31, 31, 30, 31] C++ constructions are limited in that they can only occur as initialisers in a variable declaration and the components must be literals. Java objects have a construction called the constructor and it is invoked by the new command.

22 Expressions (3) A function call, F(E), is an expression. In languages where functions are first-class values, F may be any expression that results in a function. For example in Haskell ( if... then sin else cos) (x) Operator can be thought of as denoting functions. E 1 E 2 is essentially (E 1,E 2 ) where is a binary operator. E 1 E 2 is infix notation adopted by most programming languages, and (E 1,E 2 ) is prefix notation adopted by Lisp. Some modern languages, such as C++, Ada and Haskell, recognise that E 1 E 2 is exactly equivalent to (E 1,E 2 ) and allow the programmer to write functions that define and redefine operators. Expressions (4) A conditional expression is an expression whose value depends on a condition. Examples of this are if-expressions in C, C++, Java and Haskell, and case-expression in Haskell. x > y? x : y; case month of feb > if isleapyear (year ) then 29 else 28 apr > 30 jun > 30 sep > 30 nov > 30 > 31 An iterative expression performs a computation of a series of values. In Haskell, list comprehension is an example of an iterative expression. [y y < ys, y mod 100 = 0]

23 Expressions (5) A reference to a named constant or named variable is a constant access or variable access expression. In both cases the reference results in the value of the constant or the current value of the variable. For example in Ada, pi : constant Float := ; r : Float ; area := 2 pi r evaluates the expression 2 * pi * r. The exact value that this expression will evaluate to depends on the environment of the expression. Bindings and Environments A binding is a fixed association between an identifier and a variable, value or procedure. An environment (also called a namespace) is a set of bindings. Consider the following Ada program snippet. procedure p is z: constant Integer := 0; c : Character ; procedure q is c: constant Float := 3.0e 02; b: Boolean ; begin.. (2) end q; begin... (1) end p;

24 Bindings and Environments (2) At point (1) the environment is: c: a character variable p: a procedure q: a procedure z: an integer 0 At point (2) the environment is: b: a boolean variable c: a real number 3.0e-02 p: a procedure q: a procedure z: an integer 0 Bindings and Environments (3) A bindable entity is one that can be bound to an identifier. Languages differ in what is bindable. C Java Ada types values types variables local variables values function procedures instance variables variables class variables procedures methods exceptions classes packages packages tasks

25 The scope of a declaration is the portion of the programme text over which the declaration is in effect. The scope of a binding is the portion of the programme text over which the binding is applied. In early programming languages the scope of a declaration was the whole programme. This meant writing large programmes was very awkward as every declared variable has to have a unique name. Modern programming languages limited the influence of a declaration or variable by introducing syntactic structures called blocks. Blocks A block is a construct that delimits the scope of any declaration within it. In C, the blocks are block commands ({... }), function bodies, compilation units (source files) and the whole programme itself. In Java, the blocks are block commands ({... }), method bodies, class declarations, packages and the whole programme itself. In Python, the blocks are modules, function bodies and class definitions. In Ada, blocks are block commands (declare... begin... end), procedure bodies, packages, tasks, protected objects and the whole programme itself.

26 Blocks (2) When the whole programme is the only block, the programme is said to have a monolithic block structure. Early versions of Cobol are examples of languages with monolithic block structure where every declaration is global. In languages with a flat block structure the programme is partitioned in several non-overlapping blocks. If a variable is declared in a block, its scope that block. The scope of each global variable and each procedure is the whole program. FORTRAN is an example of a flat block structure language. In a language with a nested block structure, blocks may be nested within other blocks. This is typical of Algol-like languages. C has a restricted form of nested block structure in which function bodies cannot overlap. Java allows method bodies and inner classes to be nested within a class. Ada has a truly unrestricted nested block structure. Blocks (3) declaration of x declaration of y declaration of z declaration of x declaration of y declaration of x declaration of y declaration of z declaration of z monolithic block flat block nested block

27 Visibility When an identifier I is bound to some entity X, then there is a binding occurrence of I. In the following Ada snippet: n: constant Integer := 7; the declaration of identifier n is a binding occurrence of n. When an entity X is used to which an identifier I is bound, then there is an applied occurrence of I. For each such applied occurrence we say I denotes X. In the following subsequent Ada snippet: sum := n (n 1)/2 both references to identifier n are applied occurrences of n, where n denotes 7. In a program with multiple blocks the same identifier I can be declared in multiple blocks and I will denote a different entity in each block. Visibility (2) When the same identifier, I, is declared in two nested blocks, then any applied occurrence of I in the inner block refers to the declaration of I in the inner block and not the declaration of I from the outer block. The outer declaration of I is said to be hidden by the inner declaration of I. declaration of x scope of outer declaration of x excluding the inner block declaration of x scope of inner declaration of x

28 Static vs. Dynamic Scoping A language is statically scoped if the body of a procedure is executed in the environment of the procedure s definition. Hence, we can determine the binding occurrence that corresponds to every applied occurrence of an identifier by simply examining the program s source code. A language is dynamically scoped if the body of a procedure is executed in the environment of the procedure s invocation. This environment may vary from one procedure call to another procedure call. Hence, we cannot determine which binding occurrence corresponds to each applied occurrence until run-time. Languages with dynamic scoping cannot have static typing. Most languages are statically scoped, and the few that are dynamically scoped, such as Smalltalk, have dynamic typing. Dynamic scoping tends to make programmes harder to understand and maintain. Declarations A declaration produces a binding between an identifier and an entity. Some declarations create variables. A definition is a declaration that only produces a binding. A type declaration binds an identifier to a type. There are two type of type declaration: type definition that binds an identifier to an existing type new-type declaration that binds an identifier to a new type that is not equivalent to an existing type. In C/C++ typedef char Alpha ; is a type definition as it binds Alpha to the existing type char*. Whereas, struct,enum and union are new-type declarations as they bind to new types struct Book (Alpha title, int edn}; struct Author {Alpha name, int age };

29 Declarations (2) Because Ada strictly uses name equivalence, all type declarations are new-type declarations. A constant declaration binds an identifier to a constant. They are usually of the form const I = E which binds I to the expression E (with the type if I being the type of E), or they are of the form const I T = E in which the type of I is specifically set to T. Modern languages (such as C++, Java and Ada) allow E to be evaluated at run-time. A variable declaration creates a variable and binds an identifier to that variable. Most languages allow a declaration to create several variables and bind different identifiers to them. Ada allows a variable renaming definition that binds an identifier to an exiting variable, creating an alias for the variable. pop: Integer renames population (country ); Declarations (3) A procedure definition binds an identifier to a procedure (function procedure or proper procedure). bool even ( int n) { return (n % 2 == 0); } void double ( int& n) { n = 2; return ; }

30 Composing Declarations A sequential declaration composes sub-declarations one after another. count : Integer := 0; procedure inc count is begin count := count + 1; end; A collateral declaration composes sub-declarations that are independent of each other and cannot be used until the declaration is complete. val e = and pi = ; Composing Declarations (2) A recursive declaration uses bindings that it itself has produced. Recursive declarations are not support by older languages as they were inefficient on early hardware, but they are support by most modern languages. The scope of a recursive declaration starts at the beginning of the declaration and ends with the enclosing block. void print decimal ( int n) { if (n < 0) { print ( ); print decimal ( n); } else if (n >= 10) { print decimal (n/10); print (n % ); } else print (n + 0 ); }

31 Blocks Again A block command is a command that contains a local declaration D (or a group of declarations) and a subcommand C. The binding produced by D are only in effect for the execution of C. In C/C++, a block command is {D C}. In Ada a block command is declare D begin C end. In Java, we have: if (x > y) { int z = x; x = y; y = z; } Blocks Again (2) A block expression is an expression that contains a local declaration D (or a group of declarations) and a subexpression E. The binding produced by D are only in effect for the evaluation of E. Haskell has a block expression of the form let D in E. Th calculate the area of a triangle whose sides are of length a, b and c, we can use the follow Haskell code snippet. let s = (a + b + c)/2.0 in sqrt (s (s a) (s b) (s c))

4 Bindings and Scope. Bindings and environments. Scope, block structure, and visibility. Declarations. Blocks. 2004, D.A. Watt, University of Glasgow

4 Bindings and Scope. Bindings and environments. Scope, block structure, and visibility. Declarations. Blocks. 2004, D.A. Watt, University of Glasgow 4 Bindings and Scope Bindings and environments. Scope, block structure, and visibility. Declarations. Blocks. 2004, D.A. Watt, University of Glasgow 1 Bindings and environments PL expressions and commands

More information

Example: Haskell algebraic data types (1)

Example: Haskell algebraic data types (1) Example: Haskell algebraic data types (1) Type declaration: data Number = Exact Int Inexact Float Set of values: Each Number value consists of a tag, together with either an Integer variant (if the tag

More information

Questions? Static Semantics. Static Semantics. Static Semantics. Next week on Wednesday (5 th of October) no

Questions? Static Semantics. Static Semantics. Static Semantics. Next week on Wednesday (5 th of October) no Questions? First exercise is online: http://www.win.tue.nl/~mvdbrand/courses/glt/1112/ Deadline 17 th of October Next week on Wednesday (5 th of October) no lectures!!! Primitive types Primitive value

More information

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011 Data Types (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011 Based in part on slides and notes by Bjoern 1 Brandenburg, S. Olivier and A. Block. 1 Data Types Hardware-level:

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp- 14/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 23! Type systems Type safety Type checking Equivalence,

More information

Storage. Outline. Variables and Updating. Composite Variables. Storables Lifetime : Programming Languages. Course slides - Storage

Storage. Outline. Variables and Updating. Composite Variables. Storables Lifetime : Programming Languages. Course slides - Storage Storage 1 Variables and Updating Outline Composite Variables Total and selective updating Array variables Storables Lifetime Local and global variables Heap variables Persistent variables Garbage collection

More information

CPSC 3740 Programming Languages University of Lethbridge. Data Types

CPSC 3740 Programming Languages University of Lethbridge. Data Types Data Types A data type defines a collection of data values and a set of predefined operations on those values Some languages allow user to define additional types Useful for error detection through type

More information

Topic 7: Algebraic Data Types

Topic 7: Algebraic Data Types Topic 7: Algebraic Data Types 1 Recommended Exercises and Readings From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 5.5, 5.7, 5.8, 5.10, 5.11, 5.12, 5.14 14.4, 14.5, 14.6 14.9, 14.11,

More information

Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types

Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types Chapter 6 Topics WEEK E FOUR Data Types Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer and Reference

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing

More information

Functional Programming Languages (FPL)

Functional Programming Languages (FPL) Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional

More information

22c:111 Programming Language Concepts. Fall Types I

22c:111 Programming Language Concepts. Fall Types I 22c:111 Programming Language Concepts Fall 2008 Types I Copyright 2007-08, The McGraw-Hill Company and Cesare Tinelli. These notes were originally developed by Allen Tucker, Robert Noonan and modified

More information

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result. Every program uses data, either explicitly or implicitly to arrive at a result. Data in a program is collected into data structures, and is manipulated by algorithms. Algorithms + Data Structures = Programs

More information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts

More information

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc. CSC312 Principles of Programming Languages : Functional Programming Language Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:

More information

CS321 Languages and Compiler Design I Winter 2012 Lecture 13

CS321 Languages and Compiler Design I Winter 2012 Lecture 13 STATIC SEMANTICS Static Semantics are those aspects of a program s meaning that can be studied at at compile time (i.e., without running the program). Contrasts with Dynamic Semantics, which describe how

More information

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. 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 information

COS 140: Foundations of Computer Science

COS 140: Foundations of Computer Science COS 140: Foundations of Computer Science Variables and Primitive Data Types Fall 2017 Introduction 3 What is a variable?......................................................... 3 Variable attributes..........................................................

More information

Haskell 98 in short! CPSC 449 Principles of Programming Languages

Haskell 98 in short! CPSC 449 Principles of Programming Languages Haskell 98 in short! n Syntax and type inferencing similar to ML! n Strongly typed! n Allows for pattern matching in definitions! n Uses lazy evaluation" F definition of infinite lists possible! n Has

More information

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;

More information

TYPES, VALUES AND DECLARATIONS

TYPES, 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 information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\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 information

History. used in early Mac development notable systems in Pascal Skype TeX embedded systems

History. used in early Mac development notable systems in Pascal Skype TeX embedded systems Overview The Pascal Programming Language (with material from tutorialspoint.com) Background & History Features Hello, world! General Syntax Variables/Data Types Operators Conditional Statements Functions

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

Programming Languages Third Edition. Chapter 7 Basic Semantics

Programming Languages Third Edition. Chapter 7 Basic Semantics Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol

More information

SMURF Language Reference Manual Serial MUsic Represented as Functions

SMURF Language Reference Manual Serial MUsic Represented as Functions SMURF Language Reference Manual Serial MUsic Represented as Functions Richard Townsend, Lianne Lairmore, Lindsay Neubauer, Van Bui, Kuangya Zhai {rt2515, lel2143, lan2135, vb2363, kz2219}@columbia.edu

More information

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages 1 / 26 CSE 307: Principles of Programming Languages Names, Scopes, and Bindings R. Sekar 2 / 26 Topics Bindings 1. Bindings Bindings: Names and Attributes Names are a fundamental abstraction in languages

More information

LECTURE 18. Control Flow

LECTURE 18. Control Flow LECTURE 18 Control Flow CONTROL FLOW Sequencing: the execution of statements and evaluation of expressions is usually in the order in which they appear in a program text. Selection (or alternation): a

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Data Types The ML Type System

Data Types The ML Type System 7 Data Types 7.2.4 The ML Type System The following is an ML version of the tail-recursive Fibonacci function introduced Fibonacci function in ML in Section 6.6.1: EXAMPLE 7.96 1. fun fib (n) = 2. let

More information

CSC 533: Organization of Programming Languages. Spring 2005

CSC 533: Organization of Programming Languages. Spring 2005 CSC 533: Organization of Programming Languages Spring 2005 Language features and issues variables & bindings data types primitive complex/structured expressions & assignments control structures subprograms

More information

Programming Languages, Summary CSC419; Odelia Schwartz

Programming Languages, Summary CSC419; Odelia Schwartz Programming Languages, Summary CSC419; Odelia Schwartz Chapter 1 Topics Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design

More information

Types. What is a type?

Types. What is a type? Types What is a type? Type checking Type conversion Aggregates: strings, arrays, structures Enumeration types Subtypes Types, CS314 Fall 01 BGRyder 1 What is a type? A set of values and the valid operations

More information

Review of the C Programming Language

Review of the C Programming Language Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the

More information

Fundamentals of Programming Languages

Fundamentals of Programming Languages Fundamentals of Programming Languages 1. DEFINITIONS... 2 2. BUILT-IN TYPES AND PRIMITIVE TYPES... 3 TYPE COMPATIBILITY... 9 GENERIC TYPES... 14 MONOMORPHIC VERSUS POLYMORPHIC... 16 TYPE IMPLEMENTATION

More information

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996.

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996. References: Topic IV Block-structured procedural languages Algol and Pascal Chapters 5 and 7, of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Chapter 5 of Programming languages: Concepts

More information

LECTURE 16. Functional Programming

LECTURE 16. Functional Programming LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative

More information

Topic IV. Block-structured procedural languages Algol and Pascal. References:

Topic IV. Block-structured procedural languages Algol and Pascal. References: References: Topic IV Block-structured procedural languages Algol and Pascal Chapters 5 and 7, of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Chapters 10( 2) and 11( 1) of Programming

More information

Typed Racket: Racket with Static Types

Typed Racket: Racket with Static Types Typed Racket: Racket with Static Types Version 5.0.2 Sam Tobin-Hochstadt November 6, 2010 Typed Racket is a family of languages, each of which enforce that programs written in the language obey a type

More information

The Typed Racket Guide

The Typed Racket Guide The Typed Racket Guide Version 5.3.6 Sam Tobin-Hochstadt and Vincent St-Amour August 9, 2013 Typed Racket is a family of languages, each of which enforce

More information

F28PL1 Programming Languages. Lecture 11: Standard ML 1

F28PL1 Programming Languages. Lecture 11: Standard ML 1 F28PL1 Programming Languages Lecture 11: Standard ML 1 Imperative languages digital computers are concrete realisations of von Neumann machines stored program memory associations between addresses and

More information

Storage. Outline. Variables and updating. Copy vs. Ref semantics Lifetime. Dangling References Garbage collection

Storage. Outline. Variables and updating. Copy vs. Ref semantics Lifetime. Dangling References Garbage collection Storage 1 Variables and updating Outline Copy vs. Ref semantics Lifetime Local and global variables Heap variables Persistent variables Dangling References Garbage collection 2 Variables and Updating Variable:

More information

COS 140: Foundations of Computer Science

COS 140: Foundations of Computer Science COS 140: Foundations of Variables and Primitive Data Types Fall 2017 Copyright c 2002 2017 UMaine School of Computing and Information S 1 / 29 Homework Reading: Chapter 16 Homework: Exercises at end of

More information

COSE212: Programming Languages. Lecture 3 Functional Programming in OCaml

COSE212: Programming Languages. Lecture 3 Functional Programming in OCaml COSE212: Programming Languages Lecture 3 Functional Programming in OCaml Hakjoo Oh 2017 Fall Hakjoo Oh COSE212 2017 Fall, Lecture 3 September 18, 2017 1 / 44 Why learn ML? Learning ML is a good way of

More information

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University G22.2110-001 Programming Languages Spring 2010 Lecture 6 Robert Grimm, New York University 1 Review Last week Function Languages Lambda Calculus SCHEME review 2 Outline Promises, promises, promises Types,

More information

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5 C++ Data Types Contents 1 Simple C++ Data Types 2 2 Quick Note About Representations 3 3 Numeric Types 4 3.1 Integers (whole numbers)............................................ 4 3.2 Decimal Numbers.................................................

More information

Functional Programming and Haskell

Functional Programming and Haskell Functional Programming and Haskell Tim Dawborn University of Sydney, Australia School of Information Technologies Tim Dawborn Functional Programming and Haskell 1/22 What are Programming Paradigms? A programming

More information

RSL Reference Manual

RSL Reference Manual RSL Reference Manual Part No.: Date: April 6, 1990 Original Authors: Klaus Havelund, Anne Haxthausen Copyright c 1990 Computer Resources International A/S This document is issued on a restricted basis

More information

Syntax and Variables

Syntax and Variables Syntax and Variables What the Compiler needs to understand your program, and managing data 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line

More information

Motivation was to facilitate development of systems software, especially OS development.

Motivation was to facilitate development of systems software, especially OS development. A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.

More information

The story so far. Elements of Programming Languages. Pairs in various languages. Pairs

The story so far. Elements of Programming Languages. Pairs in various languages. Pairs Elements of Programming Languages Lecture 6: Data structures James Cheney University of Edinburgh October 9, 2017 The story so far We ve now covered the main ingredients of any programming language: Abstract

More information

Names, Scopes, and Bindings II. Hwansoo Han

Names, Scopes, and Bindings II. Hwansoo Han Names, Scopes, and Bindings II Hwansoo Han Scope Rules A scope is textual region where bindings are active A program section of maximal size Bindings become active at the entry No bindings change in the

More information

For each of the following variables named x, specify whether they are static, stack-dynamic, or heapdynamic:

For each of the following variables named x, specify whether they are static, stack-dynamic, or heapdynamic: For each of the following variables named x, specify whether they are static, stack-dynamic, or heapdynamic: a) in C++: int* x = new(int); b) in Java: class book { protected string title; book(string x)

More information

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking Agenda COMP 181 Type checking October 21, 2009 Next week OOPSLA: Object-oriented Programming Systems Languages and Applications One of the top PL conferences Monday (Oct 26 th ) In-class midterm Review

More information

Introduction. Primitive Data Types: Integer. Primitive Data Types. ICOM 4036 Programming Languages

Introduction. Primitive Data Types: Integer. Primitive Data Types. ICOM 4036 Programming Languages ICOM 4036 Programming Languages Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer and Reference Types Data Types This

More information

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6] 1 Lecture Overview Types 1. Type systems 2. How to think about types 3. The classification of types 4. Type equivalence structural equivalence name equivalence 5. Type compatibility 6. Type inference [Scott,

More information

Chapter 6 part 1. Data Types. (updated based on 11th edition) ISBN

Chapter 6 part 1. Data Types. (updated based on 11th edition) ISBN Chapter 6 part 1 Data Types (updated based on 11th edition) ISBN 0-321 49362-1 Chapter 6 Topics Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative

More information

Chapter 15. Functional Programming. Topics. Currying. Currying: example. Currying: example. Reduction

Chapter 15. Functional Programming. Topics. Currying. Currying: example. Currying: example. Reduction Topics Chapter 15 Functional Programming Reduction and Currying Recursive definitions Local definitions Type Systems Strict typing Polymorphism Classes Booleans Characters Enumerations Tuples Strings 2

More information

Types and Type Inference

Types and Type Inference CS 242 2012 Types and Type Inference Notes modified from John Mitchell and Kathleen Fisher Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on Web!! Outline General discussion of

More information

3. Java - Language Constructs I

3. 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 information

Programming Languages

Programming Languages Programming Languages Types CSCI-GA.2110-001 Summer 2011 What is a type? A type consists of a set of values The compiler/interpreter defines a mapping of these values onto the underlying hardware. 2 /

More information

Input And Output of C++

Input And Output of C++ Input And Output of C++ Input And Output of C++ Seperating Lines of Output New lines in output Recall: "\n" "newline" A second method: object endl Examples: cout

More information

Informatica 3 Syntax and Semantics

Informatica 3 Syntax and Semantics Informatica 3 Syntax and Semantics Marcello Restelli 9/15/07 Laurea in Ingegneria Informatica Politecnico di Milano Introduction Introduction to the concepts of syntax and semantics Binding Variables Routines

More information

Organization of Programming Languages CS3200 / 5200N. Lecture 06

Organization of Programming Languages CS3200 / 5200N. Lecture 06 Organization of Programming Languages CS3200 / 5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Data Types A data type defines a collection of data objects

More information

1 Lexical Considerations

1 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 information

Overloading, Type Classes, and Algebraic Datatypes

Overloading, Type Classes, and Algebraic Datatypes Overloading, Type Classes, and Algebraic Datatypes Delivered by Michael Pellauer Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. September 28, 2006 September 28, 2006 http://www.csg.csail.mit.edu/6.827

More information

Products and Records

Products and Records Products and Records Michael P. Fourman February 2, 2010 1 Simple structured types Tuples Given a value v 1 of type t 1 and a value v 2 of type t 2, we can form a pair, (v 1, v 2 ), containing these values.

More information

It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis

It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis Chapter 14 Functional Programming Programming Languages 2nd edition Tucker and Noonan It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis

More information

If we have a call. Now consider fastmap, a version of map that uses futures: Now look at the call. That is, instead of

If we have a call. Now consider fastmap, a version of map that uses futures: Now look at the call. That is, instead of If we have a call (map slow-function long-list where slow-function executes slowly and long-list is a large data structure, we can expect to wait quite a while for computation of the result list to complete.

More information

CSCI312 Principles of Programming Languages!

CSCI312 Principles of Programming Languages! CSCI312 Principles of Programming Languages! Chapter 5 Types Xu Liu! ! 5.1!Type Errors! 5.2!Static and Dynamic Typing! 5.3!Basic Types! 5.4!NonBasic Types! 5.5!Recursive Data Types! 5.6!Functions as Types!

More information

Types and Type Inference

Types and Type Inference Types and Type Inference Mooly Sagiv Slides by Kathleen Fisher and John Mitchell Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on the course homepage Outline General discussion

More information

Fundamentals of Programming Languages. Data Types Lecture 07 sl. dr. ing. Ciprian-Bogdan Chirila

Fundamentals of Programming Languages. Data Types Lecture 07 sl. dr. ing. Ciprian-Bogdan Chirila Fundamentals of Programming Languages Data Types Lecture 07 sl. dr. ing. Ciprian-Bogdan Chirila Predefined types Programmer defined types Scalar types Structured data types Cartesian product Finite projection

More information

Functional Programming. Big Picture. Design of Programming Languages

Functional Programming. Big Picture. Design of Programming Languages Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics

More information

Review of the C Programming Language for Principles of Operating Systems

Review of the C Programming Language for Principles of Operating Systems Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

Functional programming with Common Lisp

Functional programming with Common Lisp Functional programming with Common Lisp Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 81 Expressions and functions

More information

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given MUHAMMAD FAISAL MIT 4 th Semester Al-Barq Campus (VGJW01) Gujranwala faisalgrw123@gmail.com MEGA File Solved MCQ s For Final TERM EXAMS CS508- Modern Programming Languages Question No: 1 ( Marks: 1 ) -

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp- 14/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 24! Composite data types (cont d) 1 Summary Data Types

More information

Programming Lecture 3

Programming Lecture 3 Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements

More information

NOTE: Answer ANY FOUR of the following 6 sections:

NOTE: Answer ANY FOUR of the following 6 sections: A-PDF MERGER DEMO Philadelphia University Lecturer: Dr. Nadia Y. Yousif Coordinator: Dr. Nadia Y. Yousif Internal Examiner: Dr. Raad Fadhel Examination Paper... Programming Languages Paradigms (750321)

More information

According to Larry Wall (designer of PERL): a language by geniuses! for geniuses. Lecture 7: Haskell. Haskell 98. Haskell (cont) - Type-safe!

According to Larry Wall (designer of PERL): a language by geniuses! for geniuses. Lecture 7: Haskell. Haskell 98. Haskell (cont) - Type-safe! Lecture 7: Haskell CSC 131 Fall, 2014 Kim Bruce According to Larry Wall (designer of PERL): a language by geniuses for geniuses He s wrong at least about the latter part though you might agree when we

More information

CSC324 Principles of Programming Languages

CSC324 Principles of Programming Languages CSC324 Principles of Programming Languages http://mcs.utm.utoronto.ca/~324 November 14, 2018 Today Final chapter of the course! Types and type systems Haskell s type system Types Terminology Type: set

More information

Motivation was to facilitate development of systems software, especially OS development.

Motivation was to facilitate development of systems software, especially OS development. A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.

More information

Decaf Language Reference Manual

Decaf Language Reference Manual Decaf Language Reference Manual C. R. Ramakrishnan Department of Computer Science SUNY at Stony Brook Stony Brook, NY 11794-4400 cram@cs.stonybrook.edu February 12, 2012 Decaf is a small object oriented

More information

Attributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes,

Attributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes, Chapter 5 Basic Semantics Attributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes, and the Environment Variables

More information

SML A F unctional Functional Language Language Lecture 19

SML A F unctional Functional Language Language Lecture 19 SML A Functional Language Lecture 19 Introduction to SML SML is a functional programming language and acronym for Standard d Meta Language. SML has basic data objects as expressions, functions and list

More information

Note that pcall can be implemented using futures. That is, instead of. we can use

Note that pcall can be implemented using futures. That is, instead of. we can use Note that pcall can be implemented using futures. That is, instead of (pcall F X Y Z) we can use ((future F) (future X) (future Y) (future Z)) In fact the latter version is actually more parallel execution

More information

Lecture 12: Data Types (and Some Leftover ML)

Lecture 12: Data Types (and Some Leftover ML) Lecture 12: Data Types (and Some Leftover ML) COMP 524 Programming Language Concepts Stephen Olivier March 3, 2009 Based on slides by A. Block, notes by N. Fisher, F. Hernandez-Campos, and D. Stotts Goals

More information

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline CS 0 Lecture 8 Chapter 5 Louden Outline The symbol table Static scoping vs dynamic scoping Symbol table Dictionary associates names to attributes In general: hash tables, tree and lists (assignment ) can

More information

CS 320: Concepts of Programming Languages

CS 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 information

CS558 Programming Languages

CS558 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 information

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

SEMANTIC ANALYSIS TYPES AND DECLARATIONS SEMANTIC ANALYSIS CS 403: Type Checking Stefan D. Bruda Winter 2015 Parsing only verifies that the program consists of tokens arranged in a syntactically valid combination now we move to check whether

More information

High Performance Computing

High Performance Computing High Performance Computing MPI and C-Language Seminars 2009 Photo Credit: NOAA (IBM Hardware) High Performance Computing - Seminar Plan Seminar Plan for Weeks 1-5 Week 1 - Introduction, Data Types, Control

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Abstract Data Types. Different Views of Data:

Abstract Data Types. Different Views of Data: Abstract Data Types Representing information is fundamental to computer science. The primary purpose of most computer programs is not to perform calculations, but to store and efficiently retrieve information.

More information

Lists. Michael P. Fourman. February 2, 2010

Lists. Michael P. Fourman. February 2, 2010 Lists Michael P. Fourman February 2, 2010 1 Introduction The list is a fundamental datatype in most functional languages. ML is no exception; list is a built-in ML type constructor. However, to introduce

More information