01 - Click to edit Master subtitle style Chapter One Modern...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Click to edit Master subtitle style Chapter One Modern Programming Languages, 2nd ed. Programming Languages Chapter One Modern Programming Languages, 2nd ed. 11 Chapter One Modern Programming Languages, 2nd ed. Outline ■ What makes programming languages an interesting subject? – The amazing variety – The odd controversies – The intriguing evolution – The connection to programming practice – The many other connections Chapter One Modern Programming Languages, 2nd ed. 22 Chapter One Modern Programming Languages, 2nd ed. The Amazing Variety ■ There are very many, very different languages ■ (A list that used to be posted occasionally on comp.lang.misc had over 2300 published languages in 1995) ■ Often grouped into four families: – Imperative – Functional – Logic – Object-oriented Chapter One Modern Programming Languages, 2nd ed. 33 Chapter One Modern Programming Languages, 2nd ed. Imperative Languages ■ Example: a factorial function in C ■ Hallmarks of imperative languages: – Assignment – Iteration – Order of execution is critical Chapter One Modern Programming Languages, 2nd ed. 44 int fact(int n) { int sofar = 1; while (n>0) sofar *= n--; return sofar; } Chapter One Modern Programming Languages, 2nd ed. Functional Languages ■ Example: a factorial function in ML ■ Hallmarks of functional languages: – Single-valued variables – Heavy use of recursion Chapter One Modern Programming Languages, 2nd ed. 55 fun fact x = if x <= 0 then 1 else x * fact(x-1); Chapter One Modern Programming Languages, 2nd ed. Another Functional Language ■ Example: a factorial function in Lisp ■ Looks very different from ML ■ But ML and Lisp are closely related – Single-valued variables: no assignment – Heavy use of recursion: no iteration Chapter One Modern Programming Languages, 2nd ed. 66 (defun fact (x) (if (<= x 0) 1 (* x (fact (- x 1))))) Chapter One Modern Programming Languages, 2nd ed. Logic Languages ■ Example: a factorial function in Prolog ■ Hallmark of logic languages – Program expressed as rules in formal logic Chapter One Modern Programming Languages, 2nd ed. 77 fact(X,1) :- X =:= 1. fact(X,Fact) :- X > 1, NewX is X - 1, fact(NewX,NF), Fact is X * NF. Chapter One Modern Programming Languages, 2nd ed. Object-Oriented Languages ■ Example: a Java definition for a kind of object that can store an integer and compute its factorial Chapter One Modern Programming Languages, 2nd ed. 88 Chapter One Modern Programming Languages, 2nd ed. Chapter One Modern Programming Languages, 2nd ed. 99 public class MyInt { private int value; public MyInt(int value) { this.value = value; } public int getValue() { return value; } public MyInt getFact() { return new MyInt(fact(value)); } private int fact(int n) { int sofar = 1; while (n > 1) sofar *= n--; return sofar; } } Chapter One Modern Programming Languages, 2nd ed....
View Full Document

{[ snackBarMessage ]}

Page1 / 39

01 - Click to edit Master subtitle style Chapter One Modern...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online