Syntax and Techniques in Imperative Programming

another detour to imperativeland l.w
1 / 6
Embed
Share

Explore syntax tips and techniques in imperative programming, including assertions, predicates, function implementations, and datatype member functions. Learn about the importance of error handling and proof techniques to enhance your understanding of imperative programming concepts.

  • Imperative Programming
  • Syntax Tips
  • Error Handling
  • Programming Techniques

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Another detour to Imperativeland chapter01/demo19.dfy 1

  2. Tips from office hours assertion failure does NOT mean false! it means false or unknown You rarely need to write ensures on functions and predicates, since they're transparent. forall proof technique "triggering assert" and "witness assert" Error: return statement is not allowed in this context (because it is guarded by a specification-only expression) 2

  3. Tips from office hours: assert isn't an expression predicate Foo(x:int) { && x < 32 && assert 20 < x; && IsEven(x) } predicate Foo(x:int) { true && x < 32 && (assert 20 < x; true && IsEven(x)) } predicate Bar(x:int) { && x < 32 && 20 < x && IsEven(x) } 3

  4. chapter 01 / exercise 22 disasters ch01/solutions/ex22.dfy seq membership vs seq indices forall i | i in TreeAsSequence(tree.left) :: i <= tree.val forall i | 0<=i<|TreeAsSequence(tree.left)| :: TreeAsSequence(tree.left)[i] <= tree.val CheckIfSortedTree recursive implementation 4

  5. Revisit IsPrime witnesses chapter02/exercise01.dfy 5

  6. A nifty new syntax: datatype member functions datatype Pet = Dog | Cat | Ant | Spider { function CountLegs() : int { match this case Dog => 4 case Cat => 4 case Ant => 6 case Spider => 8 } } function ShoesForTwo(pet: Pet) : int { 2 * pet.CountLegs() } 6

Related


More Related Content