A Programming Language. A different language g is a different vision of life. CSE 130 : Spring Two variables. L1: x++; y--; (y=0)?

Similar documents
A Programming Language. A different language g is a different vision of life. CSE 130 : Fall Two variables. L1: x++; y--; (y=0)?

Programming Languages. So why study PL? A Programming Language. A different language is a different vision of life. CSE 130 : Spring 2015

Programming Languages. So why study PL? A Programming Language. A different language is a different vision of life. CSE 130 : Fall 2015

Hi! My name is Sorin. Programming Languages. Why study PL? (discussion) Why study PL? Course Goals. CSE 130 : Fall 2013

Programming Languages

Hi! My name is Sorin. Programming Languages. Why study PL? (discussion) Why study PL? Course Goals. CSE 130 : Fall 2014

Hi! My name is Sorin. Programming Languages. Why study PL? (discussion) Why study PL? Course Goals. CSE : Fall 2017

So what does studying PL buy me?

Programming Languages

Any questions. Say hello to OCaml. Say hello to OCaml. Why readability matters. History, Variants. Plan (next 4 weeks)

CSE 130 [Spring 2014] Programming Languages

Plan (next 4 weeks) 1. Fast forward. 2. Rewind. 3. Slow motion. Rapid introduction to what s in OCaml. Go over the pieces individually

OCaml. History, Variants. ML s holy trinity. Interacting with ML. Base type: Integers. Base type: Strings. *Notes from Sorin Lerner at UCSD*

Programming Languages

Programming Languages

Programming Languages

News. Programming Languages. Complex types: Lists. Recap: ML s Holy Trinity. CSE 130: Spring 2012

OCaml. ML Flow. Complex types: Lists. Complex types: Lists. The PL for the discerning hacker. All elements must have same type.

Programming Languages

Programming Languages

Recap from last time. Programming Languages. CSE 130 : Fall Lecture 3: Data Types. Put it together: a filter function

Programming Languages

News. Programming Languages. Recap. Recap: Environments. Functions. of functions: Closures. CSE 130 : Fall Lecture 5: Functions and Datatypes

Programming Languages

Recap: ML s Holy Trinity. Story So Far... CSE 130 Programming Languages. Datatypes. A function is a value! Next: functions, but remember.

CSE 130 Programming Languages. Lecture 3: Datatypes. Ranjit Jhala UC San Diego

CSE 130 Programming Languages. Datatypes. Ranjit Jhala UC San Diego

CSE 130 : Fall Programming Languages. Lecture 11: Ranjit Jhala UC San Diego. programming

Course outline. CSE 341: Programming Languages. Why study programming languages? Course motivation and objectives. 1 lecture: Concepts

Programming Languages

Programming Languages

Dialects of ML. CMSC 330: Organization of Programming Languages. Dialects of ML (cont.) Features of ML. Functional Languages. Features of ML (cont.

Begin at the beginning

Programming Languages

CSE 341: Programming Languages

Background. CMSC 330: Organization of Programming Languages. Useful Information on OCaml language. Dialects of ML. ML (Meta Language) Standard ML

Introduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming

Side note: Tail Recursion. Begin at the beginning. Side note: Tail Recursion. Base Types. Base Type: int. Base Type: int

CMSC 330: Organization of Programming Languages. Functional Programming with Lists

Tail Recursion: Factorial. Begin at the beginning. How does it execute? Tail recursion. Tail recursive factorial. Tail recursive factorial

CSE 130 [Winter 2014] Programming Languages

Introduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming

Monday Feb 16, 5pm. solve these equalities. Midterm Thursday Feb 12. covers only ocaml part of the course, assignments 1 through 3.

COSE212: Programming Languages. Lecture 3 Functional Programming in OCaml

CS457/557 Functional Languages

Tuples. CMSC 330: Organization of Programming Languages. Examples With Tuples. Another Example

CMSC 330: Organization of Programming Languages. Functional Programming with Lists

Recap: ML s Holy Trinity

Introduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming

CS 11 Haskell track: lecture 1

61A LECTURE 1 FUNCTIONS, VALUES. Steven Tang and Eric Tzeng June 24, 2013

Lecture 1. Course Overview, Python Basics

CS 241 Data Organization. August 21, 2018

Homework 1. Notes. What To Turn In. Unix Accounts. Reading. Handout 3 CSCI 334: Spring, 2017

Today s Plan. Programming Languages. Example : Factorial. Recursion. CSE 130 : Spring Lecture 6: Higher-Order Functions

CS 241 Data Organization using C

CSE 130: Programming Languages. Polymorphism. Ranjit Jhala UC San Diego

Programming Languages

PROGRAMMING IN HASKELL. Chapter 5 - List Comprehensions

CSE 341, Autumn 2005, Assignment 3 ML - MiniML Interpreter

Recap. Recap. If-then-else expressions. If-then-else expressions. If-then-else expressions. If-then-else expressions

Which of the following expressions has the type int list?

Scope and Introduction to Functional Languages. Review and Finish Scoping. Announcements. Assignment 3 due Thu at 11:55pm. Website has SML resources

CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

Functional Programming

CS 6371: Advanced Programming Languages


! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

CS 360: Programming Languages Lecture 10: Introduction to Haskell

Lecture 1. Course Overview, Python Basics

Computer Science 210: Data Structures

Functional Programming and Haskell

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists. Zach Tatlock Winter 2018

Function definitions. CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists. Example, extended. Some gotchas. Zach Tatlock Winter 2018

INF3380: Parallel Programming for Natural Sciences

CS 3110 Lecture 1 Course Overview

CSCI-GA Scripting Languages

CSE 341: Programming Languages

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

A Second Look At ML. Chapter Seven Modern Programming Languages, 2nd ed. 1

Programming Languages. Example 5. Example 4. CSE 130 : Fall type, can reuse code for all types! let rec cat l = match l with

Programming (ERIM) Lecture 1: Introduction to programming paradigms and typing systems. Tommi Tervonen

CS 360 Programming Languages Interpreters

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1

CMSC 201 Computer Science I for Majors

CS 320: Concepts of Programming Languages

CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists. Dan Grossman Fall 2011

CS558 Programming Languages

Key components of a lang. Deconstructing OCaml. In OCaml. Units of computation. In Java/Python. In OCaml. Units of computation.

Welcome to CS 135 (Winter 2018)

Introduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15

Introduction to Data Structures

Intro. Scheme Basics. scm> 5 5. scm>

News. CSE 130: Programming Languages. Environments & Closures. Functions are first-class values. Recap: Functions as first-class values

Programming Languages

Introduction to: Computers & Programming: Review prior to 1 st Midterm

Advanced Programming Concepts. CIS 15 : Spring 2007

Programming Languages Lecture 14: Sum, Product, Recursive Types

Functional Programming Lecture 1: Introduction

Transcription:

CSE 130 : Spring 2010 Programming Languages Lecture 1: Hello, world. Ranjit Jhala UC San Diego A Programming Language Two variables x,y Three operations x++ x-- (x=0)? L1:L2; L1: x++; y--; (y=0)?l2:l1 L2: So why study PL? A different language g is a different vision of life - Federico Fellini i Fact: This language is equivalent to every PL! Try writing quicksort or Windows, Google, in this language.

So why study PL? Programming language shapes Programming thoughtht So why study PL? PL affects how: Ideas are expressed Computation is expressed Course Goals Free your mind Morpheus Course Goals: Learn Languages/Constructs New ways to: -describe - organize - think about computation

Enables you to Write software that s Readable Correct Extendable Modifiable Reusable On the internet, nobody knows you re a dog a Ruby Program a Scala Program an Erlang Program Enables you to learn new PLs No Java (C#) 15 (10) years ago AJAX? Python? Scala? Erlang? F#? Learn the anatomy of a PL Fundamental building blocks Different guises in different PLs Re-learn the PLs you already know Enables you to design new PLs who, me? Buried in every extensible system is a PL Emacs, Android: Lisp Word, Powerpoint: Macros, VBScript Quake: QuakeC (Game Scripting) Facebook: FBML, FBJS SQL, Renderman, LaTeX, XML

Enables you to choose right PL but isn t that decided by libraries, standards, d and my boss? Yes. My goal: educate tomorrow s tech leaders & bosses, so you ll make informed choices Mechanics cseweb.ucsd.edu/classes/sp10/cse130/ edu/classes/sp10/cse130/ Nothing printed, everything on Webpage! Meetings: Lectures: Ranjit Jhala, Tu-Th 6:30-8pm@CENTER 214 Section: Jeff Meister, We 2-3p@PETER104, Fr 3-4p@WLH2204 Labs: Elliot Slaughter and Jeff Mercado Office Hours: Posted on web page Material Outline: 1. Functional, OCaml, 5 weeks 2. OO, Python, 3 weeks 3. Logic, Prolog, 1 week No recommended Text: Online lecture notes Resources posted on webpage Pay attention to lecture and section! Requirements and Grading The good news: No Homework Midterm: 30% Programming g Assignments (7-8): 30% Final: 30% In-class Exercises: 5% Peerwise: 5% Grading on a curve. Two hints/rumors: 1. Lot of work 2. Don t worry (too much) about grade

PeerWise: Share Problems, Get Points! 5% of grade Points allocated by usefulness (determined by classmates) 800 Points gets you the 5% See WebCT post for details In Class Style Exercises 5-10 mins exercises Alone or in groups Go over solutions immediately Random lectures Points for showing up Suggested Homeworks On webpage after Thursday lecture Based on lectures, section of previous Tu,Thu Recommended, ungraded, HW problems are sample exam questions Webpage has first samples already Weekly Programming Assignments Schedule up on webpage Deadline Extension: Four late days, used as whole unit 5 mins late = 1 late day Plan ahead, no other extensions PA #1 online, due 4/14, 5:00 PM

Weekly Programming Assignments Unfamiliar languages + Unfamiliar environments Start Early! Weekly Programming Assignments Scoring = Style + Test suite No Compile, No Score Weekly Programming Assignments Forget Java, C, C++ other 20 th century PLs Don t complain that Ocaml is hard that Ocaml is retarded Immerse yourself in new language It is not. Free your mind.

Word from our sponsor Programming g Assignments done ALONE We use plagiarism detection software Jeff is an expert Have code from all previous classes MOSS is fantastic, ti plagiarize i at your own risk Zero Tolerance offenders punished ruthlessly Please see academic integrity statement Enough with the small talk Say hello to OCaml void sort(int arr[], int beg, int end){ if (end > beg + 1){ int piv = arr[beg]; int l = beg + 1; int r = end; while (l!= r-1){ let rec sort xs = if(arr[l] <= piv) match xs with [] -> [] l++; (h::t) -> else let(l,r)= List.partition ((<=) h) t in swap(&arr[l], &arr[r--]); (sort l)@h::(sort r) } if(arr[l]<=piv && arr[r]<=piv) Quicksort in Ocaml l=r+1; else if(arr[l]<=piv && arr[r]>piv) {l++; r--;} else if (arr[l]>piv && arr[r]<=piv) swap(&arr[l++], &arr[r--]); else r=l-1; swap(&arr[r--], &arr[beg]); sort(arr, beg, r); sort(arr, l, end); } } Quicksort in C

Why readability matters Say hello to OCaml sort=:(($:@(<#[),(=#[),$:@(>#[))({~?@#))^: (1:<#) Quicksort in J let rec sort xs = match xs with [] -> [] h::t -> let (l,r)= List.partition titi ((<=) h) t in (sort l)@h::(sort r) Quicksort in OCaml Plan (next 4 weeks) 1. Fast forward Rapid introduction to whats in ML 2. Rewind 3. Slow motion Go over the pieces individually ML: History, Variants Meta Language Designed by Robin Milner To manipulate theorems & proofs Several Dialects: Standard ML (SML) Original syntax Objective Caml: (Ocaml) The PL for the discerning hacker State-of-the-art, extensive library, tool, user support F# (Ocaml+.NET) released in Visual Studio

ML s holy trinity Expression Type Everything is an expression Everything has a value Everything has a type Value 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 expressions, values and types? Base type: Integers Base type: Strings 2 2 2+2 4 2 * (9+10) 38 ab ab ^ xy ab abxy 2 * (9+10) -12 26 int string Complex expressions using operators :(why p ( y the quotes?) +, -, * div, mod Complex expressions using operators :(why p ( y the quotes?) Concatenation ^

Base type: Booleans true false true false 1 < 2 true aa = pq false ( aa = pq ) && (1<2) false ( aa = aa ) && (1<2) bool Complex expressions using operators : Relations : =, <, <=, >= &&,, not true Type Errors (2+3) ( a = b ) pq ^ 9 (2 + a ) Untypable expression is rejected No casting, No coercing Fancy algorithm to catch errors ML s single most powerful feature (why?) Complex types: Product (tuples) Complex types: Product (tuples) (2+2, 7>8); (4,false) (9-3, ab ^ cd,(2+2,(,7>8)) (6, abcd,(4,false)) (int * string * (int * bool)) int * bool Triples, Nesting: Everything is an expression Nest tuples in tuples

Complex types: Lists Complex types: Lists []; [] a list [1;2;3]; [1;2;3] int list [1+1;2+2;3+3;4+4]; [2;4;6;8] int list [ a ; b ; c ^ d ]; [ a ; b ; cd ] string list [(1, a ^ b );(3+4, c )]; )]; [(1, ab );(7 );(7, c )] (int*string) list [[1];[2;3];[4;5;6]]; [[1];[2;3];[4;5;6]]; (int list) list [1; pq ]; All elements must have same type Unbounded size Can have lists of anything (e.g. lists of lists) but Complex types: Lists List operator Cons :: Complex types: Lists List operator Append @ 1::[]; [1] int list 1::[2]; [1;2] int list a ::[ b ; c ]; [ a ; b ; c ] string list [1;2]@[3;4;5]; [1;2;3;4;5] int list [ a ]@[ b ]; [ a ; b ] string list []@[1]; [1] string list Can only cons element to a list of same type 1::[ b ; cd ]; Can only append two lists 1 @ [2;3]; of the same type [1] @ [ a ; b ];

Complex types: Lists Complex types: Lists List operator head hd List operator tail tl hd [1;2]; 1 int tl [1;2;3]; [2;3] int list hd ([ a ]@[ b ]); a string tl ([ a ]@[ b ]); [ b ] string list Only take the head a nonempty list hd []; Only take the tail of nonempty list tl []; Recap: Tuples vs. Lists? What s the difference? Tuples: Different types, but fixed number: (3, abcd ) (int * string) pair = 2 elts (3, abcd,(3.5,4.2)) (int * string * (float* float)) triple = 3 elts Lists: Same type, unbounded number: Syntax: [3;4;5;6;7] int list Tuples = comma Lists = semicolon So far, a fancy calculator what do we need next?