What is a programming language?

Slides:



Advertisements
Similar presentations
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Winter 2013.
Advertisements

Programming Languages Section 1 1 Programming Languages Section 1. SML Fundamentals Xiaojuan Cai Spring 2015.
Recap 1.Programmer enters expression 2.ML checks if expression is “well-typed” Using a precise set of rules, ML tries to find a unique type for the expression.
Patterns in ML functions. Formal vs. actual parameters Here's a function definition (in C): –int add (int x, int y) { return x + y; } –x and y are the.
CSE341: Programming Languages Lecture 5 Pattern-Matching Dan Grossman Fall 2011.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Fall 2011.
CS 312 Spring 2004 Lecture 18 Environment Model. Substitution Model Represents computation as doing substitutions for bound variables at reduction of.
Functional Programming Element of Functional Programming.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
CSE 341 : Programming Languages Lecture 2 Functions, Pairs, Lists Zach Tatlock Spring 2014.
CS314 – Section 5 Recitation 9
Chapter 10 Programming Fundamentals with JavaScript
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation
Learning to Program D is for Digital.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Spring 2017.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
Representation, Syntax, Paradigms, Types
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Winter 2013.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2017.
CSE 341: Programming Languages Section 1
CSE341: Programming Languages Lecture 5 More Datatypes and Pattern-Matching Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 5 More Datatypes and Pattern-Matching Dan Grossman Spring 2016.
Chapter 10 Programming Fundamentals with JavaScript
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Winter 2013.
CS1100 Computational Engineering
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Spring 2013.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Winter 2018.
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Spring 2013.
Representation, Syntax, Paradigms, Types
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
Recursion (part 1) October 24, 2007 ComS 207: Programming I (in Java)
What is a programming language?
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
Type & Typeclass Syntax in function
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE341: Programming Languages Lecture 5 More Datatypes and Pattern-Matching Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 5 More Datatypes and Pattern-Matching Dan Grossman Spring 2017.
Representation, Syntax, Paradigms, Types
Let bindings Motivation: Functions without local variables can be poor style and/or really inefficient. Syntax: let b1 b2 ... bn in e end where each bi is.
C Programming Getting started Variables Basic C operators Conditionals
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 2/23/2019.
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Zach Tatlock Winter 2018.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Zach Tatlock Winter 2018.
Representation, Syntax, Paradigms, Types
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 5 More Datatypes and Pattern-Matching Doug Woos Winter 2018.
CSE 341 Lecture 11 b closures; scoping rules
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Autumn 2017.
Introduction to the Lab
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
An Overview of C.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2019.
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Spring 2019.
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Spring 2019.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE341: Programming Languages Lecture 5 More Datatypes and Pattern-Matching Dan Grossman Spring 2019.
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
Programming II Vocabulary Review Loops & functions
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Autumn 2017.
Review Functions Lists Today: Let expressions
Presentation transcript:

What is a programming language? Here are separable concepts for defining and learning a language: syntax: how do you write the various parts of the language? semantics: what do programs mean? (One way to answer: what are the evaluation rules?) idioms: how do you typically use the language to express computations? libraries: does the language provide “standard” facilities such as file-access, hashtables, etc.? How? tools: what is available for manipulating programs in the language? (e.g., compiler, debugger, REP-loop)

ML basics A program is a sequence of bindings One kind of binding is a variable binding val x = e ; (semicolon optional in a file) A program is evaluated by evaluating the bindings in order A variable binding is evaluated by: Evaluating the expression in the environment created by the previous bindings. This produces a value. Extending the (top-level) environment to bind the variable to the value. Examples of values: 13, 4.8, true, “hello”, [3, 4, 5], (8, 8.2)

Critical language concepts Expressions have a syntax (written form) E.g.: A constant integer is written as a digit-sequence E.g.: Addition expression is written e1 + e2 Expressions have types given their context E.g.: In any context, an integer has type int E.g.: If e1 and e2 have type int in the current context, then e1+e2 has type int Expressions evaluate to values given their environment E.g.: In any environment, an integer evaluates to itself E.g.: If e1 and e2 evaluate to c1 and c2 in the current environment, then e1+e2 evaluates to the sum of c1 and c2

Function definitions A second kind of binding is for functions (like Java methods without fields, classes, statements, ...) Syntax: fun x0 (x1 : t1, ..., xn : tn) = e Typing rules: Context for e is (the function’s context extended with) x1:t1, ..., xn:tn and : x0 : (t1 * ... * tn) -> t where : e has type t in this context (This “definition” is circular because functions can call themselves and the type-checker “guessed” t.) (It turns out in ML there is always a “best guess” and the type-checker can always “make that guess”.)

Function applications (aka calls) Syntax: e0 (e1,...,en) (parens optional for one argument) Typing rules (all in the application’s context): e0 must have some type (t1 * ... * tn) -> t ei must have type ti (for i=1, ..., i=n) e0 (e1,...,en) has type t Evaluation rules: e0 evaluates to a function f in the application’s environment ei evaluates to value vi in the application’s environment result is f ’s body evaluated in an environment extended to bind xi to vi (for i=1, ..., i=n). (“an environment” is actually the environment where f was defined)

Let bindings Motivation: Functions without local variables can be poor style and/or really inefficient. Syntax: let b1 b2 ... bn in e end where each bi is a binding. Typing rules: Type-check each bi and e in context including previous bindings. Type of whole expression is type of e. Evaluation rules: Evaluate each bi and e in environment including previous bindings. Value of whole expression is result of evaluating e. Elegant design worth repeating: Let-expressions can appear anywhere an expression can. Let-expressions can have any kind of binding. Local functions can refer to any bindings in scope. Better style than passing around unchanging arguments.