Introduction



SNAP, which used to be called BYOB, is a visual, drag-and-drop programming language. It is an extended reimplementation of Scratch. In this version you can Build Your Own Blocks. It also features first class lists, first class procedures, and continuations.

SNAP! runs in your browser. It is implemented using Javascript, which is designed to limit the ability of browser-based software to affect your computer, so it's safe to run even other people's projects, even if you don't trust their competence or good intentions. It also means that you can run SNAP on an iPad.

SNAP! is presented by the University of California at Berkeley. It was developed by Jens Mönig at MioSoft Corporation, with design input and documentation by Brian Harvey at Berkeley, and contributions by students at Berkeley and elsewhere.

You can either run SNAP from your browser or download BYOB

By constructing your own blocks, you can learn about programming concepts, such as
  • defining procedures and functions
  • passing parameters
  • procedure/function specific variables
  • recursion
  • "atomicity"


Types of Blocks

  • command
    Not a function, but rather a do something block
  • reporter (function)
    this function can return an type of output.
  • predicate (function)
    this function returns a boolean




  1. Make a simple command block

    1. Open SNAP


    2. Create an account


    3. Check your email, enter the password


    4. Change your password to something more memorable:



    5. Navigate to the Variables palette.


    6. In the bottom of the palette you will find a Make a block block. Click on it.



    7. The make a block dialog box will open. Now, you get to choose which tab the block should go into. Because your block will be building a square, choose Motion.



    8. When you selected Motion, the command block became blue. You now have the option of making blocks of different shapes. Right now, however, you are just going to make a (regular) command block.Name the block



    9. When you click OK, you should see the block editor below:



    10. Use the blocks from the regular menus to create a script that draws a square:



    11. Test it out.



    12. Go back and edit the block. Right-click on the new block and select edit to go back to the block editor.
    13. In the Block Editor, notice the plus signs (+). When you click on these plus signs, you can add more text or arguments. When you click on the text between the plus signs, you can delete or modify that text. Click on the plus sign at the far right as shown below:



    14. Drag the variable size down into the move block. Whenever we need a new copy of a variable, we just grab the copy from that variable in the top row.



    15. Press OK and test by adding a value:



    16. If everything is working, add a clear block, CTRL+click on the custom block and edit it so that now you are drawing a polygon of sides with size



    17. Save your file in the cloud


  2. Make a reporter block

    Your reporter block will take two integers and return the max of the two inputs:
    1. Click Make a block



    2. Select the Operators tab. You want a reporter block, so click on that option as well. As the name implies, reporter blocks can report a value.



    3. Name the function. Use the % shortcut for making input variables



    4. Press OK. You should see this:



    5. To keep track of the value to be reported, you are going to make another variable.

      Use a Script Variables block. You can click on the name of the variable (a) and change it to bigger value.



    6. Use an if/else block to set the variable bigger value to either x or y.
      Drag a set block into the Block Editor from the regular variables menu. You can click on the down arrow on the set block to select bigger value. Then, drag the bigger value variable into the box next to report:



    7. Press OK. Drag out to test:



    8. Click to test:



    9. Try adding strings to the max function. What happens?
      Maybe this is true or maybe it isn't. I don't think Clark would agree



    10. CTRL+click on the block to edit it:



    11. Click on the x, then click on the right arrow



    12. Select Number



    13. Set a default value:



    14. Click OK and repeat for y


    15. Drag a new block out to test


  3. Create a min function




  4. Go back to the draw block and make sure that it only accepts numbers




  5. Create a new block using the max block that finds the largest of three numbers. This is called Composition. hint:Use two max blocks in the report block.




  6. Make a three-argument addition operator that only accepts numbers:




  7. Make three-argument join operator that has the default values hacking, is, awesome!, and only accepts text:





  8. Make a predicate block

    This block reports either true or false. You have a "greater than" operator (>), an "equal" operator (=), and a "less than" operator (<), but now you get to create a new "greater than or equal to" (>=) operator.
    1. Click Make a block



    2. Select the Operators tab. You want a predicate block, so click on that option as well:



    3. Name the block



    4. Press OK



    5. Make sure the inputs are numbers


    6. Build:



    7. Click OK and test the block.


  9. Create a new predicate block that determines if a number is between two other numbers. The block should return true if the first number is between the two numbers or if it is equal to either of the numbers: