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
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
Testing Michael Ernst CSE 140 University of Washington.
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.
Programming Languages Dan Grossman 2013 ML Expressions and Variable Bindings.
Welcome to Computer Programming II! Computer Programming II Summer 2015.
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.
JavaScript Controlling the flow of your programs with ‘if’ statements
Programming Languages Dan Grossman 2013
CS1010 Discussion Group 11 Week 5 – Functions, Selection, Repetition.
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
Introduction to Python
CSE 341 Section 1 (9/28) With thanks to Dan Grossman, et. al. from previous versions of these slides.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Autumn 2017.
Chapter 2 - Introduction to C Programming
The switch Statement, and Introduction to Looping
Compilation and Debugging
Compilation and Debugging
Testing and Debugging.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
Testing UW CSE 160 Winter 2017.
Programming Mehdi Bukhari.
ECS10 10/10
EGR 2261 Unit 4 Control Structures I: Selection
IF statements.
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
CSE 341: Programming Languages Section 1
CSE 341: Programming Langs
Conditionals & Boolean Expressions
CSE341: Programming Languages Section 1
Conditions and Ifs BIS1523 – Lecture 8.
CSE341: Programming Languages Lecture 1 Course Mechanics ML Variable Bindings Dan Grossman Fall 2017.
Winter 2018 CISC101 11/22/2018 CISC101 Reminders
Testing UW CSE 160 Winter 2016.
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: 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 2 Functions, Pairs, Lists
SE1H421 Procedural Programming LECTURE 4 Operators & Conditionals (1)
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2016.
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
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 Xander Lent 4th-year undergrad, Computer Engineering Interested in Systems, [Computer] Architecture, P.L., etc. There are exciting challenges and fascinating ideas where hardware and software meet! Personal Journey, answering these questions: How do computers work? Why do they work that way?

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);