General Concepts of CindyScript
This section is a brief introduction to the most fundamental concepts of CindyScript.
CindyScript Is a Functional Language
All calculations in CindyScript are performed by executing functions. A function can be considered as a kind of calculation that takes the arguments of the function and produces some kind of output value. Many calculations can already be expressed using only elementary functions. Thus the code fragment
calculates the sum of the first 10 integers. Here
Moreover, seemingly procedural statements, such as an
demonstrates the function
Depending on the evaluation of the condition, the
If a function is evaluated in CindyScript, it may have "side effects." Side effects are important for all kinds of interactions between a CindyScript program and a Cinderella construction. Typical side effects are:
For instance, the statement
produces the side effect of drawing a point at position
sets the color of point A to white.
Most users are probably accustomed to sequential programming languages like C, Java, Pascal, and Basic. In practice, writing sequential code in CindyScript is not so different from writing code in these languages. CindyScript has a
repeat(9,i, j=i*i; draw([i,j]); )
creates nine points on a parabola. The function
No Explicit Typing
CindyScript is designed to provide a maximum of functionality with a minimum of syntactic overhead. Therefore, CindyScript does not have explicit typing of values. Like many other languages, CindyScript uses the concept of variables. However, in contrast to other languages, the variables do not belong to a specific type. Any value of any type can be assigned to any variable. On the one hand, this gives the programmer a great deal of freedom to generate powerful code. For instance, the following code fragment
defines a function
Local Variables: The # Variable
There are several loop-like constructions in CindyScript. For instance, the operator
returns a list of all odd numbers between
prints all numbers from
The Data Types of CindyScript
As already mentioned, CindyScript does not have explicit typing. Nevertheless, any value of a variable belongs to an explicit type. The basic types of CindyScript are
The number type is particularly powerful, since it can contain integers, floating-point numbers, and complex numbers.
Variables and Their Scope
Since CindyScript does not have explicit typing for variables, it allows variables to be created "on the fly" as needed. A variable is created when it is assigned for the first time. If
creates the variable
the values of
Access to Geometric Elements and Their PropertiesVariables are also used as a kind of handle to geometric objects. They form a major link of CindyScript to Cinderella and CindyLab. If a variable has a name that is identical to the label of a geometric object, it provides a link to that geometric object. The value of the variable can still be overloaded by an explicit assignment of a value to the variable. The different properties of a geometric object (position, color, size, etc.) are accessible via the . operator. Thus if
Many operators in CindyScript provide more functionality than one may notice at first glance. Usually these features can be accessed using so-called modifiers. The operators are defined in a way such that their default usage provides a suitable behavior for most situations. However, it may be necessary to modify the default behavior. To that end, one lists corresponding modifiers in the call of the operator. For instance, the statement
draws a point at position
draws a yellow point of size 15. Modifiers have to be separated by commas. They may occur in any order and at any position of the function call.
CindyScript offers lists as elementary data types. Lists are the fundamental paradigm that is used to define more complex data structures. In addition to the obvious application as enumeration objects, lists can also be used to represent vectors and matrices. A vector is a list of numbers. A list of vectors whose vectors all have the same length will be interpreted as a matrix. CindyScript provides the usual operations for combining vectors, matrices, and numbers. Depending on the content of
In CindyScript there is no distinction between row vectors and column vectors on the level of vectors. However, by the use of suitable functions one can convert a vector of length
CindyScript provides many statements with which one can draw directly on the canvas of the geometric views. Using this feature it is possible to enrich the behavior of Cinderella constructions significantly. It is possible to draw points, lines, segments, polygons, tables, functions, etc. However, it is important not to confuse a script-drawn geometric object with a geometric object that is active in geometry. It is not possible to use such script-drawn elements as definers in Cinderella modes.
If one wants to modify active elements using a script, then it is necessary to first construct them and then alter their positions using CindyScript statements. All free elements can be moved by setting their position parameters.
The script window of Cinderella in which one enters the CindyScript code contains several slots in which the text can be entered. The particular slots are called
Each of these entries corresponds to the occasion that triggers the execution of the script. For instance, scripts in the Draw slot is executed directly before a screen refresh in the view. The Initialization slot is executed directly after the CindyScript code is parsed. Simulation Start is executed before starting an animation when the play button is pressed. Using this mechanism it is possible to write programs that react nicely to user events.
Runtime Error handling
CindyScript runs in a runtime environment. In principle, every tiny move in a construction can cause the evaluation of a script. For this to happen, a reasonable design decision in the language had to be made concerning the occurrence of runtime errors. It would be very distractive if the usual user interaction was interrupted by error messages over and over (in particular, if a construction is used as an applet within an HTML page). For this reason, error handling in CindyScript at runtime reports only the first ten errors. However, runtime errors will never interrupt execution. Runtime errors (such as division by zero, or access to a nonexistent array index) are simply ignored in the program flow. Erroneous function evaluations simply produce an undefined result, and the calculation proceeds (perhaps causing more undefined results). This usually guarantees fluent performance of a construction even if errors occur.
This feature may make debugging of programs a little cumbersome, since runtime errors are not reported. For this purpose a special function,
The content on this page is licensed under the terms of the License.