# Vitruvia

 Vitruvia is a web app that provides an introduction to a number of concepts used in Bricklayer.

 Basics Concept 1: Cell Locations This set of Vitruvia exercises develops an understanding of cell coordinates in the xz-plane. LDD permits the creation of three dimensional structures in which the xz-plane corresponds to a (virtual) LEGO board. Concept 2: Boolean Functions This set of Vitruvia exercises develop a basic understanding of Boolean functions whose inputs are cell coordinates. Concept 3: Basic Bricks This set of exercises develops an understanding of the specification and placement of basic LEGO bricks. A basic brick is defined by its shape (e.g., 2x4) and its color (e.g., RED). Basic bricks (all bricks for that matter) can be understood in terms of a composition of 1x1 bricks. For example, a 4x2 brick is the composition of eight 1x1 bricks having the proper configuration. By convention, Bricklayer assumes the position of a brick is defined by the cell coordinate of its lower left corner. In this context, an (informal) instruction is an English sentence specifying a brick dimension, type, and location. An example of an informal instruction is: Put a 1x1 RED brick at location (0,0). The Vitruvia exercises in Concept 3 establish a vocabulary for referencing basic LEGO bricks. Concept 4: Brick Sequences This set of Vitruvia exercises develops an understanding of the sequences of (informal) brick-placement instructions. Concept 4 is a direct extension of Concept 3 and focuses on the notion of instruction sequences . Level 1 Coding Concept 5: Bricklayer functions The set of Vitruvia exercises transitions from informal brick-placement instructions to corresponding Bricklayer/SML function calls. An example of an actual SML function call is: put2D_4x2_RED(0,0) which, when executed by Bricklayer, will "put" the lower left corner of a 4x2 red LEGO brick at coordinate (0,0). When programming in Bricklayer in Level_1 and Level_2, only a fixed set of put2D_* functions are made available. Specifically, the put2D_* functions available are precisely those corresponding to those referenced in Vitruvia exercises. Corresponding Bricklayer studies can be found here. Concept 6: Function Call Sequences The set of Vitruvia exercises takes a formal look at the evaluation (aka execution) of a sequence of SML functions. At this point, an exercise solution represents the effects of evaluating a sequence of Bricklayer function calls. Concept 7: Overwriting In a virtual space, the notion of overwriting is significant. What happens when the placement of one LEGO overlaps the placement of another? This set of Vitruvia exercises explores the effects of overwriting in Bricklayer. More specifically, overwritting is permitted and can be used to advantage when building LEGO objects. Concept 8: Program Creation This set of Vitruvia exercises calls for the creation of Bricklayer programs. Basic Bricklayer programs consist of sequences of put2D_* function calls. The skill that is developed here is attention to detail - are semi-colons in the right places, are function calls syntactically well-formed? Supplemential Bricklayer assignments can be found here. Concept 9: Debugging As soon as the very first program is created, one is confronted with the problem of figuring out "why the didn't work" or "why the program produced a result different than intended". This set of exercises develops basic skills in debugging Bricklayer programs. More specifically, two LDD structures are shown - the first incorrect, the second correct. The focus of this set of Vitruvia exercises is to manually place bricks in order to transform the first solution into the second solution. Supplemential Vitruvia content and Bricklayer assignments can be found here. Level 2 Coding Concept 10: Nullary Function Declarations For lengthy put2D_* function call sequences, comprehension becomes a problem. Nullary function declarations (i.e., functions taking essentially no arguments) can be used to structure and abstract function call sequences. Such structuring of Bricklayer programs makes them easier to understand, to debug, and to modify. This set of Vitruvia exercises develops basic skills in understanding the semantics of (user-defined) nullary function declarations and corresponding function calls. Corresponding Bricklayer studies can be found here. Concept 11: Offsets Offsets provide a Bricklayer mechanism for shifting the origin of the xz-plane. Through offsets it becomes possible to reuse a (single) sequence of put2D_* function calls in order to build copies of LEGO objects positioned at various points in the xz-plane. Offsets share similarities to pointers and are (understandably) quite complex. This set of Vitruvia exercises develops basic skills in understanding offsets. Corresponding Bricklayer studies can be found here. Concept 12: Function Parameters In Bricklayer, function parameters can be used to play a role similar to offsets. However, function parameters are essentially stateless and are therefore (ultimately) much easier to understand and reason about than offsets. This distinction between offsets and parameters illustrates a fundamental difference between imperative and functional programming paradigms. Through parameterized functions, it becomes possible for users to extend the set of put2D_* functions thereby creating speciality composite pieces (e.g., L-shaped bricks and nxm bricks) having fixed colors. This set of Vitruvia exercises develops basic skills in understanding the declaration and use of parameterized functions. Corresponding Bricklayer studies can be found here. Concept 13: Circles and Rings In Bricklayer, the fundamental brick has dimensions 1x1x1. However, Bricklayer also provides functions that construct (and "put") composite structures such as circles and rings. This set of Vitruvia exercises demonstrates how composite structures are created. Corresponding Bricklayer studies can be found here. Level 3 Coding Concept 14: The Curried Function: put2D This set of Vitruvia exercises demonstrates the syntax and semantics of the Bricklayer function put2D. The curried function put2D is parameterized on (1) brick dimension (e.g., nxm), (2) brick type (i.e., color and shape), and (3) coordinate. It is through the parameterization of brick type that put2D provides the ability to "put" any of the supported bricks (over 70) in the xz-plane. Corresponding Bricklayer studies can be found here. Concept 15: Lines In Bricklayer, a 1x1x1 brick can be thought of as a large pixel that also has a physical manifestation. When using such "pixels" to draw lines, the jagged nature of lines becomes quite apparent. The algorithms used by "smooth" line drawing functions, while not overly complex, are never-the-less computationally intricate. This set of Vitruvia exercises demonstrates the syntax and of the Bricklayer function lineXZ. The exercises also give some appreciation of the semantic issues that must be confronted when drawing "smooth" lines. Corresponding Bricklayer studies can be found here. Concept 16: Clipping The purpose of evaluating a Bricklayer program is to build a LEGO structure in a virtual space, and to then display that structure in LDD. We refer to this virtual space as the "cube". The dimensions of the cube used by a Bricklayer program must be explicitly declared within the program. The xz-plane is a cube whose height (y dimension) equals 1. During execution, Bricklayer provides a safe interaction with the program's cube. Specifically it will not permit an interaction with the cube that attempts to place a brick at in cell coordinate lying outside of the cube. An interesting question concerns itself with function calls that attempt to put a composite structure (e.g., a 4x2 brick) at a location where only part of the structure lies within the cube. In such situations, Bricklayer updates the cube with the portion of the structure that lies within the cube's dimensions. This behavior is called clipping. This set of Vitruvia exercises develops an understanding of Bricklayer's clipping algorithm. Supplemential Bricklayer assignments can be found here. Concept 17: My Space Bricklayer provides the capability of controlling which cells within a cube can be updated by a function or program. This capability can be used to partition a cube into a set of sub-cubes. Multiple people interact with a cube by executing code in their own assigned sub-cube. This allows for safe compositions of user code and provides an environment for interesting group coding projects. This set of Vitruvia exercises develops an understanding of the syntax and semantics of functions that partion a cube. Supplemential Bricklayer assignments can be found here. Concept 18: Let-blocks The compositional possibilities arising from my space functions give rise to name space issues. For example, if two programs are composed there may exist a user-defined function that is declared (albiet differently) in both programs having the same name. There are a number of manual polices that can be followed to mitigate this issue. However, a better way to resolve this problem is to declare functions in ways that suitably restrict their visibility/scope. In SML, let-blocks provide one way to restrict the visibility of user-defined functions. This set of Vitruvia exercises develops an understanding of the syntax and semantics of let-blocks. Supplemential Bricklayer assignments can be found here. Level 4 Coding Concept 19: Transition to 3D Up to this point, all the exercises involved the creation of LEGO structures in the xz-plane. We now transition to three dimensions. This set of Vitruvia exercises develops an understanding of the syntax and semantics of the 3D Bricklayer function: put. Corresponding Bricklayer studies can be found here.