Snap!

Implementation of programming language Scratch

Snap! (previously known as BYOB, for Build Your Own Blocks) is an extended reimplementation of Scratch visual programming language. Snap! is presented by the University of California at Berkeley and developed by Jens Mönig at MioSoft Corporation.

The key feature of Snap! is support for user-defined blocks. It also features first class lists, first class procedures, and continuations.

Snap! is written in JavaScript and runs in a browser.

Snap! logo
Snap! logo

Snap! interactive development environment
Snap! interactive development environment

Examples:

Hello, World!:

Example for versions Snap! 4.0

Unlike Scratch, in Snap! each script must start with a “hat” block defining the condition upon which the script runs. “When green flag clicked” hat runs the script upon presentation start.

Hello, World! in Snap!
Hello, World! in Snap!

Factorial:

Example for versions Snap! 4.0

This example shows iterative calculation of factorial. To output results in required multiline format a global list variable is used.

Factorial (iterative) example in Snap!
Factorial (iterative) example in Snap!

Factorial:

Example for versions Snap! 4.0

This example uses recursive method of factorial calculation. Snap! allows to create user-defined blocks, in this case factorial block of type reporter (a block that returns a value, i.e. a function block). The newly defined block appears in the blocks palette immediately, and can be used when editing its own definition, thus allowing recursive calls.

Factorial (recursive) in Snap!
Factorial (recursive) in Snap!

Fibonacci numbers:

Example for versions Snap! 4.0

This example uses recursive calculation of Fibonacci numbers. To speed up calculations, newly found numbers are written to “cache” which is simply a global list.

Fibonacci numbers (recursive) in Snap!
Fibonacci numbers (recursive) in Snap!

Quadratic equation:

Example for versions Snap! 4.0

In Snap! block join conveniently allows to concatenate arbitrary number of arguments.

Quadratic equation in Snap!
Quadratic equation in Snap!

CamelCase:

Example for versions Snap! 4.0

Snap! has a slightly larger list of built-in blocks than Scratch; for example, blocks unicode of _ and unicode _ as letter are built-in. In this example these blocks are used to define blocks isLetter, toLower and toUpper, equivalent to functions of the same name in other languages.

CamelCase in Snap!
CamelCase in Snap!