Lecture Notes

Go To Current Lecture --

Schedule, Notes, and Examples

  1. (22 Aug) Discuss syllabus and class organization

  2. Discuss fundamental programming language concepts [HTML] [PDF]

    Concepts: programming language paradigm, imperative language, declarative language, functional language, relational or logic language; program state, implicit versus explicit state; execution of commands versus evaluation of expressions, history of programming languages

    1. (24, 26 Aug) Focus on the sections 1.2, 1.3., and 1.5 for now. We address section 1.4 later.

    2. (26, 29 Aug) History of Programming Languages HTML slides (slides for section 1.5 material in above notes)

  3. (29, 31 Aug) Discuss textbook Chapter 1 slides beginning with Compilation and Interpretation on slide 14

    Concepts: TBD (examine the notes and textbook chapter)

  4. Introduce Lua programming language (part 1)

    1. Reference: Roberto Ierusalimshcy. Programming in Lua, Fourth Edition, Lua.org, Rio de Janiero, Brazil, 2016. The First Edition of this book is available online at https://www.lua.org/pil/contents.html; it covers Lua 5.0.

    2. 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.

    3. (31 Aug; 2, 9, 12 Sep) Introduction to Lua slides based, in part, on Mascarenhas slide sets 0-5

    Concepts: Lua design principles, REPL, chunk, script, data types and operators (e.g., nil, boolean, number, string, table, function), dynamic vs. static typing, first-class functions (first-class, anonymous, variadic, multiple return), statements (multiple assignment, if, while, repeat, numeric for, generic for, do), tables (as array, matrix, record, set)

  5. Examine Expression Language 1 for Assignment 1

    Purposes: The purposes of this case study and assignment are (a) to examine the design and implementation of a simple expression language that includes integer values, variables, arithmetic operators, relational comparison operators, and conditional statements and (b) to use the Lua programming concepts learned in the early part of the semester to extend the implementation. Although not part of the assignment, the interpreter also exhibits modularization and use of the LPEG parsing library.

    Concepts: expression, concrete and abstract syntax, parsing, environment, evaluation, modularization in general, using Lua modules, using Lua tables to represent "algebraic data types" (as in the abstract syntax), read-evaluate-print-loop (REPL)

    1. (7-16 Sep) Monolithic script file (expr01.lua) given with Assignment #1

    2. (21 Sep) Modularized source code (new baseline after assignment)

      Modules:

      Scripts to execute and test:

  6. (14 Sep) 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
  7. (for reference) Examine a natural number arithmetic package

    1. Notes:

      We did not cover this example explicitly in 2016, but the Lua implementation is an example of Lua programming using tables, data abstraction, and recursion. The file contains both the function definitions and a partial test script. I did not modularize the Lua code, but I did implement it so that the primitive representation/operations layer can separated into a module used by the outer, nonprimitive operations layer, which can itself be a separate module used by clients (such as the partial test script).

      This case study has implementations in four different languages (with some slight differences among the examples). So it can be used to compare implementations in different languages. In particular, the Java implementation should be accessible to Ole Miss CS students.

      The Lua and Elixir implementations are not "object-oriented', but the Java, Ruby, and some of the Scala versions are object-oriented.

    2. Concepts: Natural numbers, Peano arithmetic; functional programming, data abstraction, use of Lua tables and modules; (Scala, Ruby, and Java versions use object-oriented design patterns such as Composite, Singleton, and Null Object)

    3. Background on Peano arithmetic

    4. Background on software design patterns

    5. Lua version (2013)

    6. Elixir version (2015)

    7. Scala versions (2012)

    8. Ruby version (2006)

    9. Java version (2004, minor mods 2016), simpler, no generics

  8. Introduce Lua programming language (part 2)

    1. (14-16 Sep) Advanced Lua Functions slides based, in part, on Mascarenhas slide set 6

    Concepts: lexical scope, higher-order functions, closure, callback, functional programming (map, filter, folds) Currying, partial application

    1. (16-19 Sep) Modules in Lua slides based, in part, on Mascarenhas slide set 9

    Concepts: module, information hiding, interface, abstract interface, module and interface design criteria, Lua module implementation

  9. (19-21 Sep) Examine Rational Arithmetic case study (data abstraction)

    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]

  10. (21 Sep) Examine modularized code above for Expression Language 1

  11. (for reference) Study a Lua expression tree parser using LPEG

    Note: This example is similar to the Expression Language 1 infix parser. However, this example does not have the relational operators or the if-expression from the Expression Language, but it does have function call syntax. I began with this code from 2013 when I was developing the infix parser.

  12. (23-28 Sep) Examine Imperative Core (ImpCore) language for Assignment #2

    1. Imperative Core Language

    2. Study code for ImpCore interpreter

      Modules:

      Run and test scripts:

      Modules and scripts revised to handle multi-expression scripts (added 20 Oct, after assignment):

    3. (28 Sep) The planned exam was rescheduled for Friday, 30 Sep. We examined the ImpCore syntax and semantics, studied the LPEG-based Parser module, traced the ImpCore feature changes through the Parser, Abstract Syntax, and Evaluator modules.

  13. (23-28 Sep) Discuss examination #1 rescheduled for Friday, 30 September

    Examination #1 was rescheduled for Friday, 30 September. It will cover all material covered in the notes, slides, and examples above.

    Examples below such as the functions from SICP, Carrie's candy bowl, Lua "cell" lists, and complex numbers also illustrate the concepts and techniques we have used.

  14. (30 Sep) Take Examination #1

  15. (3 Oct) Return and discuss Examination #1

  16. (5-7 Oct) Discuss Lua Metatables -- slides based, in part, on Mascarenhas slide set 10

    Concepts: metatable; metamethod; Lua metatable & metamethod-related functions; shared metatable; overriding operation behavior; use of metamethods such as __add, __len, __eq, __lt, __le, __index, __newindex, and __tostring; proxy tables example

  17. Discuss other programming paradigms

    1. (7-12 Oct) Procedural, modular, and (primarily) object-oriented paradigms (Section 1.4 of Fundamental Concepts document)

      [HTML] [PDF]

    Concepts: procedural programming/language; modular programming/language; object-oriented programming/language; object model; objects with state, operations, identity, encapsulation, and independent lifecycle; mutable and immutable objects; object-based language; class; instances/objects; type; class-based language; dynamic and duck typing; inheritance; base/parent/superclass; child/derived/subclass; generalization and specialization; multiple inheritance; interfaces and implementations; substitution principle for subclasses; polymorphism (see separate handout); dynamic binding; overriding; object-oriented language; prototype-based language; prototype; delegation rather than inheritance; slots; how does Java fit? Lua?

    1. (12 Oct) Kinds of polymorphism in programming languages

    Concepts: polymorphism, ad hoc polymorphism, overloading, subtyping (subtype polymorphism, polymorphism by inclusion, polymorphism by inheritance), parametric polymorphism (generics), early and late binding, polymorphism in dynamically typed languages

    CSci 555 Notes on this topic from which the above was adapted

    1. (14-17 Oct) Lua Objects slides based, in part, on Mascarenhas slide set 11

    Concepts: a simple Lua object model; Lua tables as objects; method; receiver object; colon method call operator; self; syntactic sugar; Lua classes as modules; using metatables and metamethod __index to construct classes and superclasses; constructor; class method; instance method; examples of classes and superclasses; instance-of;

  18. (10-12 Oct) Discuss Assignment #3 on simplification of abstract syntax trees

    Concepts: simplification of abstract syntax trees to enable more efficient interpretation and code generation, recursive programming of multiway tree data structures, preserving the semantics of expressions, side effects of expression evaluation/execution, more on the structure of language processors

  19. Examine Arithmetic Expression Tree program skeletons (Lua)

    These are program skeletons provided for course assignments in 2013 and 2014. They involve symbolic differentiation as well as evaluation and simplification of arithmetic expression trees. So the expression trees differ somewhat from those used in the interpreters. However, the general recursive approach is the same as used in Assignment #3. The object-oriented versions are similar to Assignment #4 in this course.

    1. Functional versions

    Background reading: Programming in Lua (PiL), Chapter 11 of the First, Second, or Third Edition or Chapter 14 of the Fourth Edition, for table-based implementations of various data structures in Lua

    (7 Nov for Assignment #4 questions) Recursive Functions with Record Representation (exprRecFuncRecord.lua)

    (7 Nov for Assignment #4 questions) Functions with List Representation (exprRecFuncList2.lua)

    (17 Oct) Function Table with List Representation and Evaluation Table (exprEvalTable2.lua).

    Purpose: I include this example here because of its use of an "evaluation table" (evalTab) in the evaluation function and the "derivation table" (derivaTab) in the differentiation function. Instead of using large if-elseif-else structures, this version uses "hash" tables indexed by the node type tag. (So it is likely more efficient as the number of tags gets large.) The values stored in the tables are the function closures to be executed. This approach uses the __index metamethod to try invalid accesses.

    Useful extensions: Use a shared metatable for all expression tree "objects" created by the constructor functions. This would allow isExp to be reimplemented to check the existence of the metatable and also allow tostring to be delegated to the valToString function directly.

    1. (17-19 Oct) Object-oriented versions

    Background reading: Programming in Lua (PiL), Chapter 16 of the First, Second, or Third Edition or Chapter 21 of the Fourth Edition, for object-oriented programming in Lua

    Prototype Object-Based (exprObjBased.lua) -- uses Lua method calls, tables, metatables, and __index metamethod to implement "classes" but not inheritance

    Concepts: prototype object; class; constructor (factory method); Lua method calls using: (colon); Singleton design pattern

    Object-Oriented with Inheritance (exprObjInherit2.lua) -- extends the above example to implement an "abstract" superclass and inheritance

    Concepts: prototype object; class; subclass (child class) superclass (parent or base class); abstract and concrete classes, single inheritance, abstract (deferred) methods; constructor (factory method); accessor and mutator methods; proxy object; method injection; Singleton, Null Object, and Template Method design patterns

    1. (for reference) Expression parser (repeated from above for completeness)

    with string and table captures (exprParser.lua)

    adding semantic action function (exprParserSemantic.lua)

  20. (21-24 Oct) 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.

    1. Concepts: prototype object; class; subclass (child class) superclass (parent or base class); abstract and concrete classes, single and multiple inheritance, abstract (deferred) methods; constructor (factory method); accessor and mutator methods; proxy object; method injection; template method design pattern (template and hook methods); Singleton and Null Object design patterns;

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

    3. (for reference) 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.

    1. (for reference) First Lua version (movable.lua)

    2. Modularized Lua version with improved class support:

    class support module (class_support.lua)

    module using class-support (movable2.lua)

    test driver (movable2Test.lua)

    1. (for reference) Other older versions:

    Haskell source

    Scala source (partial)

  21. (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

  22. (24 Oct) Introduce concept of metaprogramming ("writing code that writes code")

    1. Background: Metaprogramming, Wikipedia article

    Definition (Wikipedia): Metaprogramming is the writing of computer programs with the ability to treat programs as their data. It means that a program could be designed to read, generate, analyse and/or transform other programs, and even modify itself while running.

    Definition: Reflexive metaprogramming is the writing of computer programs that manipulate themselves as data.

    Concepts: Metaprogramming, metalanguage, object language, reflection (reflectivity), homoiconicity.

    1. Question: Java is a statically typed, compiled language. What are metaprogramming features available in Java?

    dynamic class loaders, reflection API, annotation processing, dynamic method invocation (JVM feature), JVM bytecode manipulation (mostly with external tools), etc.

    1. Question: Lua is a dynamically typed, interpreted language. What are the metaprogramming features available in Lua?

    metatables, metamethods, manipulation of environments, debug library (introspection/reflection features), loadfile and loadstring functions to dynamically execute code, extensions in C, etc.

  23. (26 Oct, 7 Nov) Discuss Assignment #4

    This assignment expects the solution to use the "object-oriented" or "prototype-based" approach in Lua, as discussed in this course.

    That is, each expression "subclass" (e.g., Add) should have an eval method that evaluates that particular type of expression object. The selection of which method to execute should not be determined by an if-then-else construct but by the "dynamic binding" of the method call to the appropriate implementation. This is the approach that is considered a "best practice" in an object-oriented language such as Java.

    The examples below illustrate this in various languages.

    The references below discuss design principles for object-oriented programs. In particular, the open-closed principle is relevant.

    (7 Nov) I discussed Assignment #4 using the Arithmetic Expression Tree background examples below.

    1. Background on object-oriented design:

    2. Background examples:

      This set of examples gives skeletons for an assignment in another course that is similar to this assignment. The modular list- and record-based versions illustrate approaches similar to the modularized ImpCore interpreter. The object-oriented version object-oriented versions give partial solutions that illustrate an approach that can be taken to Assignment #4.

      This version does not implement classes or inheritance, but shows how a delegation to a prototype object or cloning a prototype can accomplish much the same.

      The approach taken in the Complex Arithmetic implementation is a bit different from the the other object-oriented examples. The superclass has a constructor new and two "factory" methods. Each subclass implements the two "factory" methods that create complex numbers depending on the chosen coordinate system. The superclass factory methods call down to the like-named factory methods in the subclasses. This creates an unusual coupling down the class hierarchy that violates the open-closed principle for OO design. This structure should be reexamined in a future design.

  24. (26-8 Oct) Chapter 2 slides (slides 1-11 and 22-28)

    The focus here is on slides 1-11 and 22-28, which cover the general aspects of language parsing but not the specific implementation techniques for scanners and parsers.

    The course CSci 311 Models of Computation covers the theory of regular and context-free languages and related automata.

    We implemented the scanner/parser functionality using the LPEG module in Lua. The processing of the language syntax is encapsulated within the Parser modules of our modularized Expression Language 1 and Imperative Core Language (ImpCore) interpreters. There is no separate scanner component.

    LPEG grammars can parse deterministic context-free languages.

  25. (31 Oct) Review for Exam 2 (Exam 2 moved to 2 Nov)

  26. (2-4 Nov) Take Examination #2 (Take Home)

    Exam 2 covers the material discussed in class since Exam #1 plus the Imperative Core Language interpreter (used in Assignments #2 and #3) and the instructor's introductory Lua slides (similar to the ones created by Dr. Fabio Mascarenhas).

    Exam #2 will not cover textbook chapter 3 on "Names, Scopes, and Bindings" or the accompanying slides.

  27. (4 Nov) Enjoy guest lecture on Elm programming by Nate Clark (Technical Direct, Base Camp Coding Academy)

    Concepts: functional programming, Elm programming language, model-view-controller pattern, Elm architecture for front-end Web applications, algebraic data type

  28. (7 Nov) Review concepts for Assignment #4

  29. Continue discussion of Elm language and programming

    Concepts: functional programming, basic syntax and semantics of Elm, recursion, backward recursion, forward recursion, linear recursion, tail recursion, accumulating parameter

    1. (7-11 Nov) Learn X in Y Minutes, X == Elm

      Note: The Learn X in Y Minutes tutorial uses a few Elm features that do not seem to be in the current version of Elm (0.18). These are in Haskell and may have been in earlier versions of Elm.

      • The notation [1..5] does not seem to be defined. We can use the function call List.range 1 5 instead.

      • Component extraction functions fst and snd for tuples do not seem to be defined. We can use functions Tuple.first and Tuple.second instead.

    2. Elm Language website

    3. Instructor's examples

    4. (16 Nov, mostly for reference) Review notes on recursion concepts

    Concepts: forward and backward recursion, linear and nonlinear recursion, tail recursion, accumulating parameter, logarithmic recursion

    Comment: Tail recursion is an important property of function definitions. It can sometimes be used to derive a more time-efficient algorithm. This is the case with the Fibonacci and Exponentiation series of examples.

    Tail call optimization (or tail call elimination or proper tail calls) is a useful property of language implementations. It can result in more space-efficient algorithms by converting function calls into "loops" (e.g., by reusing the caller's stack frame).Moreover, this may make it possible to evaluate some expressions that otherwise would result in stack overflow.

    Lua supports tail call optimization.

    Elm probably supports tail call optimization in limited circumstances--some self-recursive calls can be translated to loops, but it does not support indirect recursions. (It is based on JavaScript; current implementations of JavaScript 5 do not usually support tail call optimization.)

    1. (for reference) Elm Tutorial (GitBook)

    2. (for reference) Awesome Elm tutorial list

  30. (14-18, 28 Nov) Study Names, Scopes, and Bindings from PLP textbook Chapter 3: slides

  31. (16 Nov) Discuss Assignment #5, which involves Elm programming. You likely will need to study the tutorials and examples

  32. (18, 28 Nov) Study Subroutines and Control Abstractions form PLP textbook Chapter 9: slides

  33. (28 Nov) Review for Exam 3

  34. (30 Nov) Take Examination #3 (2 Dec) Take-Home Component

    Exam #3 focuses on the content covered since Exam #2 including the Elm language and Elm programming techniques and chapters 3 and 9 of the textbook. Students should study the Elm tutorials and the notes on recursion concepts and work on Assignment #5 to become familiar with Elm.

    Exam #3 will not explicitly cover the Lua object-oriented material from Assignment #4. However, the exam questions will assume that you are familiar with the programming language and programming techniques we have studied this semester and they will assume that you are familiar with Java (taken in prerequisite courses).

  35. (2 Dec) Discuss Exam #3 and Final Examination

    Take Home Exam Solution

  36. (7 Dec) Take Final Examination

  37. (12 Dec) Enjoy Winter Break

    EXTRA MATERIALS NOT EXPLICITLY COVERED FALL 2016

  38. (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

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

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

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

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

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

  39. (for reference Discuss Domain-Specific Languages, from instructor's lecture notes

    Concepts: domain-specific languages (DSLs); DSLs versus general-purpose programming languages; external versus internal DSLs; shallow versus deep embedding of internal DSLs; use of algebraic data types to implement DSLs

  40. (for reference) Discuss Sandwich DSL case study

    1. Scala Sandwich DSL Case Study, instructor's lecture notes (with exercises)

    Scala code

    1. Haskell SandwichDSL Case Study, instructor's lecture notes (with exercises)

    Haskell code

    1. Lua Sandwich DSL Case Study (similar but not identical to above)

    Semantic Model module

    DSL Builder module using function sequence pattern (sandwich_builder.lua)

    Test driver (test_sandwichDSL.lua)

  41. (for reference) Discuss Fowler's Lair Configuration DSL in Lua

    1. Background reading on case study:
      Martin Fowler, One Lair and Twenty Ruby DSLs, Chapter 3, The ThoughtWorks Anthology: Essays on Software Technology and Innovation, The Pragmatic Bookshelf, 2008

    2. Background reading on DSL patterns: DSL patterns catalog from Martin Fowler's book Domain Specific Languages, Addison Wesley, 2010

    Caveat: Some of these DSL programs may depend upon features from Lua 5.1 that were changed in Lua 5.2 and 5.3.

    Shared modules

    1. Class support module (same as in Movable Objects case study)
      class support module

    2. Semantic Model
      model module -- test driver

    Internal DSLs

    1. Global Function Sequence
      builder module (builder08.lua) -- dsl script (rules08.lua) -- test driver (test08.lua)

    2. Class Method Function Sequence with Method Chaining
      builder module (builder11.lua) -- dsl script (rules11.lua)

    3. Expression Builder with Method Chaining
      builder module (builder14.lua) -- dsl script (rules14.lua) -- test driver (test14.lua)

    4. Nested Closures
      builder module (builder03.lua) -- dsl script (rules03.lua) -- test driver (test03.lua)

    5. Expression Builder with Object Scoping and Method Chaining
      builder module (builder17.lua) -- dsl script (rules17.lua) -- test driver (test17.lua)

    6. Literal Collection
      builder module (builder22.lua) -- dsl script (rules22.lua) -- test driver (test22.lua)

    External DSL

    1. LPEG Parser/Builder (no corresponding example in Fowler paper)
      builder module (builderLPEG1.lua) -- dsl script (rulesLPEG1.dsl) -- test driver (testLPEG1.lua)
  42. (for reference) Chapter 4 slides

  43. (for reference) Chapter 5 slides

  44. (for reference) Chapter 6 slides

  45. (for reference) Chapter 7 slides

  46. (for reference) Chapter 8 slides

  47. (for reference) Chapter 10 slides

  48. (for reference) Chapter 11 slides

  49. (for reference) Chapter 12 slides

  50. (for reference) Chapter 13 slides

  51. (for reference) Chapter 14 slides

  52. (for reference) Chapter 15 slides

  53. (for reference) Chapter 16 slides

  54. (for reference) Chapter 17 slides

  55. (for reference) Examine functions adapted from SICP

    1. Background: 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

    SICP video lectures, Hal Abelson

    1. Recursion Concepts (Lua) -- improved discussion (Haskell)

    2. Stepwise refinement of Square Root function in Haskell (Section 2.5)

    3. Lua versions (2013):

  56. (for reference) Carrie's Candy Bowl modules in Lua

    Purpose: Carrie's Candy Bowl case study illustrates design and implementation methods for abstract data types (ADTs) and information hiding modules in Lua. It gives formal interface implementation invariants for the ADT module and precondition and postcondition assertions for each function (operation).

    Concepts: information-hiding module, interface, data representation, interface and implementation invariants for abstract data types (ADTs), preconditions and postconditions for ADT operations, mathematical bag

    Background reading on modular programming: Lecture Notes on Data Abstraction

    Caveat: These modules (from 2013-14) provide a common interface to the CandyBowl "type" with different underlying implementations. They do not internally separate the data representation into a separate module (or layer) as the Rational Arithmetic example does.

    1. ADT Problem Description

    2. ADT Semantics

    3. Description of Bag Concept

    4. Data Representations

    5. Hashed version (candybowl_hash.lua)

    6. Unsorted list version (candybowl_list.lua)

    7. Test driver (test_candybowl.lua)

  57. (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.)

    Concepts: information-hiding module, interface, secret, changeability, data representation, interface and implementation invariants for modules (or abstract data types), preconditions and postconditions for functions, primitive operation (function), convenience operation (function), function closure, proxy
  58. 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]

    1. Closure-and-table-based list module variant:

    [module source] [test driver]

    1. Function-based cell list module variant:

    [module source] [test driver]

    1. Lazy list module variant using C preprocessor (cpp -P):

    [module source] [source after cpp]
    [test driver] [driver after cpp] [sh script]

    1. 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]

  59. (for reference) Discuss Computer Configuration DSLs

    1. Semantic Model

    2. Method Chaining Internal DSL

    c Nested Closures and Object Scoping Internal DSL

  60. Develop a Email Message Building Internal DSL using Method Chaining with Progressive Interfaces:

    1. DSL and Semantic Model
  61. (for reference) Develop a State Machine Model and "Secret Panel" Controller External DSLs

    1. State Machine Semantic Model
      StateMachine.scala -- StateMachineTest.scala -- CommandChannel.scala (mock)

    2. XML-based External DSL
      StateMachineXMLTest .scala -- IncrementalStateMachineBuilder.scala -- input file SecretPanel.xml

    3. Custom External DSL with a Delimiter-Directed parser
      DelimiterDSLTest.scala -- IncrementalStateMachineBuilder.scala -- input file CustomExternalStateMachineDSL.dsl

    4. Custom External DSL with handcoded Recursive-Descent parser
      RecursiveDescentTest.scala -- IncrementalStateMachineBuilder.scala -- input file CustomExternalStateMachineDSL2.dsl

    5. Custom External DSL (using Scala parser combinator library) with embedded state machine builder
      CombinatorParserBuilderTest.scala -- IncrementalStateMachineBuilder.scala -- input file CustomExternalStateMachineDSL2.dsl

    6. Custom External DSL (using Scala parser combinator library) with full AST construction
      CombinatorParserASTTest.scala -- input file CustomExternalStateMachineDSL2.dsl --

    7. Static C Code Generator with Model-Aware target platform library
      StaticC _GeneratorTest .scala -- generated C output file output.c

    Note: The needed framework code to run the C program is not yet available in this form. It needs to be reconstructed from Fowler's web site.

  62. (for reference) Examine the Survey DSL

    1. Reference: H. C. Cunningham. "A Little Language for Surveys: Constructing an Internal DSL in Ruby," In Proceedings of the ACM SouthEast Conference, 6 pages, March 2008.

    manuscript -- presentation

    1. Ruby source code -- test DSL input file -- test DSL input file with errors
  63. (for reference) CRuby version of Fowler's DSL framework

    1. DSL Reader Framework module
      ReaderFramework.rb source code

    2. DSL Reader Utilities module, a mix-in used several places
      ReaderUtilities.rb source code

    3. Simple test data files
      Data input file -- Text DSL description -- XML DSL description

    4. Direct configuration and testing of Reader
      BuilderDirect.rb source code

    5. Single-pass text DSL configuration and testing
      TextSinglePass.rb source code

    6. Two-pass text and XML DSL configuration and testing
      TwoPass.rb source code -- class BuilderExternal source code generated by TwoPass.rb

    7. Ruby internal DSL configuration and testing
      RubyDSL.rb source code

References and Web Resources

General language

  1. Free online programming language textbooks and tutorials

  2. Harold Abelson and Gerald J. Sussman with Julie Sussman. Structure and Interpretation of Computer Programs, Second Edition, MIT Press, 1996. [HTML book]

    SICP video lectures, Hal Abelson

  3. William R. Cook. Anatomy of Programming Languages online draft

  4. Shiram Krishnamurthi. Programming Languages: Application and Interpretation, online book

Lua

  1. Lua language website

  2. Lua users site

    1. Lua Tutorial
  3. Fabio Mascarenhas. Programming in Lua, Slides for Course, Federal University of Rio de Janeiro, Brazil, July 2013. This course was delivered at Nankai University, P. R. China, in July 2013 using Lua 5.2.

  4. Roberto Ierusalimshcy. Programming in Lua, First Edition, Lua.org, Rio de Janiero, Brazil, 2003. This old edition at https://www.lua.org/pil/contents.html covers Lua 5.0.

  5. Luarocks component site

  6. Lua Toolbox

  7. Kepler Project

  8. Tecgraf PUC-Rio Libraries and Tools for Lua

  9. Penlight Lua Libraries inspired by the Python standard libraries

  10. LuaMacro site

  11. Love 2D game framework

Elm

  1. Elm language website

  2. Awesome Elm tutorial list

  3. An Introduction to Elm

  4. Elm Tutorial

Haskell

  1. Haskell language website

    1. Haskell 2010 Language Report

    2. GHC User's Guide

  2. Haskell Cheat Sheet

  3. School of Haskell online tutorials

  4. 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.)

    Video lectures by Peter Drake

  5. H. Conrad Cunningham. Introduction to Functional Programming Using Haskell, Computer and Information Science, University of Mississippi, 2016 (partial draft), available from the prototype CSci 555 course site at http://www.cs.olemiss.edu/~hcc/csci555/prototype/. I begin developing this set of notes in June 2016 based partly on previous materials.

  6. H. Conrad Cunningham. Notes on Functional Programming with Haskell, Computer and Information Science, University of Mississippi, 1994-2014. This older document is being revised and integrated with other materials to produce the document Introduction to Functional Programming Using Haskell.

  7. 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.

  8. 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.

  9. 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.
  10. 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.

Prolog

  1. SWI Prolog website

  2. Patrick Blackburn, Johan Bos, and Kristina Striegnitz. Learn Prolog Now. This a tutoral available online at http://www.learnprolognow.org/. It is also available in print from College Publications, 2006.