In other languages

Help the wiki!

The Scratch Wiki is made by and for Scratchers. Do you want to contribute?

Learn more about joining as an editor!

See discussions in the Community Portal

Build Your Own Blocks (Scratch Modification)

(Redirected from Build Your Own Blocks (BYOB))

Archive.png
The subject of this article or section has changed dramatically and requires updating. Please keep in mind that some of the information or images may not be accurate or relevant to the current version of Scratch, the Scratch website, or the article subject.
Document stub.png This article or section may not have content matching Scratch Wiki editing standards. Please improve it according to Scratch Wiki:Guidelines.
Reason: Many informal abbreviations, unorganized info and unclear descriptions.
Danger.png Scratch and the Scratch Wiki are not responsible for the security of external programs or links in this page or section.
Build Your Own Blocks (BYOB)
BYOB3.png
Version BYOB 3.1.1; Snap 4.0 (developing)
Operating Systems Windows, Macintosh, Linux, Unix
Purpose for creation The ability to build your own blocks; everything first class
Developer(s) Jens, bharvey
Open source? Yes
Programming language Squeak, JavaScript
Released? Yes
Compatible with Scratch 1.3 and 1.4
Official Website http://byob.berkeley.edu/
Archived Forum Topic http://scratchforums.blob8108.net/forums/viewtopic.php?id=34284
The BYOB logo.
Build Your Own Blocks — often referred to by its acronym, BYOB — is a modification of Scratch, made mainly by the users Jens and bharvey. It includes many features that are not available in Scratch without many large modifications to the source code (see Shift-Click-R for details) — these range from building your own blocks to Mesh. The primary focus for this Scratch modification is first-class data.


Features

The other BYOB logo.
BYOB contains many features not available in Scratch (without editing the code). The features are that users can:
  • Build their own blocks via drag & drop
  • Host and join Mesh sessions, share sprites over the mesh
  • The "Elements" feature allows you to edit the underlying Smalltalk code in a Scratch-like environment.
  • Nestable sprites
  • True object oriented sprite hierarchy
  • Compiler (makes a project into an .exe/.app (application) file).
  • Scrolling enhancements
  • Undo (Scratch 1.4 only contains "Undelete", which some 1.3 fans find useless)
  • Pause / resume the project
  • Debugger
  • Multi-dimensional lists (lists in lists, or arrays)
  • First class procedures (lambda) and full closures
  • Cloning
  • Atomicity control
  • Type checking
  • A tools sprite with many common procedures

BYOB 3.0 Features

There are 18 new blocks in BYOB 3.0. They are as follows:

Control

[run ()]
Runs the block(s) inserted. When the ► is clicked, the block becomes [run () [with inputs/with input list] ◄►]. With inputs allows users to specify the inputs of a block; With input list sets the inputs to a list.
[launch ()]
Similar to RUN, this runs the script simultaneously with the next. The same thing happens when the ► is pressed.
(call ())
Allows a user to call a variable that is a reporter. Also has the same menu.
[report ()]
For use in custom reporter/boolean blocks, it specifies what to report.
[stop block]
Stops a custom block without reporting anything.
[debug]
(debug ())
An experimental debugger that allows true single-stepping of scripts and examination of local variables. Doesn't do anything in Presentation Mode. More information is available here.

Operators

<true>
Simply reports true.
<false>
Simply reports false.
(ascii code of ())
Reports the ASCII code of a single character. If there are more than one character, it reports Error!
(ascii () as letter)
Reports the character equivalent to an ASCII code.
<is () a |dropdown|?>
With choices of number, text, boolean, list, command, reporter, predicate, object; it reports true if the insert is of the selected type, and false if it is not.
[the script►]
This is a C Block, but a reporter, not a command like most C-shaped blocks. It reports the block(s) inserted. If there is nothing, it reports itself, the script. When the ► is pressed it becomes [the script. Input names:(#1)◄►] #1 is a variable, and more can be created by pressing the arrows. They can be renamed by clicking, and deleted by right-clicking and choosing "delete." They can be used in the script inside the C-shaped slot, and are assigned values when the reported script is run using the run or launch block.
(the () block►)
Reports the reporter or predicate block inserted. It starts out as a reporter, but turns predicate-shaped when one is inserted. If nothing is put in, it also reports itself: the block. If the script is put in, it says [report [the script]]. It works very similarly to the script, and the same things happen when the ► is pressed. This block is equivalent to the Lisp lambda function.

Variables

[script variables ()►]
Even though it is a variables block, it is gray. It creates variables that can only be used in that script. They appear in the dropdown menu for the other variable blocks. However, the show variable and hide variable blocks do not work with these.

Lists

(list ()◄►)
Reports a list without having to create a new named list. Because of this, the other list blocks accept dropped reporters.
(() as text)
BYOB does not normally report a list as text, rather as a list as it is shown on the Stage. This block makes it text and works the same way as the Scratch block ().
(copy of ())
If a variable is set to a list, it will update with the list. Here is how to avoid that.

BYOB 3.1 Features

The main new feature in BYOB 3.1 is the promotion of sprites to first class status, along with the ability to create a true object hierarchy by cloning sprites; child sprites inherit some properties from their parent sprite.

There are four new blocks, along with changes to three other blocks.

The BYOB 3.1 manual is here.

Sensing

(object |dropdown|)
Reports a sprite, a list of all sprites, or the stage.
(attribute |dropdown|)
Reports any attribute of the sprite that calls it, e.g., (attribute draggable?) reports true if the padlock next to the sprite's name is unlocked, or false if locked. Inside a the block block, this block represents the attribute itself as a first class entity that can be given to the of, set, or delete blocks.

Also, the of block has an expanded range of inputs; any sprite property can be dropped onto the left pulldown, and any sprite onto the right pulldown.

Operators

(clone)
Reports a clone of the sprite that calls it. A clone is not merely a copy; it shares some properties (the user can control exactly what is shared) with the original, so that a change to the parent is reflected in the child.

Also, the (is () a ()?) block has a new type, object, in the pulldown menu of types.

Variables

[delete ()]
Deletes the object, attribute, or variable given as input. Objects can be used directly; attributes and variables are enclosed in a the block block (or dropped with a grey border, since the input slot is of type Reporter). This replaces the "Delete a variable" button.

Also, the set block now allows an attribute to be dropped onto the pulldown list of variables.

Snap! 4.0 Features

The Snap! logo.
Snap! screenshot
The newest version, Snap! 4.0, has essentially the features of BYOB 3.0, plus the following:

Control blocks

[warp]
is a C-shaped block that runs the script inside it without yielding to other threads or allowing redisplay, apart from breaks once every few seconds mainly to allow sensing the stop sign being clicked and held. Like turbo mode, except that the latter merely prevents redisplay, with all script threads still running in parallel.
[create a clone of]
[delete this clone]
[when I start as a clone]
implement a temporary sprite cloning feature like that of Scratch 2.0.
[run (script) w/continuation]
(call (script) w/continuation)
implement first class continuations, making Snap! almost a full-featured dialect of Scheme. (The big missing capability, macros, will be in a later version.) The continuation of a block in a script is the part of the computation that remains to be done when that block has been run. For a command block, this generally means the blocks below it in the script. For a reporter, it means the block to which this block provides an input, plus whatever comes below it.

The script input to Run/Call w/continuation must take one input; it will be called with this block's continuation as input. For more details see the Snap! Reference Manual.

Sensing blocks

(http:// (URL))
takes a URL as input and reports the entire text (including HTML tags) of the given web page, provided that the page allows cross-origin references.
<turbo mode?>
reports true if turbo mode is set, or false otherwise.
[set turbo mode to (Boolean)]
turns turbo mode on or off without restarting the project. This is useful if you have a project that is a game, but you need to debug only some parts of it.

Operators blocks

The three grey rings at the top of the Operators palette are the Snap! replacement for "the block" and "the script" in BYOB3. Aside from brevity, the new version behaves somewhat differently when a block input is declared to be a procedure type: Dragging a ringed block into a ringed input slot results in only one ring, not two, surrounding the original block. Dragging a variable into a ringed input slot makes the ring disappear, so that the value of the variable, not the variable block itself, is used as the input. Context menu items "ringify" and "unringify" can be used in the exceptional cases (such as calling a reporter that returns a reporter, and then calling that returned value) in which the default behavior does not do what's needed. This design replaces the BYOB3 distance-sensitive behavior when dropping a block onto a block-type input slot.

(Unicode of (character))
(Unicode (number) as letter)
replace the BYOB3 blocks ASCII of () and ASCII () as letter.
<Is (value) identical to (value)?>
reports true if and only if its two inputs are identical, i.e., the same location in the computer's memory. This block is useful mainly in comparing two lists, which might have equal values (i.e., all items equal) while still being separately constructed lists. If this block reports true, then changing the items of one input will also change the other input, because they are actually the same list.

Variables blocks

Snap! allows Lisp-style linked lists as well as Scratch-style dynamic arrays.

((value) in front of (list))
creates a linked list whose first item is the first input, and whose remaining items are the items of the second input. This block is equivalent to cons in Lisp.
(all but first of (list))
reports all but the first item of a linked list, without copying anything, in constant time. It is equivalent to CDR in Lisp.
(item (1) of (list))
reports the first item of any list, linked or array, in constant time.

For any particular list, computation will be fast if only the traditional Scratch-style commands are used to change its contents. Computation will also be fast if only the new reporters described here are used on a given list. If both sets of blocks are used, then the list will be converted back and forth between linked and array forms internally, and computation will be slower. Linked lists are particularly useful in writing recursive reporter blocks, whereas dynamic arrays are more useful in sequential (command-based) programming style.

Other features

Snap! 4.0, like Scratch 2.0, runs in a browser window rather than requiring the program to be downloaded to the user's computer. As in Scratch, Snap! users can create accounts on the Snap! server and save their projects in their account as well as on their local computer. Saving on the server allows the project to be written on one computer and used on another easily. In the initial beta release, projects are stored for private use; sharing between users will come later.

Unlike Scratch 2.0, which is implemented using Flash, Snap! uses Javascript and can therefore run on Apple iOS devices. However, Javascript imposes restrictions on web sites for security reasons. This has the advantage that users can confidently run other users' projects, which can not do anything harmful even if there is a bug in Snap!. However, some things do not yet work in Javascript, most notably timbre control for playing musical notes. Local saving and loading of projects is slightly more complicated.

As of the beta release (spring 2013), there is no paint editor for costumes, which must be created in other software and then imported to the project. Both bitmap and vector graphics formats are supported. A paint editor will be added in a later release.

History

Jens's first modification was "Chirp," a program that had improvements to Scratch. He then began to work on BYOB (a much bigger project), which has three versions: 1.0 (based on Scratch 1.3), 2.0 (based on Scratch 1.4), and version 3.1.1, which can be downloaded here.

In 2009, the University of California at Berkeley decided to create a new computer science course for non-majors and wanted to use Scratch as the programming language, but also wanted to teach recursion and higher order functions. This is how bharvey, one of the developers of the new course, joined the BYOB project, working with Jens to design the user interface for first class lists and first class procedures.

The 4.0 version, renamed Snap!, is a complete reimplementation based on Javascript, currently in beta release here.

Use in Scratch 2.0

Main article: Procedures#Custom Blocks in Scratch

The Scratch Team has incorporated a function based on BYOB into Scratch 2.0. Custom blocks are procedures (also known as functions or methods) in which a script can easily be modified or run without duplicating it entirely. An example of Scratch's is as below:

define jump
repeat (10)
change y by (6)
end
repeat (10)
change y by (-6)
end

jump

Intellectual Precursors

Custom Blocks

The ability to write and invoke procedures, which is the core idea of BYOB, has been part of almost every programming language (with hardware support in every processor design at least to the extent of an instruction to save the return address somewhere before jumping to the procedure) in the history of computing. (In the original Fortran, the first general-purpose high level programming language, procedures were not reentrant, like Scratch scripts, which break off in the middle if the event that started the script happens again.)

Mapwithexample.png

Glide BYOB.png

Among languages intended primarily for children, by the way, there were heated debates between BASIC and Logo advocates because the latter included support for recursive procedures and the former did not, limiting itself instead to something pretty similar to the Scratch Broadcast () and Wait block. There's an irony in this, since the Scratch Team is a descendant of the old MIT Logo Lab. Seymour Papert, one of Logo's inventors and the founder of the MIT Logo Lab, argued for recursion as one of the mathematical big ideas that children should learn from programming computers.

First Class Data

The phrase "first class data" was coined by computer scientist Christopher Strachey, who argued in the 1960s that any data type that exists in a language at all should be first class. This means that data of that type

  • can be the value of a variable.
  • can be an input to a procedure (Scratch: block).
  • can be reported by a procedure.
  • can be a member of an aggregate (Scratch: list).
  • can exist without having a name.

It's easy to see why one might want lists of lists; every data structure (trees, heaps, hash tables, etc.) can be constructed out of lists, but not straightforwardly with only lists of text strings. But why should procedures be first class? This was historically a counterintuitive idea, especially because a procedure can not be recursive unless it has a name by which to call itself.

The idea of first class procedures comes ultimately from the 1936 invention by mathematician Alonzo Church of lambda calculus, which is a formal study of the behavior of functions. In 1936 there were only a handful of experimental computers, and no symbolic programming languages, so the fact that lambda calculus turned out to be of practical use (it is the basis for much of the theory of programming languages today) was a great confirmation of the power of the idea.

Church demonstrated that the ability to create and call functions is universal — it is all you need to perform any computation that can be done at all. (He also proved that there are undecidable problems, which is the reason for the qualifying clause above.) In BYOB terms, this means you could have a programming language with nothing but THE BLOCK and CALL, and still be able to compute any function. (See this BYOB project description for an explanation of how to invent arithmetic from that starting point.) The Greek letter lambda (λ) is Church's name for THE BLOCK.

Compose.png

(Of course lambda does not solve the problem of input/output: capturing mouse clicks, drawing pictures on the screen, and so on. Although obviously of crucial practical importance, such input/output activities are not central to the understanding of what a program or a programming language is.)

Church's work influenced actual programming language design by way of John McCarthy's 1958 invention of the Lisp programming language for artificial intelligence research. Lisp is a direct influence on Logo, and therefore an indirect influence on Scratch. The detailed design of first class procedures in BYOB was strongly influenced by Scheme, a Lisp dialect invented in the late 1970s by Gerald Jay Sussman and Guy Steele, which brought Lisp closer to its roots in lambda calculus by introducing lexical scoping rules.

Prototyping

The clone block reports a new object that inherits properties of the parent object. This allows users to create an object hierarchy, as in other OOP languages such as Smalltalk. But unlike Smalltalk, BYOB does not distinguish between classes and instances; every object can be viewed as an instance of its parent or as the class of its children. This form of inheritance is called "prototyping" because the user builds an example of a category of sprite rather than building the category as an abstract description. The best known prototyping languages are JavaScript and Self. The particular form of prototyping used in BYOB was inspired by the work of Henry Lieberman.

Future Versions

The developers, Jens and bharvey, are working on the next version — Snap! 4.0.

Snap! 4.0 is written in JavaScript, using the HTML5 canvas element. It uses a Morphic library by Jens called Morphic.js.

The current Snap! 4.0 experimental version can be found here to try out. At this point it has most of the BYOB 3.0 capabilities, but not yet the OOP features added in 3.1. (They'll be in Snap! 4.1.) Some of the new Scratch 2.0 features, including sprite cloning, are also in Snap! 4.0. A new feature (compared with BYOB) is cloud storage of projects. The ability to share projects with other users is coming later.

Snap! 4.0 is currently in beta stage. The current target for the official release is summer 2013. The BYOB-based Beauty and Joy of Computing curriculum will be converted to Snap! for fall 2013.

The name was changed from "BYOB" to "Snap!",[1] because of the other meaning of the acronym BYOB. Some people think a warning is OK,[2] but the Berkeley personnel experienced some resistance to the old name from potential users, and the developers did not feel the name was worth fighting about.

Scratch Mod Design Aesthetics

It is traditional to measure the power of a Scratch modification in part by the number of blocks it adds to the language. BYOB has taken the opposite approach, trying to get a lot of expressive power out of a very small number of new blocks.

One reason for this is that an explicit goal of BYOB is to influence the design of Scratch 2.0, and it is hoped that the Scratch Team may be more amenable to changes with a "small footprint" — ones that will not intrude dramatically on the experience of the traditional Scratch programmer.

Alpha/Beta Testers

The certificate.
Bharvey put a "Certificate of Appreciation" on the BYOB website, consisting of 16 people who helped test BYOB3.

External Links

See Also

References

  1. http://scratchforums.blob8108.net/forums/viewtopic.php?id=34284&p=124#p719634
  2. http://scratchforums.blob8108.net/forums/viewtopic.php?id=34284&p=124#p719904
  • This page was last modified on 15 September 2014, at 04:30.