Unit 2: Abstraction

Lab 1: Games

Lab 1, Page 1: Variable
AAP-1.A.1

A variable is like a labeled box that can hold one value at a time, such as one word, one costume, or one list (which can contain many things). You can look at what's inside as many times as you want.

On Unit 1 Lab 2 Page 2: Making Programs Talk, you learned about procedural abstraction: giving scripts names by putting them in new blocks. Here, we are starting to look at data abstraction, giving names to numbers, text, lists, etc. When you give something a name, you can refer to it without knowing exactly what the value is.
Lab 1, Page 1: Local Variable

A local variable can be set or used only in the environment in which it is defined. This term includes inputs to procedures and variables created by the for or script variables block.

Lab 1, Page 2: Predicate and Boolean value
Read More Why is Boolean capitalized?

The word Boolean is capitalized because it's named after a person, George Boole, who invented the branch of mathematics dealing with Boolean operations (such as and, or, and not).

A predicate is a hexagon-shaped reporter that asks a true/false question such as these examples:
8 > 7 reporting true 6 > 7 reporting false

AAP-2.E.1

Predicates report a Boolean value (either true or false).

Lab 1, Page 2: Conditions and Conditionals

The if and if-else blocks are called conditionals because they control the code based on a true-or-false condition.

redo pic in yellowbox with plain prototype labels --MF, 2/6/25
Click for examples of predicates being used inside conditionals.
more complicated who {
    if (pick random (1) to (4)) = (3) {
        report (join (who) (', who') (does what) ( ) (who) (,))
    } else {
        report (who)
    }
} when green flag clicked:
repeat until (touching (Leader)?)
{
    point towards (Leader)
    move (1) steps
}
Lab 1, Page 4: Global Variable

A global variable is a variable that is usable by all scripts in the program.

Lab 1, Page 4: Initialization

Setting the starting value of a variable is known as initializing the variable.

Lab 1, Page 5: Index

The position number is called the index of the item in the list.
item (2) of (list (apple) (cantaloupe) (banana)) reporting 'cantaloupe'
In this list, 1 is the index of the item "apple," 2 is the index of the item "cantaloupe," and so on.

AAP-1.D.8

In Snap! and on the AP exam, the index is always a whole number (1, 2, 3, 4, etc.). It is an error to use an index less than 1 or greater than the length of the list.

Lab 2: Making Lists

Lab 2, Page 1: Element
AAP-1.C.2

An element is another name for an item in a list. (If the same value is in the list twice, that counts as two different elements.) Each element has a unique index (position) in the list.

Lab 2, Page 2: Sublist

A sublist is a list used as an item of another list.

(The word sublist is also used to refer to some subset of a list.)

Lab 2, Page 2: Data Type
Lab 2, Page 2: Abstract Data Type (ADT) and Data Abstraction The constructor and selector together implement the quiz item abstract data type.
Lab 2, Page 2: Table

A table is a two-dimensional data structure with rows and columns. If you've used a spreadsheet program, what it displays is a table.

In Snap!, a table is implemented as a list of lists, in which each sublist is one row of the table.

Lab 2, Page 3: Function Composition

Using the result from item as the input to address from contact is called composition of functions.

Lab 2, Page 3: Traversing a List
AAP-2.O.2

Traversing a list means looking at each item of the list. For each is iterative. That is, it's repetitive, like for, which can also traverse a list. But unlike for, for each traverses the list without using index numbers.

Lab 3: Making Decisions

Lab 3, Page 1: Input Type, Output Type, Domain, and Range
Lab 3, Page 1: Sequencing, Selection, and Iteration
Selection: AAP-2.G.1; sequencing, selection, iteration: AAP-2.A.4

Selection means deciding (selecting) which part of an algorithm to run based on whether a condition is true or false.

Every algorithm can be constructed using sequencing (following steps in order), selection (deciding), and iteration (repeating).

Lab 3, Page 3: Nested Conditional
AAP-2.I.1

A nested conditional statement is an if or if else statement inside another if else statement.

Lab 3, Page 5: String and Index

Lab 4: Making Computers Do Math

Lab 4, Page 2: Software Library
AAP-3.D.1

A software library is a collection of procedures that can be used in programs.

Lab 4, Page 2: Application Program Interface (API)
AAP-3.D.4, AAP-3.D.5

An application program interface (API) documents what a programmer needs to know about using a library: it's a description of each procedure's purpose, inputs, and outputs (but not its algorithms).

What is a Web API?

A common kind of API is a web API in which the library exists on someone else's computer. For example, the Google Maps API describes how to embed a Google Map on your own website.

I'm actually inclined to cut all the rest of this yellow box. --MF, 1/15/20

A web API is just a call to a procedure on another machine. For example, these are three different notations for the same procedure call, which looks up the number of searches for "BJC" in the US:

The only difference is that the URL shows where on the Internet to find the procedure.

Lab 5: Copyrights

Lab 5, Page 2: Creative Commons
IOC-1.F.5
Lab 5, Page 2: Free Software, Open Source, and Open Access
IOC-1.F.5

Ideas similar to Creative Commons are used for particular kinds of material: