Unit 2: Abstraction

Lab 1: Games

2.1.1: Variable  
AAP-1.A.1

A variable is like a 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.
2.1.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.

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

2.1.2  

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

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
}
2.1.4: Global Variable  

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

2.1.4  

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

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

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

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

2.2.2: Data Types  
2.2.2: Abstract Data Types   The constructor and selector together implement the quiz item abstract data type.
2.2.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.

2.2.3  

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

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

2.3.1: Domain and Range  
2.3.1: Sequencing, Selection, 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).

2.3.3  
AAP-2.I.1

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

2.3.5: String and Index  
2.3.6  

All the words in the puzzle are related to the AP CS Principles course.

Lab 4: Making Computers Do Math

2.4.2  
AAP-3.D.1

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

2.4.2: APIs  
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

2.5.2  
IOC-1.F.5
2.5.2  
IOC-1.F.5

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