ST EK List:
5.3.1A Procedures are reusable programming abstractions.
5.3.1B A function is a named grouping of programming instructions. (???)

Making Your Own Block

Ruthless Suggestions from Al

On this page, you will create a newgossip response block that will make the program feel more like a conversation by using phrases like "I heard," "Who cares!" or "Well, guess what" instead of always "Oh, but."
gossip2 reporting 'Guess what. Gabrielle helped Señora'

  1. If it isn't open already, open your U1L2-Gossip project.
  2. Create the gossip response block. Instructions are below.

Making a New Block

  1. Click make a block button in the Variables palette, or Control-click (or right-click) in an empty spot in the scripting area and choose "make a block..."
  2. make a block option
  3. Choose the color, in this case red for Lists.
  4. Type the title for your block: gossip response.
  5. Select the shape and click OK. For this block, choose the oval reporter shape because you want it to report a value (the chosen response) to another block (the join).
  6. Making a block

Block Building Essentials

In Snap!, every block needs a color category, also known as a palette. Gray ("Other") is the default. It also needs a type (shown by the block's shape), a title, and a script that defines its behavior.

Color Category/Palette; Type/Block Shape; Title; Script

Coding the Block's Script

  1. Drag in the blocks you need. For this block, use the list block and item(1) of ().
  2. Snap the blocks together. The code structure will look similar to who, does what, and who2.
  3. Fill any inputs.
    • For this project, click the down-arrow in item to change "1" to random.
    • Then fill list with phrases.
  4. Click OK when you're satisfied.
  5. Pair Programming Swap
Revisit the sidenote and this text, which is confusing. --MF, 6/26/18
Note: Mathematicians use the word "function" in a slightly different way from computer scientists. Don't worry if you hear something in math class that differs from what you see in BJC.

In many programming languages, what Snap! calls a reporter (blocks with an oval shape like pick random () to ()) is called a function and what Snap! calls a command (blocks with a puzzle shape like point in direction (90)) is called a procedure. But programming languages are not consistent about this. Some use "function" for both, and others use "procedure" for both. (Also, most languages use these words only for procedures or functions that you write, not the ones that are built into the language.)

The AP Exam uses the word procedure for both reporters and commands.

Debugging

  1. Test your custom gossip response block by clicking it several times. It should behave like the who, does what, and who2 blocks.
  2. Debug any problems before moving on.
  3. Review how to edit a block in Unit 1 Lab 2 Page 2: Customizing and Debugging, if needed.
  4. Use your new block. Edit gossip2, and insert gossip response in place of the text "Oh, but...." gossip2{report(join(gossip response)( )(who2)( )(does what)( )(who))}
  5. Test and debug gossip2 also.
  6. Then test the whole program by clicking script D several times, and fix any bugs.
  7. Now Is a Good Time to Save
These purple "Take It Further" boxes have harder activities that are not required for this course. If you finish everything else on the page early, try these instead of jumping ahead to the next page.
Tough Stuff
  1. Edit gossip and gossip2 so that sometimes, not too often, they say something like "John and Paul" using two of the names in the lists of who or who2.
    • You can use code like
      if ((pick random from (1) to (10)) > 7){ }else{ }
      to do something some of the time. Change the 7 to another number to adjust the probability.
    • If your program uses two names at the beginning of the sentence, you'll have to use a plural verb instead of a singular verb. You can have two versions of does what with different lists, or you can try to take a verb reported by does what and use a set of rules ("if the word ends in x change it to zz") to turn it into a plural verb.