CSci 658-01: Software Language Engineering
Spring 2018 Lecture Notes

H. Conrad Cunningham

4 May 2018

Copyright (C) 2018, H. Conrad Cunningham
Professor of Computer and Information Science
University of Mississippi
211 Weir Hall
P.O. Box 1848
University, MS 38677
(662) 915-5358

I maintain these notes as text in the Pandoc’s dialect of Markdown using embedded LaTeX markup for the mathematical formulas and then translate the notes to HTML, PDF, and other formats as needed.

Advisory: The HTML version of this document requires use of a browser that supports the display of MathML. A good choice as of May 2018 is a recent version of Firefox from Mozilla.

Lecture Notes

Go To Current Lecture

Lecture Notes, Examples, and Schedule

Language-Oriented Programming

  1. (22 Jan) Review syllabus. Distribute papers to be discussed over next two weeks.

  2. (24-26 Jan) Discuss “Little Languages” paper

    1. Paper: Jon Bentley. Programming Pearls: Little Languages, Communications of the ACM, Vol. 29, No. 8, pp. 711-721, August 1986.

    2. Software: The groff package includes the GNU implementations of the troff set of “Unix” tools such as pic and chem. (I installed this on my iMac using Homebrew. I also installed the plotutils package to help with display in various formats.)

    3. Additional references for little language pic (not discussed)

    4. Additional references for the little languages lex, yacc, make, and chem (not discussed)

  3. (26-29 Jan) Discuss “No Silver Bullet” paper and related issues

    1. Paper: Frederick P. Brooks. No Silver Bullet: Essence and Accident in Software Engineering, IEEE Computer, Vol. 20, No. 4, 10-19, 1987.

    2. Retrospective paper after 10 years (not discussed): Frederick P. Brooks. ‘No Silver Bullet’ Refired, Chapter 17 in The Mythical Man Month: Essays on Software Engineering, Anniversary Edition, Addison Wesley, 1995.

  4. (29-31 Jan) Discuss “Language-Oriented Programming” paper

    1. Paper: M. P. Ward. Language-Oriented Programming, Software–Concepts and Tools, Vol. 15, No. 4, pp. 147-161, 1994. [local]

    2. Additional references from paper (not discussed)

      • Charles Antony Richard Hoare. The Emperor’s Old Clothes (1980 Turing Award Address), Communications of the ACM, Vol. 24, No. 2, 75-83, 1981.
  5. (31 Jan; intermittently until Spring Break, 19-28 Mar; 2-6 Apr) Discuss overview of Domain Specific Languages

    1. Instructor’s notes on Domain Specific Languages

    2. Mixed-in introductory discussion of Fowler’s DSL book introductory chapters, State Machine DSL, and Computer Configuration DSL below.

    3. References used in notes (most not discussed directly)

  6. (dates on items) Survey Design Patterns

    1. (5-7 Feb) Instructor’s notes on Introduction to Patterns [HTML slides]

    2. (7 Feb) Instructor’s notes on Pipes and Filters Architectural Pattern (Not fully covered, used mainly to illustrate approach to pattern definition) [Powerpoint]

    3. (9-12 Feb) John Vlissides. Designing with Patterns, In Pattern Hatching: Design Patterns Applied, Addison-Wesley, 1998. [Powerpoint]

    4. Additional references (not directly discussed in class)

  7. (5, 14-21 Feb) Discuss Fowler’s introductory DSL example

    1. Martin Fowler. An Introductory Example, Chapter 1, Domain-Specific Languages, Addison Wesley, 2011.

    2. Martin Fowler. Using Domain-Specific Languages, Chapter 2, Domain-Specific Languages, Addison Wesley, 2011.

External DSLs

  1. (dates on items) Discuss State Machine External DSLs based on Martin Fowler’s Secret Panel Controller (State Machine) DSLs

    1. (2-5, 14-26 Feb) Martin Fowler. Domain Specific Languages, Addison Wesley, 2011.

      • Fowler introduces the running example, the Secret Panel Controller (State Machine) case study, in DSL Chapter 1)
      • Fowler DSL Chapter 1 “An Introductory Example
      • Fowler DSL Chapter 2 “Using Domain-Specific Languages”
      • Fowler DSL Chapter 3 “Implementing DSLs”
      • Fowler DSL Chapter 5 “Implementing an External DSL”
      • Fowler DSL Chapter 8 “Code Generation”
      • Fowler DSL Chapter 11 “Semantic Model”
      • Fowler DSL Chapter 17 “Delimiter-Directed Translation”
      • Fowler DSL Chapter 18 “Syntax-Directed Translation”
      • Fowler DSL Chapter 21 “Recursive Descent Parser”
      • Fowler DSL Chapter 21 “Parser Generator”
      • Fowler DSL Chapter 22 “Parser Combinator”
      • Fowler DSL Chapter 51 “State Machine”
      • Fowler DSL Chapter 52 “Transformer Generation”
      • Fowler DSL Chapter 55 “Model Aware Generation”
      • Fowler DSL Chapter 56 “Model Ignorant Generation”
      • Fowler’s List of DSL Patterns from DSL book.
    2. Other items from the instructor’s notes

      Scala versions (2009)

    3. Scala notes

      • I developed the Scala versions in 2009 by referring to an in-work version of Fowler’s book on his website, so they may not follow his final book precisely. Fowler’s code is in Java, Ruby, C#, etc. I updated the Scala programs in 2018 to make sure they would compile and execute under the current Scala release.

      • Scala references below

    4. (21 Feb) Graphviz and dot language reference and examples (looked at examples in class)

    5. (14 Feb) Scala State Machine Semantic Model (Ch. 1, 3, 11)

    6. (21 Feb) Scala XML-based External DSL (Ch. 1, 3, 5)

    7. (16 Feb) Scala Custom External DSL with a Delimiter-Directed parser (Ch. 1, 3, 5, 17)

    8. (19 Feb) Scala Custom External DSL with hand-coded Ad Hoc Recursive-Descent parser (Ch. 1, 3, 5, 21)

    9. (21 Feb briefly) Scala Custom External DSL (using Scala parser combinator library) with embedded state machine builder (Ch. 1, 3, 5, 22)

    10. (21 Feb briefly) Scala Custom External DSL (using Scala parser combinator library) with full AST construction (Ch. 1, 3, 5, 22)

    11. (21 Feb briefly) Scala Static C Code Generator with Model-Aware target platform library (Ch. 1, 3, 5, 8, 52, 55)

    12. (21 Feb) Scala Graphviz Dot Language Code Generator (added 2018) (Ch. 1, 3, 5, 8, 52)

  2. (16 Feb) Announce homework Assignment #1 and Assignment #2

  3. (23 Feb) Discuss Metaprogramming

    Note: We return to this topic near the end of the semester with an emphasis on Python 3 metaprogramming features.

Internal DSLs

  1. (dates on items) Discuss Fowler’s Computer Configuration Internal DSLs (Ch. 4, 35, 36, 38)

    1. Background: Martin Fowler. Domain Specific Languages, (Addison Wesley, 2011).

      • Martin Fowler’s List of DSL Patterns from Domain Specific Languages, Addison Wesley, 2011
      • Fowler DSL Chapter 1 “An Introductory Example
      • Fowler DSL Chapter 2 “Using Domain-Specific Languages”
      • Fowler DSL Chapter 3 “Implementing DSLs”
      • Fowler DSL Chapter 4 “Implementing an Internal DSL”
      • Fowler DSL Chapter 11 “Semantic Model”
      • Fowler DSL Chapter 13 “Context Variable”
      • Fowler DSL Chapter 32 “Expression Builder”
      • Fowler DSL Chapter 33 “Function Sequence”
      • Fowler DSL Chapter 34 “Nested Functions”
      • Fowler DSL Chapter 36 “Object Scoping”
      • Fowler DSL Chapter 37 “Closure”
      • Fowler DSL Chapter 38 “Nested Closure”
      • Fowler DSL Chapter 39 “Literal List”
      • Fowler DSL Chapter 40 “Literal Map”

      Scala versions (2009)

    2. (23 Feb) Scala semantic model (shared)

    3. (23, 26 Feb) Scala internal DSL using Method Chaining

    4. (26 Feb) Scala internal DSL using Nested Closures and Object Scoping

    5. CompConfig.sh test script

  2. (26 Feb) Discuss Fowler’s Email Message Building Internal DSL (Ch. 35)

    1. Background: Martin Fowler. Domain Specific Languages, (Addison Wesley, 2011). See listing of chapters under Computer Configuration internal DSL above.

      Scala versions (2009)

    2. Scala internal DSL using Method Chaining and Progressive Interfaces

    3. EmailProgressive.sh test script

  3. (see dates on items) Explore Fowler’s Lair Configuration DSLs

    1. Background on Lair DSL

    2. Background on internal DSLs: Martin Fowler. Domain Specific Languages, (Addison Wesley, 2011). See chapters under Computer Configuration internal DSL above.

    3. Background on Lua

      • See Lua references below

      • Several of the Lair DSL programs must execute with Lua 5.1 because they use a few Lua platform features changed in Lua 5.2 or 5.3. I installed the lua@5.1 package on my iMacs using the Homebrew package manager.

      • At the terminal command line, lua5.1 testNN.lua compiles and executes the test driver program for the DSL with files builder program builderNN.lua and DSL script rulesNN.lua.

    4. (28 Feb Python) Shared modules

      Fowler’s Ruby source

      Lua (2013)

      Python 3 (2018)

    5. (2 Mar Python) Internal DSL using Global Function Sequence pattern

      Fowler’s Ruby

      Lua (2013)

      Python 3 (2018)

    6. (7 Mar Python) Internal DSL using Class Method Function Sequence and Method Chaining patterns

      Fowler’s Ruby

      Lua (2013)

      Python 3 (2018)

    7. (7 Mar Python) Internal DSL using Expression Builder and Method Chaining patterns

      Fowler’s Ruby

      Lua (2013)

      Python 3 (2018)

    8. Internal DSL using Nested Closures pattern

      Fowler’s Ruby

      Lua (2013)

      Python 3 – none yet. (Python’s weak syntactic support for lambdas does not allow the relatively direct approach usable in Ruby, Scala, and Lua.)

    9. Internal DSL using Expression Builder, Object Scoping, and Method Chaining patterns

      Fowler’s Ruby

      Lua (2013)

      Python 3 – none yet

    10. Internal DSL using Literal Collection pattern

      Fowler’s Ruby

      Lua (2013)

      Python 3 – none yet

    11. (5 Mar Python) External DSL using Parser/Builder (no corresponding example in Fowler book chapter)

      Lua (2013)

      Python 3 (2018)

  4. (5 Mar) Announce homework Assignment #3

  5. (not discussed, but an alternative context for Assignment #3) Use Sandwich DSL Case Study

    1. Notes

    2. Haskell version (2014, 2017) using algebraic data types

    3. Scala version (2016) using case classes

    4. Lua version (2013) implements slightly different problem

  6. (9 Mar) No formal class. Work on new Assignment #3. Study the following handouts for discussion after Spring Break

    1. (assigned first week of semester) James Coplien, Daniel Hoffman, and David Weiss. Commonality and Variability in Software Engineering, IEEE Software, Vol. 15, No. 6, November 1998.

    2. Paper “A Little Language for Surveys: Constructing an Internal DSL in Ruby” BELOW

    3. Conrad Barski. Building a Text Game Engine, Chapter 5, In Land of Lisp: Learn to Program in Lisp, One Game at a Time, pp. 69-84, No Starch Press, 2011.

      The Common Lisp example in this chapter is similar to the classic Adventure game; the underlying data structure is a labeled digraph.

      There is m<ore information about both labeled digraphs and the Wizard’s adventure game BELOW.

  7. (12-16 Mar) Enjoy Spring Break!

Analysis and Design of DSLs

  1. (19-21, 2-6 Apr) Resume direct discussion of Domain Specific Languages notes

  2. (21-26 Mar) Discuss commonality and variability analysis paper:

    James Coplien, Daniel Hoffman, and David Weiss. Commonality and Variability in Software Engineering, IEEE Software, Vol. 15, No. 6, November 1998.

  3. (dates below) Examine Cunningham’s Survey DSL case study, in particular the analysis and DSL design

    1. (28 Mar; 2 Apr) Discuss paper: H. Conrad Cunningham. A Little Language for Surveys: Constructing an Internal DSL in Ruby, In Proceedings of the ACM SouthEast Conference, 6 pages, March 2008.

    2. (2 Apr briefly) Ruby source code (2006, 2008)

  4. (dates below) Study object-oriented software development

    1. (for reference) Study domain analysis

      • (not updated) Instructor’s slides on Domain Modeling (Powerpoint), for course registration system example

      • Alistair Cockburn. Introduction, Chapter 1 in Writing Effective Use Cases, Addison-Wesley, 2001.

      • Doug Rosenberg with Kendall Scott. Domain Modeling, Chapter 2 in Use Case Driven Object Modeling with UML, Addison Wesley 1999.

      • Doug Rosenberg with Kendall Scott. Use Case Modeling, Chapter 3 in Use Case Driven Object Modeling with UML, Addison Wesley 1999.

    2. (6-13 Apr) Instructor’s notes on Object-Oriented Software Development

    3. (6-11 Apr) Instructor’s notes on Programming Paradigms – a draft “chapter” from the evolving “textbook” Exploring Languages using Interpreters and Functional Programming

    4. (9 Apr) Discuss type systems terminology from Python 3 Metaprogramming notes

    5. (for reference) Instructor’s notes on the Kinds of Polymorphism

  5. (13 Apr) Distribute Assignment #4 (Final Project)

  6. (dates below) Continue study of object-oriented software development

    1. (16-18 Apr) Instructor’s slides on Using CRC Cards (Class-Responsibility-Collaboration) (HTML)

    2. (for reference) Ralph E. Johnson and Brian Foote. Designing Reusable Classes, Journal of Object-Oriented Programming, Vol. 1, No. 2, pages 22-35, June/July 1988.

    3. (for reference) A simple example of the open-closed principle

    4. (for reference) SOLID Design Principles, a look at the core SOLID principles through the lens of modularity.

    5. (for reference) “Uncle” Bob Martin video on “SOLID Principles of Object-Oriented and Agile Design”

  7. (for reference, slides need additional updating) Examine object-oriented programming

    1. Understanding Inheritance, based on Timothy Budd’s Understanding Object-Oriented Programming with Java, Chapter 8: [Powerpoint]

    2. Software Reuse, based on Timothy Budd’s Understanding Object-Oriented Programming with Java, Chapter 10: [Powerpoint]

    3. Replacement and Refinement, loosely based on Timothy Budd’s An Introduction to Object-Oriented Programming, Third Edition, Section 16.2: [Powerpoint]

    4. Implications of Inheritance, based on Timothy Budd’s Understanding Object-Oriented Programming with Java, Chapter 11: [Powerpoint]

    5. Multiple Inheritance, based on Timothy Budd’s An Introduction to Object-Oriented Programming, Third Edition, Chapter 13: [Powerpoint]

    6. Polymorphism, based on Timothy Budd’s Understanding Object-Oriented Programming with Java, Chapter 12: [Powerpoint]

    7. Second Look at Classes, loosely based on Timothy Budd’s An Introduction to Object-Oriented Programming, Chapter 25 on Reflection and Introspection: [Powerpoint]

    8. Luca Cardelli and Peter Wegner. On Understanding Types, Data Abstraction, and Polymorphism, ACM Computing Surveys, Vol. 17, No. 4, pp. 471-523, 1985.

  8. (20-25 Apr) Do object-oriented analysis and design in class for a “choose your own adventure” game

    1. Reference: Conrad Barski. Building a Text Game Engine, Chapter 5, In Land of Lisp: Learn to Program in Lisp, One Game at a Time, pp. 69-84, No Starch Press, 2011.

      The Common Lisp example in this chapter is similar to the classic Adventure game; the underlying data structure is a labeled digraph.

      There is more information about both labeled digraphs and the Wizard’s adventure game BELOW,

    2. Adventure Game Analysis

Python 3 Metaprogramming

  1. (25-30 Apr, 2-4 May) Explore Python 3 Reflexive Metaprogramming

    1. Introduction [HTML] [PDF]

    2. Basic Features Supporting Metaprogramming [HTML] [PDF]

    3. Decorators and Metaclasses (for Debugging Case Study) [HTML] [PDF]]

Not Discussed Spring 2018 (For Reference)

Ruby DSLs

  1. (for reference) Background on writing Ruby DSLs

    1. Jim Freeze. Creating DSLs with Ruby, Artima Developer, March 2006.

    2. Jamis Buck. Writing Domain Specific Languages, The Bucklog (blog), 20 April 2006.

    3. Rake (Ruby Make), a software management and build tool written as a Ruby internal DSL

  2. (for reference) Discuss Fowler’s DSL Reader framework

    1. Background:

      Ruby DSLs (2006)

    2. Ruby shared modules

    3. Ruby direct configuration and testing of Reader

    4. Ruby single-pass external text DSL

    5. Ruby two-pass external XML DSL

    6. Ruby internal DSL

Language Processing

  1. (for reference) Study Parsing Expression Grammars (PEGs)

    1. Wikipedia entry on Parsing Expression Grammar

    2. Bryan Ford. Packrat Parsing: Simple, Powerful, Lazy, Linear Time, Functional Pearl. In Proceedings of the seventh ACM SIGPLAN International Conference on Functional Programming (ICFP ’02), ACM, pp, 36-47, 2002.

    3. Bryan Ford. Parsing Expression Grammars: A Recognition-Based Syntactic Foundation, ACM SIGPLAN Notices, Vol. 39, No. 1, pp. 111-122, 2004. [slides]

  2. (for reference) Arithmetic expression tree program skeletons

    1. Background: These are expanded from the example in Notes on Scala for Java Programmers.

      Scala versions (2008-16)

    2. Scala recursive function version using case classes

    3. Scala traditional object-oriented version

      Haskell version (2017)

    4. Haskell Expression Tree Calculator case study [source]

      Lua versions (2013-16)

    5. Lua recursive function versions (2013, 2014)

    6. Lua object-oriented versions (2013, 2016)

    7. Lua LPEG parsers (2013)

Exploring Languages using Interpreters

Haskell

  1. (for reference, from 2017 CSci 450) Explore the Expression Language Syntax and Semantics (Chapter 10)

    1. Supplemental slides:

    2. Code in work:

  2. (for reference, from 2017 CSci 450) Explore the Expression Language Parsing (Chapter 11)

    1. Supplemental slides:

    2. Code in work:

  3. (for reference, from 2017 CSci 450) Explore the Expression Language Compilation (Chapter 12)

    1. Code in work:

  4. (for reference, from 2017 CSci 450) Explore the Imperative Core Language: No notes or slide yet, but the code follows

    1. Modules

Lua

  1. (for reference, from 2016 CSci 450) Examine modularized Expression Language 1 interpreter

    1. Modules

    2. Scripts to execute and test:

  2. (for reference, from 2016 CSci 450) Imperative Core Language

    1. Modules

    2. Run and test scripts

Kamin Interpreters

  1. (for reference, not updated) Kamin Interpreters in Lua Toolset (KILT)

    1. Kamin-Budd Interpreters

      Samuel N. Kamin. Programming Languages: An Interpreter-Based Approach, Addison-Wesley, 1990.

      Note: I implemented the interpreter prototypes below in Lua 5.1 in 2013 for the Fall offering of CSci 658 and for a potential future offering of CSci 450. Some aspects my not work with Lua 5.2 or 5.3.

      I subsequently reimplemented the first with improved modularization in Lua in 2016 and then reimplemented it again in 2017 in Haskell.

    2. Language/Interpreter-independent modules

    3. Kamin Chapter 1 Core language interpreter

    4. Kamin Chapter 2 Lisp language interpreter

    5. Kamin Chapter 4 Scheme language interpreter

Modules and Frameworks

  1. (for reference) Simple, silly Employee hierarchy example

    1. Scala (2008, 2010)

    2. Ruby (2006)

  2. (for reference) Examine a natural number arithmetic package

    This case study has implementations in five different languages (with some slight differences among the examples). So it can be used to compare implementations in different languages.

    1. Background on Peano arithmetic

    2. Lua version (2013)

    3. Elixir version (2015)

    4. Scala versions (2012, 2016)

    5. Ruby version (2006)

    6. Java version (2004, 2016), simpler, no generics

  3. (for reference) Abstract data types and modular design

    1. Background: Abstract data types

      • Nell Dale and Henry Walker. Abstract specification techniques, Chapter 1, In Abstract Data Types: Specifications, Implementations, and Applications, pp. 1-34,D. C. Heath, 1996.
      • H. Conrad Cunningham, Yi Liu, and Jingyi Wang. Designing a flexible framework for a table abstraction, Chapter 13 in Y. Chan, J. Talburt, and T. Talley, editors, Data Engineering: Mining, Information, and Intelligence, pp. 279-314, Springer, 2010.
        [manuscript] [slides]
    2. Modular Design

    3. Data Abstraction: [slides]

    4. Abstraction – draft “chapter” from evolving “textbook” Exploring Languages with Interpreters and Functional Programming (some overlap with Data Abstraction document)

    5. Classic papers by David L. Parnas and associates:

    6. William R. Cook. On Understanding Data Abstraction Revisited. In Proceedings of OOPSLA, October 2009. [local]

  4. (for reference) Explore consequences of software architectural mismatch.

    Paper: David Garlan, Robert Allen, and John Ockerbloom. Architectural Mismatch: Why Reuse is So Hard, IEEE Software, Vol. 12, No. 6, November 1995.

    Instructor’s notes on Architectural Mismatch

  5. (for reference) Examine the CookieJar ADT case study (in Scala)

    1. Cookie Jar ADT Problem Description

    2. Specification concepts and notation – from Candy Bowl ADT description

    3. Immutable CookieJar ADT Implementation in Scala (ICookieJar) – uses method chaining functional style with immutable objects

    4. Mutable CookieJar ADT Implementation in Scala (CookieJar) – uses object-oriented style with mutable state

    5. Similar specification and Ruby program

  6. (for reference) Examine Carrie’s Candy Bowl ADT (abstract data type) case study

    1. Lua

    2. Scala

  7. (for reference) Examine the Labeled Digraph case study

    1. Background:

      • Nell Dale and Henry Walker. “Directed Graphs or Digraphs,” Chapter 10, In Abstract Data Types: Specifications, Implementations, and Applications, pp. 439-469, D. C. Heath, 1996.

      • Conrad Barski. “Building a Text Game Engine,”, Chapter 5, In Land of Lisp: Learn to Program in Lisp, One Game at a Time, pp. 69-84, No Starch Press, 2011.

        The Common Lisp example in this chapter is similar to the classic Adventure game; the underlying data structure is a labeled digraph.

    2. Haskell solutions (2015)

    3. Elixir solutions (2015)

    4. Scala solutions (2016)

    5. Using the Elixir Digraph ADT module to build the Wizard’s Adventure game (2015)

  8. (for reference) Examine the Dice of Doom game.

    1. Background: Conrad Barski. Land of Lisp: Learn to Program in Lisp, One Game at a Time, No Starch Press, 2011.

    2. Dice of Doom, Version 1a, is a basic eagerly evaluated version (similar to that developed on pages 303-325 of Land of Lisp). This version supports either two human players or a human player and a simple, minimax search-based “AI” (artificial intelligence) opponent.

    3. Dice of Doom, Version 1b, is an eager version above with an attempt at memoization of functions neighbors and game_tree using the Elixir Agent modules.

    4. Dice of Doom, Version 2a, is a lazy version using Elixir Stream data structures (but without the memoization optimizations). This is based on version 1a above plus the discussion from pages 384-389 in chapter 18 of Land of Lisp. This version implements a limited depth minimax search, but it does not implement the artificial intelligence heuristics given in the last part of chapter 18.

  9. (for reference) Explore Systematic generalization.

    1. Hans A. Schmid. Systematic Framework Design by Generalization, Communications of the ACM, Vol. 40, No. 10, pp. 48-51, October 1997.

    2. Hans A. Schmid. Creating Applications From Components: A Manufacturing Framework Design, IEEE Software, Vol. 13, No. 6, November 1997.

    3. Hans A. Schmid. Framework Design by Systematic Generalization, Chapter 15 in M. E. Fayad and R. E. Johnson, editors, Domain-Specific Application Frameworks, pp. 353-378, Wiley, 2000.

    4. Hans A. Schmid. OSEFA: Framework for Manufacturing, Chapter 4 in M. E. Fayad, D. C. Schmidt, and R. E. Johnson, editors, Building Application Frameworks: Object-Oriented Foundations of Framework Design, pp. 43-65, Wiley, 1999.

  10. (for reference) Mark Ardis, Nigel Daley, Daniel Hoffman, Harvey Siy, and David Weiss. Software Product Lines: A Case Study, Software Practice and Experience, Vol. 30, No. 7, pp. 825-847, 2000.

  11. (for reference) Frameworks, based on Timothy Budd’s An Introduction to Object-Oriented Programming, Third Edition, Chapter 21.

    1. Simple Sorting Framework in Scala

    2. Ice Cream Store discrete event simulation

  12. (for reference) Scala Divide-and-Conquer Framework, similar to the Java framework in the paper:

    H. C. Cunningham, Y. Liu, and C. Zhang. Using classic problems to teach Java framework design, Science of Computer Programming, Special Issue on Principles and Practice of Programming in Java (PPPJ 2004), Vol. 59, No. 1-2, pp. 147-169, January 2006. doi: 10.10.16/j.scico.2005.07.009. [manuscript]

    Note: The above paper was not discussed in class, but the Scala versions of the Divide-and-Conquer (immediately below) and Binary Tree Traversal (farther down on this page) frameworks were discussed.

  13. (for reference) Binary Tree Visitor Scala Framework

    1. Background: H. C. Cunningham, Y. Liu, and C. Zhang. Using classic problems to teach Java framework design, Science of Computer Programming, Special Issue on Principles and Practice of Programming in Java (PPPJ 2004), Vol. 59, No. 1-2, pp. 147-169, January 2006. doi: 10.10.16/j.scico.2005.07.009.
      [manuscript]

      Scala versions (2008, 2010)

    2. Straightforward translation of the non-generic Java program to Scala

    3. Generic implementation of BinTree framework in Scala.

  14. (for reference) Study the Movable and Named Objects case study (in Lua but based on a Haskell case study by Thompson)

    1. Purpose: The Named and Movable Objects case study explores use of inheritance hierarchies and multiple inheritance in Lua. I also extracted a “class support module” from the initial version of this code; this module was used in later case studies (e.g., Lair Configuration DSL).

      The “makeClass” function dynamically creates a “class” that has zero or more superclasses. It creates the class prototype object with an appropriate constructor/initialization function, appropriate default definitions of instance methods, and the needed settings of metaclasses and the __index metamethod to support the inheritance hierarchy.

    2. Background reading on object-oriented programming languages: Object-oriented subsection of the Fundamental Concepts of Programming Languages notes

    3. Background reading on case study: Section 14.6 of Simon Thompson. Haskell: The Craft of Functional Programming, Third Edition, Addison Wesley, 2011

      Note: We should readdress the design and implementation of this case study and the class support module. The latter may be too complex for our purposes in this course.

    4. First Lua version (movable.lua)

    5. Modularized Lua version with improved class support:

    6. Other older versions:<

  15. (for reference) Study the prototype-based programming example

    Comments: Lua is essentially a prototype-based programming language. A Lua table has its own state, a unique identity, and an independent lifecyle. By assigning function closures to identifier-style keys, a table can also have its own operations. The method-call syntax enables these operations to refer to its associated table conveniently.

    The Lua metatable and metamethod features enable a table to delegate some of its work conveniently to other tables. In particular, the __index metamethod enables accesses to data fields or operations not defined in one table to other tables.

    The previous “object-oriented” Arithmetic Expression Tree and Movable & Named Objects examples use Lua’s prototype-based features to implement classes and inheritance structures.

    This module uses those features in a more straightforward prototype-based approach–by creating a “copy” of the prototype object. It provides two constructor functions, set up to use the method-call syntax.

    Constructor method Prototype:new creates a new object as a shallow copy of the table parameter mixin with other references delegated to object self. A call Prototype:new creates a basic object that delegates to object Prototype. If obj has been created by this new method, then a call of obj:new creates a new object that delegates to obj rather than Prototype. (This is different from the way Lua classes are implemented.)

    Constructor method Prototype:clone creates a new object that is a shallow copy of object self and then mixes in the fields and methods from mixin. It delegates accesses to any undefined fields to whatever object self does.

    Concepts: Prototype object, delegation, shallow copy, mixin

  16. (for reference) Examine Rational Arithmetic case study (data abstraction)

    Note: I have rewritten this 2016 case study to use Haskell and incorporated it into the draft Abstraction “chapter” of Exploring Languages with Interpreters and Functional Programming

    1. Using Data Abstraction in Lua

    Example motivated by sections 2.1.1 and 2.1.2 from: Harold Abelson and Gerald J. Sussman with Julie Sussman. Structure and Interpretation of Computer Programs, Second Edition, MIT Press, 1996

    SICP video lectures, Hal Abelson

    Concepts: designing modules with multiple implementations, data abstraction barrier (“building the wall”), canonical forms, using Lua modules, using higher order functions, using closures/thunks to encapsulate data

    1. Rational arithmetic module – outer layer implementation of Rational Arithmetic abstraction

    2. Rational number data representation using two-element arrays – primitive layer implementation 1
      [module] [test script]

    3. Rational number data representation using array but deferring GCD – – primitive layer implementation 2
      [module] [test script]

    4. Rational number data representation using closures – primitive layer implementation 3
      [module] [test script]

  17. (for reference) Examine the complex number arithmetic modules in Lua

    Modules are repeated in each package in which they are used

    1. Background reading: Structure and Interpretation of Computer Programs, Second Edition, MIT Press, 1996, Section 2.4

      SICP video lectures, Hal Abelson

    2. Rectangular coordinates modules:
      [arithmetic] [rectangular representation] [utilities] [test driver]

    3. Polar coordinates modules:  
      [arithmetic] [polar representation] [utilities] [test driver]

    4. Tagged data modules:   [arithmetic] [data tagging] [utilities] [test driver]

    5. Data-directed programming modules:  
      [arithmetic] [rectangular representation] [polar representation] [data tagging] [utilities] [test driver]

    6. Object-oriented modules:
      [arithmetic] [utilities] [test driver]

  18. (for reference) Lua list module case study (Cell List)

    Purpose: This Lua case study illustrates (i) functional programming principles, (ii) design and implementation methods for abstract data types and information hiding modules, and, (iii) Lua programming techniques (linked lists, stateless iterators, closures, metatables, etc.)

    Background reading on Lua: Chapter 11 on data structures (pages 107-116) and Chapter 15 on modules (pages 151-161) of Programming in Lua (PiL), Third Edition

    Caveats: (1) These modules (from 2013-14) internally layer the operations into primitive and non-primitive operations, but they do not separate the primitive operations into its own module. That can be done similarly to the Rational Arithmetic case study. (2) In the future, I plan to construct a more efficient implementation that uses array-style tables. The table-based versions likely also need to use weak tables to avoid memory leaks.

    1. Cell-based list module:
      [module source] [test driver]

    2. Closure-and-table-based list module variant:
      [module source] [test driver]

    3. Function-based cell list module variant:
      [module source] [test driver]

    4. Lazy list module variant using C preprocessor (cpp -P):
      [module source] [source after cpp]
      [test driver] [driver after cpp] [sh script]

    5. Lazy list module variant using Lua Macro 2.5:
      [macro definitions] [module macro source] [source after luam -o]
      [macro test driver] [driver after luam -o] [sh script]

  19. (for reference) Examine functions adapted from SICP

    1. Background reading: Chapter 1 of the classic textbook SICP – Harold Abelson and Gerald J. Sussman with Julie Sussman. Structure and Interpretation of Computer Programs, Second Edition, MIT Press, 1996:
      [book site at MIT Press] [HTML] [SICP ebook site

    2. First-order functions in Scala

    3. Higher-order functions in Scala

    4. Lua versions

    5. Also various Haskell, Elixir, Elm, and Scheme versions

  20. (for reference) Examine Square Root case study (stepwise refinement)

    1. Using Stepwise Refinement in Lua

    Concepts: TBD (examine the notes to see what was covered)

    Example motivated by sections 1.1.7 and 1.1.8 from: Harold Abelson and Gerald J. Sussman with Julie Sussman. Structure and Interpretation of Computer Programs, Second Edition, MIT Press, 1996

    SICP video lectures, Hal Abelson

    1. Square root

Programming Language Reference Materials

  1. Free online programming language textbooks and tutorials

Haskell

  1. Learn X in Y Minutes, Where X = Haskell

  2. H. Conrad Cunningham. Introduction to Functional Programming Using Haskell, Computer and Information Science, University of Mississippi, 2016-2017. (I am writing this “textbook” primarily for CSci 450 and likely will use the title Exploring Languages with Interpreters and Functional Programming for the Fall 2018 draft.)

  3. H. Conrad Cunningham. Notes on Functional Programming with Haskell, Computer and Information Science, University of Mississippi, 1994-2014. (I am revising this document and integrating it with other materials to produce the new “textbook” above Exploring Languages with Interpreters and Functional Programming. The chapters at the chapters at the end have not yet been integrated.)

  4. Haskell language website

    1. Haskell 2010 Language Report
    2. GHC User’s Guide
  5. Haskell Cheat Sheet

  6. School of Haskell online tutorials

  7. Miron Lipovaca. Learn You a Haskell for Great Good: A Beginner’s Guide, a free online tutorial at http://learnyouahaskell.com/. (It is also in print from No Starch Press, 2011.)

  8. Kees Doets and Jan van Eijck. The Haskell Road to Logic, Math and Programming, March 2004. This book is also available in print, published by College Publications, 2004.

  9. Paul Hudak. The Haskell School of Music: From Signals to Symphonies, Version 2.6, January 2014. This book is a recent rewrite of Hudak’s The Haskell School of Expression: Learning Functional Programming through Multimedia, Cambridge University Press, 2000.

  10. Simon Marlowe. Parallel and Concurrent Programming in Haskell: Techniques for Multicore and Multithreaded Programming,
    1. This book is also available in print, published by O'Reilly Media, 2013.
  11. Bryan O'Sullivan, Don Stewart, and John Goerzen. Real World Haskell,
    1. This book is also available in print, published by O'Reilly Media in November 2008.

Lua

  1. Learn X in Y Minutes, Where X = Lua

  2. Definitive reference: Roberto Ierusalimshcy. Programming in Lua, Fourth Edition, Lua.org, Rio de Janiero, Brazil, 2016. (The First Edition of this book, covering Lua 5.0, is available online at https://www.lua.org/pil/contents.html.)

  3. Instructor’s Lua slides (from CSci 450, Fall 2016)

    1. Background: The slides below are adapted, in part, from Programming in Lua, Slides for Course by Fabio Mascarenhas from the Federal University of Rio de Janeiro, Brazil. He taught a course, which used Lua 5.2, at Nankai University, P. R. China, in July 2013.
    2. Introduction to Lua slides based, in part, on Mascarenhas slide sets 0-5
    3. Advanced Lua Functions slides based, in part, on Mascarenhas slide set 6
    4. Modules in Lua slides based, in part, on Mascarenhas slide set 9
    5. Lua Metatables slides based, in part, on Mascarenhas slide set 10
    6. Lua Objects slides based, in part, on Mascarenhas slide set 11

Python 3

  1. Learn X in Y Minutes, Where X = Python3

  2. Bernd Klein. Python Course

Ruby

  1. Learn X in Y Minutes, Where X = Ruby

  2. Chris Pine. Learn to Program

  3. why the lucky stiff (Jonathan Gillette). why's (poignant) guide to Ruby

Scala

  1. Learn X in Y Minutes, Where X = Scala

  2. Definitive reference: Martin Odersky, Lex Spoon, and Bill Venners. Programming in Scala, Third Edition, Artima, 2016. The first edition (2008) is available online at http://www.artima.com/pins1ed/.

  3. Martin Odersky. Scala by Example, EPFL, 2014. [local]

  4. Instructor’s Notes on Scala for Java Programmers

  5. Paul Chiusano and Runar Bjarnason. Functional Programming in Scala, Manning, 2015.

    1. Instructor’s Notes on Functional Data Structures (Chapter 3)
    2. Instructor’s Notes on Error Handling without Exceptions (Chapter 4)
    3. Instructor’s Notes on Strictness and Laziness (Chapter 5)