The Kaleidoscope programming language is a
constraint programming
Constraint programming (CP) is a paradigm for solving combinatorial problems that draws on a wide range of techniques from artificial intelligence, computer science, and operations research. In constraint programming, users declaratively state th ...
language embedding
constraints into an
imperative object-oriented
Object-oriented programming (OOP) is a programming paradigm based on the concept of " objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of ...
language. It adds keywords ''always'', ''once'', and ''assert''..''during'' (formerly ''while''..''assert'') to make statements about relational invariants. Objects have constraint constructors, which are not methods, to enforce the meanings of user-defined datatypes.
There are three versions of Kaleidoscope which show an evolution from declarative to an increasingly imperative style. Differences between them are as follows.
[http://www.cs.washington.edu/research/constraints/cip/kaleidoscope-asi.pdf ]
Example
Compare the two code segments, both of which allow a user to drag the level of mercury in a simple graphical thermometer with the mouse.
Without constraints:
while mouse.button = down do
old <- mercury.top;
mercury.top <- mouse.location.y;
temperature <- mercury.height / scale;
display_number( temperature );
if old < mercury.top then
delta_grey( old, mercury.top );
elseif old > mercury.top then
delta_white( mercury.top, old );
end if;
end while;
With constraints:
always: temperature = mercury.height / scale;
always: white rectangle( thermometer );
always: grey rectangle( mercury );
always: display number( temperature );
while mouse.button = down do
mercury.top = mouse.location.y;
end while;
References
*
*
Procedural programming languages
Constraint programming
Constraint programming languages
{{compu-lang-stub