CSE 341 Section 1 (9/28) With thanks to Dan Grossman, et. al. from previous versions of these slides.

Slides:



Advertisements
Similar presentations
Chapter 4 - Control Statements
Advertisements

Programming Languages Section 1 1 Programming Languages Section 1. SML Fundamentals Xiaojuan Cai Spring 2015.
Introduction to Computers and Programming Lecture 9: For Loops New York University.
Introduction to a Programming Environment
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
Methods. Why methods? A method gives a name to something that you want to do, so you don’t have to think about how to do it, you just do it The name should.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Making Decisions (True or False) Relational Operators >greater than =greater than or equal to
Today’s Agenda ML Development Workflow –Emacs –Using use –The REPL More ML –Shadowing Variables –Debugging Tips –Boolean Operations –Comparison Operations.
“Hello World” In Java Mehdi Einali Advanced Programming in Java 1.
Programming Languages Dan Grossman 2013 ML Expressions and Variable Bindings.
Chapter 5: Loops Tarik Booker CS 201 California State University, Los Angeles.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
Content Programming Overview The JVM A brief look at Structure – Class – Method – Statement Magic incantations – main() – output Coding a Dog Programming.
Programming Languages Dan Grossman 2013
Introduction to Decision Structures and Boolean Variables
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Based on slides by Shawn.
Programming Languages Dan Grossman 2013
Content Programming Overview The JVM A brief look at Structure
CSE 341 Section 1 (9/28) With thanks to Dan Grossman, et. al. from previous versions of these slides.
Introduction to Python
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Autumn 2017.
Chapter 2 - Introduction to C Programming
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
ECS10 10/10
EGR 2261 Unit 4 Control Structures I: Selection
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Winter 2013.
CSE341: Programming Languages Lecture 1 Course Mechanics ML Variable Bindings Dan Grossman Spring 2017.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2017.
Nicholas Shahan Spring 2016
Chapter 2 - Introduction to C Programming
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Emily Leland (Not Nick) Spring 2017
CSE 341: Programming Languages Section 1
CSE 341: Programming Langs
CSE341: Programming Languages Section 1
Conditions and Ifs BIS1523 – Lecture 8.
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
CSE341: Programming Languages Lecture 1 Course Mechanics ML Variable Bindings Dan Grossman Fall 2017.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Autumn 2018.
CSE 341 Section 1 Nick Mooney Spring 2017
CSE341: Programming Languages Section 1
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Winter 2018.
CSE 341 Section 7 Winter 2018 Adapted from slides by Eric Mullen, Nicholas Shahan, Dan Grossman, and Tam Dang.
CSE 341: Programming Languages Section 1
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
Java Programming Control Structures Part 1
CSE341: Programming Languages Lecture 1 Course Mechanics ML Variable Bindings 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
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
Adapted from slides by Nicholas Shahan and Dan Grossman
SE1H421 Procedural Programming LECTURE 4 Operators & Conditionals (1)
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2016.
Adapted from slides by Nicholas Shahan, Dan Grossman, and Tam Dang
Nicholas Shahan Spring 2016
Zorah Fung University of Washington, Spring 2015
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE341: Programming Languages Lecture 1 Course Mechanics ML Variable Bindings Dan Grossman Spring 2019.
Introduction to C Programming
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2019.
Programming Languages Dan Grossman 2013
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
CSE341: Programming Languages Section 1
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
Zorah Fung University of Washington, Winter 2016
Presentation transcript:

CSE 341 Section 1 (9/28) With thanks to Dan Grossman, et. al. from previous versions of these slides.

Agenda Introduction Setup: get everything running Emacs Basics ML development workflow Shadowing Debugging Comparison Operators Boolean Operators Testing

Introduction Eric Mullen nth year PhD student Dan is one of my advisors Originally took intro PL in Autumn 2010, 7 years ago PL is where I’m getting my PhD, and is something I’m very passionate about I love to sing, I love boardgames, and camping (though I don’t do enough of it)

Course Resources We have a ton of course resources. Please use them! If you get stuck or need help: Email the staff list! cse341-staff@cs.washington.edu Come to Office Hours (Every Weekday, see website) We’re here for you

Setup Excellent guide located on the course website: https://courses.cs.washington.edu/courses/cse341/17au/sml_emacs.pdf We’re going to spend about 5 minutes setting up now (so you can follow along for the rest of section) You need 3 things installed: Emacs SML SML mode for Emacs

Emacs Basics Don’t be scared! Commands have particular notation: C-x means hold Ctrl while pressing x Meta key is Alt (thus M-z means hold Alt, press z) C-x C-s is Save File C-x C-f is Open File C-x C-c is Exit Emacs C-g is Escape (Abort any partial command you may have entered)

ML Development Workflow REPL means Read Eval Print Loop You can type in any ML code you want, it will evaluate it Useful to put code in .sml file for reuse Every command must end in a semicolon (;) Load .sml files into REPL with use command

val a = 1; val b = 2; val a = 3; Shadowing a -> 1 a -> 1, b -> 2 a -> 1, b -> 2, a -> 3 a -> int a -> int, b -> int a -> int, b -> int, a -> int You can’t change a variable, but you can add another with the same name When looking for a variable definition, most recent is always used Shadowing is usually considered bad style

val x = 8; val y = 2; val x = 8; Shadowing This behavior, along with use in the REPL can lead to confusing effects Suppose I have the following program: I load that into the REPL with use. Now, I decide to change my program, and I delete a line, giving this: I load that into the REPL without restarting the REPL. What goes wrong? (Hint: what is the value of y?) val x = 8; val y = 2; val x = 8;

Debugging DEMO Errors can occur at 3 stages: Syntax: Your program is not “valid SML” in some (usually small and annoyingly nitpicky) way Type Check: One of the type checking rules didn’t work out Runtime: Your program did something while running that it shouldn’t The best way to debug is to read what you wrote carefully, and think about it.

Comparison Operators = (Equality) < (Less than) You can compare numbers in SML! Each of these operators has 2 subexpressions of type int, and produces a bool = (Equality) < (Less than) <= (Less than or equal) <> (Inequality) > (Greater than) >= (Greater than or equal) Weird error messages may appear from the type support: >,<,<=,>= can be used with either 2 ints or 2 reals (think floating point), but not a mixture =,<> work with equality types (to be covered later) but not real

Boolean Operators You can also perform logical operations over bools! Syntax Type-Checking Evaluation andalso e1 andalso e2 e1 and e2 have type bool Same as Java’s e1 && e2 orelse e1 orelse e2 Same as Java’s e1 || e2 not not e1 e1 has type bool Same as Java’s !e1 SML and is a different operation, we will cover it later. We’ll cover why they have to be builtins later. Technical note: andalso/orelse are SML builtins as they use short-circuit evaluation.

Testing We don’t have a unit testing framework (too heavyweight for 5 weeks) You should still test your code! val test1 = ((4 div 4) = 1); (* Neat trick for creating hard-fail tests: *) val true = ((4 div 4) = 1);