Programming Thought - Programming Language - Lecture Slides, Slides of Computer Engineering and Programming

In this short course we study the basic concept of the programming. In these lecture slides the key points are:Programming Thought, Different Language, Language Affects, Learn New Languages, Fundamental Building Blocks, Choose Right Language, Extensible System, Imperative Programming, Functional Programming, Mapreduce

Typology: Slides

2012/2013

Uploaded on 04/23/2013

sarasvatir
sarasvatir 🇮🇳

4.5

(28)

86 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE 130 : Spring 2012
Programming Languages
Lecture 1: Hello, world.
A Programming Language
Two variables
x, y
Three operations
x++
x--
(x=0)? L1:L2;
L1: x++;
y--;
(y=0)?L2:L1
L2: …
Fact: This is “equivalent to” to every PL!
Good luck writing quicksort
… or Windows, Google, Spotify!
So why study PL ?
A different language is a
different vision of life”
- Federico Fellini
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Programming Thought - Programming Language - Lecture Slides and more Slides Computer Engineering and Programming in PDF only on Docsity!

CSE 130 : Spring 2012

Programming Languages

Lecture 1: Hello, world.

A Programming Language

  • Two variables
    • x, y
  • Three operations
    • x++
    • x--
    • (x=0)? L1:L2;

L1: x++; y--; (y=0)?L2:L L2: …

Fact: This is “equivalent to” to every PL!

Good luck writing quicksort … or Windows, Google, Spotify!

So why study PL?

“ A different language is a different vision of life”

  • Federico Fellini

So why study PL?

Programming language

shapes

Programming thought

So why study PL?

Language affects how:

  • Ideas are expressed
  • (^) Computation is expressed

Course Goals

“Free your mind”

-Morpheus

Learn New Languages/Constructs

New ways to:

  • describe
  • organize
  • think about

computation

Goal: How to design new PLs …“who, me ?”

Buried in every extensible system is a PL

  • Emacs, Android: Lisp
  • Word, Powerpoint: Macros, VBScript
  • Unreal: UnrealScript (Game Scripting)
  • Facebook: FBML, FBJS
  • SQL, Renderman, LaTeX, XML … Choose Right Language

Enables you to choose right PL

“…but isn’t that decided by

  • libraries,
  • standards,
  • and my boss ?”

Yes.

My goal: educate tomorrow’s tech leaders & bosses, so you’ll make informed choices

Speaking of Right and Wrong...

Imperative

Programming

x = x+

WTF? x = x+1 Imperative = Mutation

Func%onal Programming?

No Assignment.

No Muta0on.

No Loops.

OMG! Who uses FP?!

So, Who Uses FP?

MapReduce

So, Who Uses FP?

Linq, F#

So, Who Uses FP?

Erlang

So, Who Uses FP?

Scala

So, Who Uses FP?

Wall Street

(all of the above)

So, Who Uses FP?

...CSE 130

Interacting with ML

“Read-Eval-Print” Loop

Repeat:

  1. System reads expression e
  2. System evaluates e to get value v
  3. System prints value v and type t

What are these expressions, values and types?

Base type: Integers

Complex expressions using “operators”: (why the quotes ?)

  • +, -, *
  • div, mod

(^2 )

int

2+2 (^4) 2 * (9+10) (^38) 2 * (9+10) -12 (^26)

Base type: Strings

Complex expressions using “operators”: (why the quotes ?)

  • (^) Concatenation ^

“ab” (^) “ab”

string

“ab” ^ “xy” (^) “abxy”

Base type: Booleans

Complex expressions using “operators”:

  • “Relations”: = , <, <=, >=
  • &&, ||, not

true (^) true

bool

false (^) false 1 < (^2) true “aa” = “pq” (^) false (“aa” = “pq”) && (1<2) (^) false (“aa” = “aa”) && (1<2) (^) true

Type Errors

Untypable expression is rejected

  • No casting, No coercing
  • Fancy algorithm to catch errors
  • ML’s single most powerful feature (why ?)

(2+3) || (“a” = “b”)

(2 + “a”)

“pq” ^ 9

Complex types: Product (tuples)

(2+2 , 7>8); (^) (4,false)

int * bool

Complex types: Product (tuples)

(9-3,“ab”^“cd”,(2+2 ,7>8)) (^) (6, “abcd”,(4,false))

(int * string * (int * bool))

  • Triples,…
  • Nesting:
    • Everything is an expression
    • Nest tuples in tuples

Complex types: Lists []; (^) [] ’a list

  • Unbounded size
  • Can have lists of anything (e.g. lists of lists)
  • but …

[1;2;3]; [1;2;3] int list

[“a”;“b”; “c”^“d”]; [“a”;“b”; “cd”] string list

[1+1;2+2;3+3;4+4]; [2;4;6;8] int list

[(1,“a”^“b”);(3+4,“c”)]; [(1,“ab”);(7,“c”)] (int*string) list [[1];[2;3];[4;5;6]]; (^) [[1];[2;3];[4;5;6]]; (int list) list

Complex types: Lists

List operator “tail”

int list tl ([“a”]@[“b”]); (^) [“b”] string list

tl [];

tl [1;2;3];

tl

Only take the tail of nonempty list

[2;3]

Recap: Tuples vs. Lists? What’s the difference?

  • Tuples:
    • Different types, but fixed number:
      • pair = 2 elts
      • triple = 3 elts
  • Lists:
    • Same type, unbounded number:

(3, “abcd”) (int * string) (3, “abcd”,(3.5,4.2)) (int * string * (float* float))

[3;4;5;6;7] int list

So far, a fancy calculator…

… what do we need next?