9/23/

Size: px
Start display at page:

Download "9/23/2014. http://jatinga.iitg.ernet.in/~asahu/cs431/"

Transcription

1 Dr A Sahu Dept of Computer Science & Engeerg IIT Guwahati Admistrative thgs SML stallation and Book ML Motivation ML : Meta Language (Basic Concepts) Expression, Type Consistency, Variable & Environment Tuples and Lists Function: it s easy and it is fun Patterns Function Defitions, Local environment usg let Exception and I/O Course Structure : Functional Programmg (ML: Meta Lang.) 25% Logic Programmg (Prolog) 25% Concurrent/Parallel Programmg (Java/Cilk) 50% Lab hours : Mon 2PM 5PM (It is not mandatory to be present Lab) Tutorial hours Mon 5 6PM, 2001 (Mandatory) TAs : Debanjan, Pratik, Tarun and Rajendra Course website Assignments: One basic and one advanced from each part (Total 6 Assignments) ML Programmg: Basic (10%), Advanced (15%) Prolog programmg: Basic (10%), Advanced (15%) ParallelProgrammg: Programmg: Basic (20%), Advanced/Project (30%) Demos of Last Assignment/Project only Absolute Gradg Copy case any Assignment lead to F Grade ML Motivation : Why to Study? Functional Programmg Language: Entirely different paradigms Other than C Style for, while, do_while Thkg terms of Recursion Composite functions Functor (function on structures) Interactive type type expression, evaluate and get result Standard Meta language (SML) SML stallation Available for both Lux and Wdow ML Basic (Tutorial 1) ML Basic (Tutorial 1) ML Advanced (Tutorial 2 and 3) Jeffrey D. Ullman, Elements of ML Programmg, Prentice Hall,

2 Expression Type Consistency Variable & Environment Tuples and Lists Function: it s easy and it is fun Patterns Function Defitions Local environment usg let Exception and I/O $ sml Standard ML of New Jersey v [built: Tue Jul 30 09:57: ] - prt "hello world"; hello world val it = () : unit - $ sml Standard ML of New Jersey v [built: Tue Jul 30 09:57: ] -1+2*3; val it =7 : t We typed the expr 1+2*3 and ML respond the value of variable it is 7. Constants : Integer, Real, Boolean, Strg Arithmetic Operations Arithmetic : +,, *, div and mod ; val it =5.2 : real val it 5.2 : real -43 div ( 8 mod 3 ) * 5 ; val it 105 : t Result type is also out put Unary operator mus is ~ - ~3+4; val it =1 : t Result type Strg operations - house ^ cat ; val it = housecat : strg - loleium ^ ; val it= loleium : strg Comparison Operations -2<1+3; val it =true : bool - abc <= ab ; val it false : bool Precedence of comparison is less as compared to arithmetic ops Logical Operators -1<2 orelase 3>4; val it=true: bool 1<2 andalso 3>4; val it=false: bool The If then else Operator -if 1<2 then 3+4 else 5+6; val it =7 : t 2

3 Almost strictly Typed Language -1+2; val it=3 : t ; val it=3.0; real ; stdin: Error: operator and operand don't agree [literal] operator doma: real * real operand: real * t expression: if 1<2 then 3 else 4.0; stdin: Error: types of if branches do not agree [literal] then branch: t else branch: real expression: if 1 < 2 then 3 else 4.0 -if 2 then 3 else 4; stdin: Error: test expression if is not of type bool [literal] test t expression: t expression: if 2 then 3 else 4 Some time we have a reason to convert (coerce) from one type to another -real(4); val it=4.0 :real -5.3/real(4); val it=1.325 :real; -ceilg(3.5); val it=4 :t -floor(~3.5); val it=~4 :t -truncate(2.5); val it =2 : t -ord( a ); val it =97 : t -ord( a )-ord( A ); val it =32 :t -chr(97); val it = a : strg An Assignment like statement -val pi= ; val pi= :real -val radius=4.0; val radius=4.0:real -pi*radius*radius; val it= :real -val area= pi*radius*radius; val area= :real Tuple is kd of record -val t=(4,5.0, six ); val t=(4,5.0, six ):t*real*strg -val t1=(1,2,3); val t1=(1,2,3):t*t*t -vall t2=(1,(2,3.0)); (2 val t2==(1,(2,3.0)):t*(t*real) Accessg tuples -#1(t); val it=4:t -#3(t); val it= six :strg 3

4 List : element of same type -[1,2,3]; val it=[1,2,3]:t list -[ a ]; val it=[ a ] :strg list -[ a,3]; stdin: Error: operator and operand don't agree [literal] operator doma: strg * strg list operand: strg * t list expression: "a" :: 3 :: nil Operator head hd and tail tl Head of list is an element and tail of a list is a list -val L=[1,2,3]; val L=[1,2,3]:t list -hd(l); val it=1: t -tl(l); val it=[2,3]: t list -tl(tl(tl(l))); val it=[]:t list Cons operator (: : ) take an element and a list and produce a list -2::[3,4]; val it=[2,3,4]:t list -2.0::nil; val it=[2.0]: real list -1::2::3::4; Right associative: 1:: (2:: (3:: nil)) val it=[1,2,3,4]: t list Concatenation (@): concatenate two list of same type -[1,2]@[3,4]; val it=[1,2,3,4]: t list explode -expolde( abcd ); val it=[ a, b, c, d ]:strg list -expolde( ); val it=[]: strg list implode -implode([ a, bc, d ]); val it= abcd : strg -implode(nil); val it=[]: strg ML: Functional Programmg Language It s easy: It s fun Defe the function and use this function as argument seamlessly Use function place Where more traditional languages uses iterations (while, for, stmt loops) to defe Format fun <identifier> (<param list>) = expression; Examples -fun upper (c)= chr(ord (c) -32); val upper=fn: strg->strg Doma Range -upper( a ); val it= A : strg Parameter type -fun square(x:real)=x*x; val square=fn: real -> real -val area=3.142 * square 5.0; val area=70.55: real 4

5 Parameter type: Another example -fun square(x)=x*x; val square=fn: t -> t -val area=3.142 * square 5; stdin: Error: operator and operand don't agree [tycon mismatch] operator doma: real * real operand: real * t expression: pi * square 5 Function with three parameters -fun max3(a:t,b,c)= if a>b then if a>c then a else c else if b>c then b else c; val max3=fn: t*t*t->t Here ML deduce d b and c are teger type as if then else require same type parameters max3 works -max3(1,2,4); for val it=4:t -val t=(1,2,4); this type val t = (1,2,4):t*t*t also -max3(t); val it=4:t Recursive function A basis (base case) : for significantly small arguments we compute result without makg recursive call An ductive step: can t be handled by basic, we call function recursively one or more time with smaller argument -fun fact (n) = if n=0 then 1 else n*fact(n-1); val fact = fn : t -> t Other examples -fun reverse(l)= if L=nil then nil else reverse(tl(l))@ [hd(l)]; val reverse =fn: a list -> a list -reverse([1,2,3]; val it=[3,2,1]: a list fun reverse(l)= if L=nil then nil else reverse(tl(l))@ [hd(l)]; reverse([1,2,3]; Reverse.ml -use Reverse.ml ; (* Use file *) -open Math; (*Open library math *) -open Real; -open Int; -open List; Non Lear Recursion -fun(comb(n,m)=(*assume 0<=m<=n*) if m=0 orelse m=n then 1 else comb(n-1,m)+comb(n-1,m-1); val comb=fn:t*t ->t -comb(4,2); val it=6:t 5

6 Dependent recursive functions -fun odd (n) = if n=0 then false else even (n-1) and even (n) = if n=0 then true else odd (n-1); val odd = fn : t -> bool val even = fn : t -> bool -odd(4); val it=false : bool -even(4); val it=true : bool Dependent recursive functions -fun take (L) = if L=nil then nil else if hd(l)::skip(tl(l)) and skip(l) = if L=nil then nil else take(tl(l)); val take = fn : a list -> a list val skip = fn : a list -> a list -take([1,2,3,4,5); val it=[1,3,5]: t list -skip([ a, b, c, d, e ]); val it=[ b, d ] : strg list Matchg declaration - val (fst, snd) = (4, 4.45); val fst = 4 : t val snd = 4.45 : real -val abscissa=x, ordate=y = abscissa=1.2, ordate=3.2; val x = 1.2 : real val y = 3.2 : real -val b=x,...=a=2,b="s,c=3.4,d=[1]; val x = "s" : strg - val 2=x,... = (1,2,3); val x = 2 : t -val (x,x) = (2,3); stdin: Error: duplicate variable pattern(s): x -val (x,_,y,_) = (1,2,3,4); val x = 1 : t val y = 3 : t -val head :: _ = [1, 2, 3]; stdin: Warng: bdg not exhaustive head :: _ =... val head = 1 : t -fun reverse(nil)=nil reverse(x::xs)=reverse(xs)@[x]; val reverse =fn: a list -> a list -fun comb(n,0)=1 comb(n,n)=1 comb(n,m)=comb(n-1,m)+comb(n-1,m-1); Error: duplicate variable pattern(s):n fun comb(_,0)=1 if m=n then 1 else comb(n,m)=comb(n-1,m)+comb(n-1,m-1); val comb=fn:t*t -> t -fun sumpairs(nil)=0 SumPair((x,y)::zs)=x+y+sumPair(zs); val reverse =fn: (t*t)list -> t -sumpairs([(1,2),(1,5),(~3,6)]); val it= 12: t -fun sumll(nil)=0 sumll(nil::ys)=sumll(ys) sumll(x::xs)::ys)=x+sumlist(xs::ys); val sumll=fn: t list list->t -sumll([[1,2],nil,[3,4,5],[6])); val it=21:t 6

7 #clude<stdio.h> char A='E'; t ma() char A='M'; char A='B'; prtf("inside Block %c\n",a); extern char A; prtf("inside Ext Block %c\n",a); prtf("inside Ma %c\n",a); #clude<stdio.h> char A='E'; t ma() char A='M'; char *p=&a; //Save before decl. char A='B'; prtf("inside Block %c\n",a); prtf( Saved Value=%c\n",*p); extern char A; prtf("inside Ext Block %c\n",a); prtf("inside Ma %c\n",a); #clude<stdio.h> /* In C++, this feature has been removed, encourage to use :: */ void Resolve() prtf("external\n"); t ma() void Resolve()prtf("Ma\n"); void Resolve()prtf("Block\n"); Resolve(); extern void Resolve(); Resolve(); Resolve(); let val=<first variable>=<first expr>; val= <second variable>=<second expr>; val= <last variable>=<last expr> expression Expression can be combation expression and functions -fun hudreadthpower(x:real)= let val four=x*x*x*x; val twenty=four*four*four*four*four twenty*twenty*twenty*twenty*twenty val hundreadthpower: fn : real->real -hundreadthpower(2.0); val it= e30 :real -fun split(nil)=nil split([a])=([a],nil); split(a::b::cs)= let val (M,N)=split(cs) (a::m,b::n) It divide the list to two equal parts with alternative element val split: fn : a list-> a list* a list -split([1,2,3,4,5]); val it=(1,3,5],[2,4]): t list * t list 7

8 -fun merge(nil,m)=m merge(n,nil)=n; merge(x:;xs,y::ys)= if (x<y) then x::merge(xs,y::ys) else y::merge(x::xs,ys); ys); val merge=fn: a list* a list-> a list -fun mergesort(nil)=nil mergesort([a])=([a]); mergesort(l)= let val (M,N)=split(L); val M=mergeSort(M); val N=mergeSort(N) Split(L): divide the list to two equal parts with alternative elements merge(m,n) val mergesort: fn : a list-> a list -5 div 0; uncaught exception Div 5.0/0.0 uncaught exception Div hd(nil); uncaught exception Hd chr(500); uncaught exception Chr -exception BadN; exception badn - fun fact (n) = if n<0 raise BadN else if n=0 then 1 else n*fact(n-1); val fact=fn:t->t -exception BadM; exception badm fun comb(n,m) = if n<0 then raise BadN else if m<0 orelse m>n then raise BadM else if m=0 orelse m=1 then 1 else comb(n-1,m)+comb(n-1,m-1) val comb = fn : t*t->t fun comb(n,m) = let exception BadN; exception BadM; if n<0 then raise BadN else if m<0 orelse m>n then raise BadM else if m=0 orelse m=1 then 1 else comb(n-1,m)+comb(n-1,m-1) val comb = fn : t*t->t - fun id x = x; val id = fn : 'a -> 'a - (id 1, id "two"); val it = (1,"two") : t * strg - fun fst (x,y) = x; val fst = fn : 'a * 'b -> 'a - fun snd (x,y) = y; val snd = fn : 'a * 'b -> 'b - fst (1,"two"); val it = 1 : t - fst ([true, false], ); val it = [true,false] : bool list - fst (1,"two") + snd ((1,2), hd [1,2,3]); val it = 2 : t 8

9 - fun switch (x,y) = (y,x); val switch = fn : 'a * 'b -> 'b * 'a - switch (2, "abc"); val it = ("abc",2) : strg * t - switch (2, ); val it = ( ,2) : real * t - #2 (switch ([6,9], (fn x =>x))); val it = [6,9] : t list - fun null (nil) = true null (_::_) = false; val null = fn : 'a list -> bool - fun length (x) = if null x then 0 else length (tl x) + 1; val length = fn : 'a list -> t Op: convertg fix operators to function names -2+3; val it 5: t -op + (2,3); val it 5: t -fun map = map (f,nil) = nil map (f,h::t) = f(h) :: map (f,t); val map = fn : ('a->'b)*'a list -> 'b list -fun square(x:t)=x*x; val sqaure= fn:t->t -map(square,[1,2,3]); val it=[1,4,9]; -map (fn x=>x+1, [1,2,3,4,5]); val it = [2,3,4,5,6] : t list -map(~,[1,2,3]); val it = [~1,~2,~3]: t list Defe function onle -fun comp(f,g)= let fun C(x)=G(F(x)) C val map = fn : ('a->'b)* ( b-> c)-> ('a-> c) -fun F(x)=x+3; val F=fn:t->t -fun G(y)=y*y+2*y; val G = fn: t->t -val H=comp(F,G);; val H= fn:t->t -H(10); val it=195; - val f = comp (Math.s, Math.cos); val f = fn : real -> real - val g = Math.s o Math.cos; (* Composition "o" is predefed *) val g = fn : real -> real - f(0.25); val it = : real - g(0.25); val it = : real Dividg a to b to n equal parts of some n Let h=(b a)/n; Area of i th trapezoid has width δ runs from a+(i 1)h to a+ih is = Area= h( f ( a + ( i 1) h) + f ( a + ih) )/ 2 Total Area 9

10 Recursive defition of this Will be Total Area=Area of first trapezoid + rest area h(f(a)+f(a+h))/2 + Trap(a+h,b,n 1,F) -fun sqaure:real)=x+x; val square :fn :real->real; -fun trap(a,b,n,f) = if n<=0 orelse b-a<=0.0 then 0.0 else let val h=(b-a)/real(n) h*(f(a)+f(a+h))/2.0+trap(a+h,b,n-1,f) val trap=fn:real8real*t*(real->real)->real; -trap(0.0,1.0,8, square); Val it = :real -exception Emptylist; exception EmptyList; -fun reduce(f,nil) =raise EmptyList reduce(f,[a]) = a; reduce(f,x::xs)=f(x,reduce(f,xs); val reduce:fn: ( a* a-> a)* alist-> a -reduce(+,[1,4,8]); val it=13:t -fun plus(x:real)=x+y; val plus:fn :real*real->real n n 2 2 Var = ( ai ) / n (( ai ) / n) i= 1 i= 1 -fun variance(l)= let val n=length(l) reduce(plus,map(sqaure(l))/n - square(reduce(plus,l)/n) val variance = fn: real list->real -variance ([1.0,2.0,5.0,8.0]); val it =7.5:real 10

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority) Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

More information

How To Write A Programmg With A State Monad And An Imperative Dsl

How To Write A Programmg With A State Monad And An Imperative Dsl Outle Doma Specific Languages Lecture 2: The State Monad and an Imperative DSL Verónica Gaspes ceres School of Information Science, Computer and Electrical Engeerg February 2 Programmg with monads Computations

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

More information

Programming Fundamentals. Lesson 20 Sections

Programming Fundamentals. Lesson 20 Sections Programming Fundamentals Lesson 20 Sections Today, we will Study sections, in Haskell. Sections are another class of expressions that represent functions. A section is a binary operation where one of the

More information

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

More information

Python Evaluation Rules

Python Evaluation Rules Python Evaluation Rules UW CSE 160 http://tinyurl.com/dataprogramming Michael Ernst and Isaac Reynolds mernst@cs.washington.edu August 2, 2016 Contents 1 Introduction 2 1.1 The Structure of a Python Program................................

More information

Example of a Java program

Example of a Java program Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);

More information

Programming Language Rankings. Lecture 15: Type Inference, polymorphism & Type Classes. Top Combined. Tiobe Index. CSC 131! Fall, 2014!

Programming Language Rankings. Lecture 15: Type Inference, polymorphism & Type Classes. Top Combined. Tiobe Index. CSC 131! Fall, 2014! Programming Language Rankings Lecture 15: Type Inference, polymorphism & Type Classes CSC 131 Fall, 2014 Kim Bruce Top Combined Tiobe Index 1. JavaScript (+1) 2. Java (-1) 3. PHP 4. C# (+2) 5. Python (-1)

More information

Functional Programming

Functional Programming FP 2005 1.1 3 Functional Programming WOLFRAM KAHL kahl@mcmaster.ca Department of Computing and Software McMaster University FP 2005 1.2 4 What Kinds of Programming Languages are There? Imperative telling

More information

The C Programming Language course syllabus associate level

The C Programming Language course syllabus associate level TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

More information

Habanero Extreme Scale Software Research Project

Habanero Extreme Scale Software Research Project Habanero Extreme Scale Software Research Project Comp215: Java Method Dispatch Zoran Budimlić (Rice University) Always remember that you are absolutely unique. Just like everyone else. - Margaret Mead

More information

Functional Programming. Functional Programming Languages. Chapter 14. Introduction

Functional Programming. Functional Programming Languages. Chapter 14. Introduction Functional Programming Languages Chapter 14 Introduction Functional programming paradigm History Features and concepts Examples: Lisp ML 1 2 Functional Programming Functional Programming Languages The

More information

Binary Multiplication

Binary Multiplication Binary Multiplication Q: How do we multiply two numbers? eg. 12, 345 6, 789 111105 987600 8641500 + 74070000 83, 810, 205 10111 10101 10111 00000 1011100 0000000 + 101110000 111100011 Pad, multiply and

More information

Chapter 5. Selection 5-1

Chapter 5. Selection 5-1 Chapter 5 Selection 5-1 Selection (Decision) The second control logic structure is selection: Selection Choosing between two or more alternative actions. Selection statements alter the sequential flow

More information

Analyse et Conception Formelle. Lesson 5. Crash Course on Scala

Analyse et Conception Formelle. Lesson 5. Crash Course on Scala Analyse et Conception Formelle Lesson 5 Crash Course on Scala T. Genet (ISTIC/IRISA) ACF-5 1 / 36 Bibliography Simply Scala. Online tutorial: http://www.simply.com/fr http://www.simply.com/ Programming

More information

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University http://www.cs.stonybrook.

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University http://www.cs.stonybrook. Elementary Number Theory and Methods of Proof CSE 215, Foundations of Computer Science Stony Brook University http://www.cs.stonybrook.edu/~cse215 1 Number theory Properties: 2 Properties of integers (whole

More information

Programming in Standard ML

Programming in Standard ML Programming in Standard ML (DRAFT: VERSION 1.2 OF 11.02.11.) Robert Harper Carnegie Mellon University Spring Semester, 2011 Copyright c 2011 by Robert Harper. All Rights Reserved. This work is licensed

More information

Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

More information

CS 241 Data Organization Coding Standards

CS 241 Data Organization Coding Standards CS 241 Data Organization Coding Standards Brooke Chenoweth University of New Mexico Spring 2016 CS-241 Coding Standards All projects and labs must follow the great and hallowed CS-241 coding standards.

More information

Computer Programming I

Computer Programming I Computer Programming I COP 2210 Syllabus Spring Semester 2012 Instructor: Greg Shaw Office: ECS 313 (Engineering and Computer Science Bldg) Office Hours: Tuesday: 2:50 4:50, 7:45 8:30 Thursday: 2:50 4:50,

More information

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void 1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of

More information

6.087 Lecture 2 January 12, 2010

6.087 Lecture 2 January 12, 2010 6.087 Lecture 2 January 12, 2010 Review Variables and data types Operators Epilogue 1 Review: C Programming language C is a fast, small,general-purpose,platform independent programming language. C is used

More information

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements 9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending

More information

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013 Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper

More information

6.170 Tutorial 3 - Ruby Basics

6.170 Tutorial 3 - Ruby Basics 6.170 Tutorial 3 - Ruby Basics Prerequisites 1. Have Ruby installed on your computer a. If you use Mac/Linux, Ruby should already be preinstalled on your machine. b. If you have a Windows Machine, you

More information

Chapter 15 Functional Programming Languages

Chapter 15 Functional Programming Languages Chapter 15 Functional Programming Languages Introduction - The design of the imperative languages is based directly on the von Neumann architecture Efficiency (at least at first) is the primary concern,

More information

Chapter 7: Functional Programming Languages

Chapter 7: Functional Programming Languages Chapter 7: Functional Programming Languages Aarne Ranta Slides for the book Implementing Programming Languages. An Introduction to Compilers and Interpreters, College Publications, 2012. Fun: a language

More information

Statements and Control Flow

Statements and Control Flow Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10. Introduction to

More information

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser) High-Level Programming Languages Nell Dale & John Lewis (adaptation by Michael Goldwasser) Low-Level Languages What are disadvantages of low-level languages? (e.g., machine code or assembly code) Programming

More information

The previous chapter provided a definition of the semantics of a programming

The previous chapter provided a definition of the semantics of a programming Chapter 7 TRANSLATIONAL SEMANTICS The previous chapter provided a definition of the semantics of a programming language in terms of the programming language itself. The primary example was based on a Lisp

More information

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June 2014. Dr.-Ing.

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June 2014. Dr.-Ing. Computers An Introduction to Programming with Python CCHSG Visit June 2014 Dr.-Ing. Norbert Völker Many computing devices are embedded Can you think of computers/ computing devices you may have in your

More information

Information and Computer Science Department ICS 324 Database Systems Lab#11 SQL-Basic Query

Information and Computer Science Department ICS 324 Database Systems Lab#11 SQL-Basic Query Information and Computer Science Department ICS 324 Database Systems Lab#11 SQL-Basic Query Objectives The objective of this lab is to learn the query language of SQL. Outcomes After completing this Lab,

More information

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example Overview Elements of Programming Languages Lecture 12: Object-oriented functional programming James Cheney University of Edinburgh November 6, 2015 We ve now covered: basics of functional and imperative

More information

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

Exercise 4 Learning Python language fundamentals

Exercise 4 Learning Python language fundamentals Exercise 4 Learning Python language fundamentals Work with numbers Python can be used as a powerful calculator. Practicing math calculations in Python will help you not only perform these tasks, but also

More information

Outline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators

Outline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators Conditional Statements For computer to make decisions, must be able to test CONDITIONS IF it is raining THEN I will not go outside IF Count is not zero THEN the Average is Sum divided by Count Conditions

More information

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system. http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral

More information

Web Programming Step by Step

Web Programming Step by Step Web Programming Step by Step Lecture 13 Introduction to JavaScript Reading: 7.1-7.4 Except where otherwise noted, the contents of this presentation are Copyright 2009 Marty Stepp and Jessica Miller. Client-side

More information

Boolean Algebra Part 1

Boolean Algebra Part 1 Boolean Algebra Part 1 Page 1 Boolean Algebra Objectives Understand Basic Boolean Algebra Relate Boolean Algebra to Logic Networks Prove Laws using Truth Tables Understand and Use First Basic Theorems

More information

How To Program In Scheme (Prolog)

How To Program In Scheme (Prolog) The current topic: Scheme! Introduction! Object-oriented programming: Python Functional programming: Scheme! Introduction Next up: Numeric operators, REPL, quotes, functions, conditionals Types and values

More information

Integrating Formal Models into the Programming Languages Course

Integrating Formal Models into the Programming Languages Course Integrating Formal Models into the Programming Languages Course Allen B. Tucker Robert E. Noonan Computer Science Department Computer Science Department Bowdoin College College of William and Mary Brunswick,

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

Introduction to Python

Introduction to Python Caltech/LEAD Summer 2012 Computer Science Lecture 2: July 10, 2012 Introduction to Python The Python shell Outline Python as a calculator Arithmetic expressions Operator precedence Variables and assignment

More information

Advanced GMAT Math Questions

Advanced GMAT Math Questions Advanced GMAT Math Questions Version Quantitative Fractions and Ratios 1. The current ratio of boys to girls at a certain school is to 5. If 1 additional boys were added to the school, the new ratio of

More information

The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2).

The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2). CHAPTER 5 The Tree Data Model There are many situations in which information has a hierarchical or nested structure like that found in family trees or organization charts. The abstraction that models hierarchical

More information

Functions Recursion. C++ functions. Declare/prototype. Define. Call. int myfunction (int ); int myfunction (int x){ int y = x*x; return y; }

Functions Recursion. C++ functions. Declare/prototype. Define. Call. int myfunction (int ); int myfunction (int x){ int y = x*x; return y; } Functions Recursion C++ functions Declare/prototype int myfunction (int ); Define int myfunction (int x){ int y = x*x; return y; Call int a; a = myfunction (7); function call flow types type of function

More information

The countdown problem

The countdown problem JFP 12 (6): 609 616, November 2002. c 2002 Cambridge University Press DOI: 10.1017/S0956796801004300 Printed in the United Kingdom 609 F U N C T I O N A L P E A R L The countdown problem GRAHAM HUTTON

More information

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java CS1020 Data Structures and Algorithms I Lecture Note #1 Introduction to Java Objectives Java Basic Java features C Java Translate C programs in CS1010 into Java programs 2 References Chapter 1 Section

More information

Chapter 5 Parser Combinators

Chapter 5 Parser Combinators Part II Chapter 5 Parser Combinators 5.1 The type of parsers 5.2 Elementary parsers 5.3 Grammars 5.4 Parser combinators 5.5 Parser transformers 5.6 Matching parentheses 5.7 More parser combinators 5.8

More information

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

More information

PL / SQL Basics. Chapter 3

PL / SQL Basics. Chapter 3 PL / SQL Basics Chapter 3 PL / SQL Basics PL / SQL block Lexical units Variable declarations PL / SQL types Expressions and operators PL / SQL control structures PL / SQL style guide 2 PL / SQL Block Basic

More information

Visual Basic Programming. An Introduction

Visual Basic Programming. An Introduction Visual Basic Programming An Introduction Why Visual Basic? Programming for the Windows User Interface is extremely complicated. Other Graphical User Interfaces (GUI) are no better. Visual Basic provides

More information

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

More information

VB.NET Programming Fundamentals

VB.NET Programming Fundamentals Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements

More information

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code 1 Introduction The purpose of this assignment is to write an interpreter for a small subset of the Lisp programming language. The interpreter should be able to perform simple arithmetic and comparisons

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Lecture 2 Notes: Flow of Control

Lecture 2 Notes: Flow of Control 6.096 Introduction to C++ January, 2011 Massachusetts Institute of Technology John Marrero Lecture 2 Notes: Flow of Control 1 Motivation Normally, a program executes statements from first to last. The

More information

Chapter 5 Programming Statements. Chapter Table of Contents

Chapter 5 Programming Statements. Chapter Table of Contents Chapter 5 Programming Statements Chapter Table of Contents OVERVIEW... 57 IF-THEN/ELSE STATEMENTS... 57 DO GROUPS... 58 IterativeExecution... 59 JUMPING... 61 MODULES... 62 Defining and Executing a Module....

More information

Microsoft Access 3: Understanding and Creating Queries

Microsoft Access 3: Understanding and Creating Queries Microsoft Access 3: Understanding and Creating Queries In Access Level 2, we learned how to perform basic data retrievals by using Search & Replace functions and Sort & Filter functions. For more complex

More information

Python Lists and Loops

Python Lists and Loops WEEK THREE Python Lists and Loops You ve made it to Week 3, well done! Most programs need to keep track of a list (or collection) of things (e.g. names) at one time or another, and this week we ll show

More information

Java Crash Course Part I

Java Crash Course Part I Java Crash Course Part I School of Business and Economics Institute of Information Systems HU-Berlin WS 2005 Sebastian Kolbe skolbe@wiwi.hu-berlin.de Overview (Short) introduction to the environment Linux

More information

Analysis of Binary Search algorithm and Selection Sort algorithm

Analysis of Binary Search algorithm and Selection Sort algorithm Analysis of Binary Search algorithm and Selection Sort algorithm In this section we shall take up two representative problems in computer science, work out the algorithms based on the best strategy to

More information

The Cool Reference Manual

The Cool Reference Manual The Cool Reference Manual Contents 1 Introduction 3 2 Getting Started 3 3 Classes 4 3.1 Features.............................................. 4 3.2 Inheritance............................................

More information

Sample CSE8A midterm Multiple Choice (circle one)

Sample CSE8A midterm Multiple Choice (circle one) Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

Introduction to Java

Introduction to Java Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

More information

IVR Studio 3.0 Guide. May-2013. Knowlarity Product Team

IVR Studio 3.0 Guide. May-2013. Knowlarity Product Team IVR Studio 3.0 Guide May-2013 Knowlarity Product Team Contents IVR Studio... 4 Workstation... 4 Name & field of IVR... 4 Set CDR maintainence property... 4 Set IVR view... 4 Object properties view... 4

More information

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Introduction to the C language Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) The C language

More information

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

SQL - QUICK GUIDE. Allows users to access data in relational database management systems. http://www.tutorialspoint.com/sql/sql-quick-guide.htm SQL - QUICK GUIDE Copyright tutorialspoint.com What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java

More information

Programming and Reasoning with Side-Effects in IDRIS

Programming and Reasoning with Side-Effects in IDRIS Programming and Reasoning with Side-Effects in IDRIS Edwin Brady 19th October 2014 Contents 1 Introduction 3 1.1 Hello world............................................. 3 1.2 Outline................................................

More information

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is preceded by an equal sign d. its name has undereline 2. Associations

More information

PHP Tutorial From beginner to master

PHP Tutorial From beginner to master PHP Tutorial From beginner to master PHP is a powerful tool for making dynamic and interactive Web pages. PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.

More information

Semester Review. CSC 301, Fall 2015

Semester Review. CSC 301, Fall 2015 Semester Review CSC 301, Fall 2015 Programming Language Classes There are many different programming language classes, but four classes or paradigms stand out:! Imperative Languages! assignment and iteration!

More information

Tutorial on C Language Programming

Tutorial on C Language Programming Tutorial on C Language Programming Teodor Rus rus@cs.uiowa.edu The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:

More information

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language Simple C++ Programs Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input and Output Basic Functions from

More information

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

An Introduction to Assembly Programming with the ARM 32-bit Processor Family An Introduction to Assembly Programming with the ARM 32-bit Processor Family G. Agosta Politecnico di Milano December 3, 2011 Contents 1 Introduction 1 1.1 Prerequisites............................. 2

More information

El Dorado Union High School District Educational Services

El Dorado Union High School District Educational Services El Dorado Union High School District Course of Study Information Page Course Title: ACE Computer Programming II (#495) Rationale: A continuum of courses, including advanced classes in technology is needed.

More information

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example Operator Overloading Lecture 8 Operator Overloading C++ feature that allows implementer-defined classes to specify class-specific function for operators Benefits allows classes to provide natural semantics

More information

Anatomy of Programming Languages. William R. Cook

Anatomy of Programming Languages. William R. Cook Anatomy of Programming Languages William R. Cook Copyright (C) 2013 2 Chapter 1 Preliminaries Preface What? This document is a series of notes about programming languages, originally written for students

More information

Chapter 3. if 2 a i then location: = i. Page 40

Chapter 3. if 2 a i then location: = i. Page 40 Chapter 3 1. Describe an algorithm that takes a list of n integers a 1,a 2,,a n and finds the number of integers each greater than five in the list. Ans: procedure greaterthanfive(a 1,,a n : integers)

More information

Static Analysis. Find the Bug! 15-654: Analysis of Software Artifacts. Jonathan Aldrich. disable interrupts. ERROR: returning with interrupts disabled

Static Analysis. Find the Bug! 15-654: Analysis of Software Artifacts. Jonathan Aldrich. disable interrupts. ERROR: returning with interrupts disabled Static Analysis 15-654: Analysis of Software Artifacts Jonathan Aldrich 1 Find the Bug! Source: Engler et al., Checking System Rules Using System-Specific, Programmer-Written Compiler Extensions, OSDI

More information

Selection Statements

Selection Statements Chapter 5 Selection Statements 1 Statements So far, we ve used return statements and expression ess statements. e ts. Most of C s remaining statements fall into three categories: Selection statements:

More information

Conditions & Boolean Expressions

Conditions & Boolean Expressions Conditions & Boolean Expressions 1 In C++, in order to ask a question, a program makes an assertion which is evaluated to either true (nonzero) or false (zero) by the computer at run time. Example: In

More information

Dice. David Watkins Emily Chen Khaled Atef Phillip Schiffrin. djw2146 ec2805 kaa2168 pjs2186. Manager System Architect Testing Language Guru

Dice. David Watkins Emily Chen Khaled Atef Phillip Schiffrin. djw2146 ec2805 kaa2168 pjs2186. Manager System Architect Testing Language Guru Dice David Watkins Emily Chen Khaled Atef Phillip Schiffrin djw2146 ec2805 kaa2168 pjs2186 Manager System Architect Testing Language Guru September 30 th, 2015 1 DESCRIPTION Dice is a distributed systems

More information

JavaScript: Control Statements I

JavaScript: Control Statements I 1 7 JavaScript: Control Statements I 7.1 Introduction 2 The techniques you will learn here are applicable to most high-level languages, including JavaScript 1 7.2 Algorithms 3 Any computable problem can

More information

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC Introduction to Programming (in C++) Loops Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC Example Assume the following specification: Input: read a number N > 0 Output:

More information

Chapter 6: Programming Languages

Chapter 6: Programming Languages Chapter 6: Programming Languages Computer Science: An Overview Eleventh Edition by J. Glenn Brookshear Copyright 2012 Pearson Education, Inc. Chapter 6: Programming Languages 6.1 Historical Perspective

More information

MXwendler Javascript Interface Description Version 2.3

MXwendler Javascript Interface Description Version 2.3 MXwendler Javascript Interface Description Version 2.3 This document describes the MXWendler (MXW) Javascript Command Interface. You will learn how to control MXwendler through the Javascript interface.

More information

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification: Example Introduction to Programming (in C++) Loops Assume the following specification: Input: read a number N > 0 Output: write the sequence 1 2 3 N (one number per line) Jordi Cortadella, Ricard Gavaldà,

More information

Introduction to Java. CS 3: Computer Programming in Java

Introduction to Java. CS 3: Computer Programming in Java Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods

More information

C Coding Style Guide. Technotes, HowTo Series. 1 About the C# Coding Style Guide. 2 File Organization. Version 0.3. Contents

C Coding Style Guide. Technotes, HowTo Series. 1 About the C# Coding Style Guide. 2 File Organization. Version 0.3. Contents Technotes, HowTo Series C Coding Style Guide Version 0.3 by Mike Krüger, mike@icsharpcode.net Contents 1 About the C# Coding Style Guide. 1 2 File Organization 1 3 Indentation 2 4 Comments. 3 5 Declarations.

More information

CSCI-B 565 DATA MINING Project Report for K-means Clustering algorithm Computer Science Core Fall 2012 Indiana University

CSCI-B 565 DATA MINING Project Report for K-means Clustering algorithm Computer Science Core Fall 2012 Indiana University CSCI-B 565 DATA MINING Project Report for K-means Clustering algorithm Computer Science Core Fall 2012 Indiana University Jayesh Kawli jkawli@indiana.edu 09/17/2012 1. Examining Wolberg s breast cancer

More information

Programming Languages in Artificial Intelligence

Programming Languages in Artificial Intelligence Programming Languages in Artificial Intelligence Günter Neumann, German Research Center for Artificial Intelligence (LT Lab, DFKI) I. AI programming languages II. Functional programming III. Functional

More information

Unix Scripts and Job Scheduling

Unix Scripts and Job Scheduling Unix Scripts and Job Scheduling Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh spring@imap.pitt.edu http://www.sis.pitt.edu/~spring Overview Shell Scripts

More information

While Loop. 6. Iteration

While Loop. 6. Iteration While Loop 1 Loop - a control structure that causes a set of statements to be executed repeatedly, (reiterated). While statement - most versatile type of loop in C++ false while boolean expression true

More information