Build Your Own Blocks (Scratch Modification)
(Redirected from Build Your Own Blocks (BYOB))
| 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. |
| 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.
|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)|
|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|
|Compatible with||Scratch 1.3 and 1.4|
|Archived Forum Topic||http://scratchforums.blob8108.net/forums/viewtopic.php?id=34284|
- 1 Features
- 2 History
- 3 Use in Scratch 2.0
- 4 Intellectual Precursors
- 5 Future Versions
- 6 Scratch Mod Design Aesthetics
- 7 Alpha/Beta Testers
- 8 External Links
- 9 See Also
- 10 References
- 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
- Multi-dimensional lists (lists in lists, or arrays)
- First class procedures (lambda) and full closures
- 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:
- [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 ())
- 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.
- Simply reports true.
- 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.
- [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.
- (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.
- (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.
- 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.
- [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
- 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.
- (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.
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.
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.
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.
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.
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.
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
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.)
Among languages intended primarily for children, 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.
(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.
The developers, Jens and bharvey, are working on the next version — Snap! 4.0.
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!", because of the other meaning of the acronym BYOB. Some people think a warning is OK, 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.
- BYOB Forum Topic
- BYOB 3 Forum Topic
- BYOB (original) Guide (now partially obsolete)
- BYOB 3.0 Reference Manual
- BYOB 3.1 Reference Manual
- BYOB 2.0 Download Link.
- BYOB Website