OPLMantras

Home Assignments Martin Blog Sherman Blog Resources Project Discussion Group

Inspired by J. Canning's poems/mantras for teaching ideas in 91.101 Computing I; e.g.:

What is a string?
“A string is a pointer to a character
followed by a series of characters
ending in a null byte.”

I propose the following mantras for OPL.


Define

What does define do?
“Define creates a binding
from a symbol to an object
in an environment.”


Evaluation

What are the normal Scheme evaluation rules?
“Evaluate each thing in the expression.
then apply the first thing to the rest of the things.”

(The first thing had better be a procedure.)


Closure

What is a closure?
“A closure is a first-class function
with free variables that are bound
in the lexical environment.”

With thanks to Wikipedia.


Environments and Frames

What is a frame?
“A frame is a place where bindings are made from symbols to objects.”
What does define do?
“Define creates a binding
from a symbol to an object
in a frame.”
What is an environment?
“An environment is a series of frames.”


Procedure Application

How do I apply a procedure?
“To apply a procedure,
create a new frame and in it bind the parameters' symbols to their associated values,
link that frame back to the frame from which the procedure was created,
and evaluate the body of the procedure from this new frame.”


Let and Lambda

What is let?
let is syntactic sugar for lambda,
which creates a new frame with bindings for the symbols created in the header of the let,
and evaluates by body of the let in the context of this new frame.”
(let (( <var> <exp> )) <body> )
is equivalent to
((lambda ( <var> ) <body> ) <exp> )

Procedural Abstraction

Procedural abstraction uses a set of procedures that operate on a corresponding set of data structures to implement specific functionality.
The procedures provide constructors for creating the data structures and selectors (also known as accessors) for retrieving their values.
Only use the constructors and selectors for interacting with the represented objects. The underlying representation/implementation may change, but the interface provided by the constructors and selectors will not.
Do not violate the abstraction barrier.