CSE341: Programming Languages Section 1

Slides:



Advertisements
Similar presentations
Chapter 4 - Control Statements
Advertisements

CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Winter 2013.
Programming Languages Section 1 1 Programming Languages Section 1. SML Fundamentals Xiaojuan Cai Spring 2015.
September 19, 2012Introduction to Artificial Intelligence Lecture 5: Functional Programming with Haskell 1 Functional Programming Symbolic AI is based.
HOMEWORK REVIEW This is an if else statement layout if (condition) { code to be executed if condition is true; } else { code to be executed if condition.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Making Decisions (True or False) Relational Operators >greater than =greater than or equal to
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Today’s Agenda ML Development Workflow –Emacs –Using use –The REPL More ML –Shadowing Variables –Debugging Tips –Boolean Operations –Comparison Operations.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)
Programming Languages Dan Grossman 2013 ML Expressions and Variable Bindings.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
JavaScript: Conditionals contd.
JavaScript Controlling the flow of your programs with ‘if’ statements
Programming Languages Dan Grossman 2013
Introduction to Decision Structures and Boolean Variables
Basic concepts of C++ Presented by Prof. Satyajit De
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
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.
The switch Statement, and Introduction to Looping
ECS10 10/10
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.
Scripts & Functions Scripts and functions are contained in .m-files
Nicholas Shahan Spring 2016
CMSC201 Computer Science I for Majors Lecture 03 – Operators
CSS 161: Fundamentals of Computing
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
CSE 341: Programming Languages Section 1
Cracking the Coding Interview
CSE 341: Programming Langs
Conditionals & Boolean Expressions
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.
Winter 2018 CISC101 11/22/2018 CISC101 Reminders
CSE 341 Section 1 Nick Mooney Spring 2017
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 Section 2 Winter 2018 Adapted from slides by Nick Mooney, Nicholas Shahan, Patrick Larson, and Dan Grossman.
Coding Concepts (Basics)
CSE 341: Programming Languages Section 1
CSE 341 Section 5 Winter 2018.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Autumn 2018.
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
Flowcharts and Pseudo Code
Nicholas Shahan Spring 2016
Chapter 3 Selections Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.
Winter 2019 CISC101 4/16/2019 CISC101 Reminders
Zorah Fung University of Washington, Spring 2015
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
Chapter 3 Debugging Section 3.4
Review of Previous Lesson
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2019.
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Section 1
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
Zorah Fung University of Washington, Winter 2016
Presentation transcript:

CSE341: Programming Languages Section 1 Chandrakana Nandi (Chandra) Winter 2018 Adapted from slides by Dan Grossman, Eric Mullen and Ryan Doenges

CSE 341: Programming Languages Introduction 3rd year graduate student in I write ocaml, which is quite similar to SML. PL tools for manufacturing processes Enjoy running! (http://raceconditionrunning.com) Winter 2018 CSE 341: Programming Languages

CSE 341: Programming Languages Course Resources We have a ton of course resources. Please use them! If you get stuck or need help: Ask questions in Google Group Email the staff list! cse341-staff@cs.washington.edu Come to Office Hours (on website, you don’t need a list of topics before you decide to stop by) We’re here for you Winter 2018 CSE 341: Programming Languages

CSE 341: Programming Languages Agenda Setup: get everything running Emacs Basics ML development workflow Shadowing Comparison Operators Boolean Operators Debugging Testing Winter 2018 CSE 341: Programming Languages

CSE 341: Programming Languages Setup Excellent guide located on the course website: https://courses.cs.washington.edu/courses/cse341/18wi/software-setup/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 Winter 2018 CSE 341: Programming Languages

CSE 341: Programming Languages 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) Consult the installation guide Winter 2018 CSE 341: Programming Languages

ML Development Workflow REPL is the general term for tools like “Run I/O” you have been using in jGRASP for CSE 142/3 REPL means Read Eval Print Loop Read: ask the user for semi colon terminated input Evaluate: try to run the input as ML code Print: show the user the result or any error messages produced by evaluation Loop Winter 2018 CSE 341: Programming Languages

ML Development Workflow Demo of REPL with lecture 1 code 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 Winter 2018 CSE 341: Programming Languages

CSE 341: Programming Languages Shadowing val a = 1; val b = 2; val a = 3; 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 Winter 2018 CSE 341: Programming Languages

CSE 341: Programming Languages 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; Reintroducing variable bindings in the same REPL session may... • make it seem like wrong code is correct; or • make it seem like correct code is wrong. Winter 2018 CSE 341: Programming Languages

CSE 341: Programming Languages Comparison Operators 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 Winter 2018 CSE 341: Programming Languages

CSE 341: Programming Languages Boolean Operators You can also perform logical operations over bools! and is completely different, we will talk about it later andalso/orelse are SML built-ins as they use short-circuit evaluation, we will talk about why they have to be built-ins later Operation 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 Winter 2018 CSE 341: Programming Languages

CSE 341: Programming Languages And… Those Bad Styles Language does not need andalso , orelse , or not Using more concise forms generally much better style And definitely please do not do this: (* e1 andalso e2 *) if e1 then e2 else false (* e1 orelse e2 *) if e1 then true else e2 (* not e1 *) if e1 then false else true (* just say e (!!!) *) if e then true else false Winter 2018 CSE 341: Programming Languages

CSE 341: Programming Languages 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. Winter 2018 CSE 341: Programming Languages

CSE 341: Programming Languages 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); Winter 2018 CSE 341: Programming Languages