# Kaleidoscope (programming language)

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Kaleidoscope_(programming_language)
> Markdown URL: https://mediated.wiki/source/Kaleidoscope_(programming_language).md
> Source: https://en.wikipedia.org/wiki/Kaleidoscope_(programming_language)
> Source revision: 1303148661
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

Programming language

The **Kaleidoscope programming language** is a [constraint programming](/source/Constraint_programming) language embedding [constraints](/source/Constraint_satisfaction_problem) into an [imperative](/source/Imperative_programming) [object-oriented](/source/Object-oriented_programming) 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.[1]

Kaleidoscope'90 Kaleidoscope'91 Kaleidoscope'93 Constraint Evaluation Lazy Eager Eager Variables Hold streams Hold streams Imperative Concurrent Constraints Strict Strict Non-strict Syntax Smalltalk-like Algol-like Algol-like Constraint Model Refinement Refinement Perturbation Method Dispatching Single Multiple Multiple Assignment As a constraint As a constraint Destructive

## 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

- Lopez, Gus; Bjorn Freeman-Benson; Alan Borning (1994). "Kaleidoscope: A Constraint Imperative Programming Language". *Constraint Programming*. Springer-Verlag. pp. 313–329.

- Marriott, Kim; Peter J. Stuckey (1998). *Programming with constraints: An introduction*. MIT Press. [ISBN](/source/ISBN_(identifier)) [0-262-13341-5](https://en.wikipedia.org/wiki/Special:BookSources/0-262-13341-5)

1. **[^](#cite_ref-1)** Lopez, Gus; Freeman-Benson, Bjorn; Borning, Alan (1993). ["Kaleidoscope: A Constraint Imperative Programming Language"](https://constraints.cs.washington.edu/cip/kaleidoscope-asi.pdf) (PDF). *constraints.cs.washington.edu*. Retrieved 2023-12-30.

This programming-language-related article is a stub. You can help Wikipedia by adding missing information.

- [v](https://en.wikipedia.org/wiki/Template:Prog-lang-stub)
- [t](/source/Template_talk%3AProg-lang-stub)
- [e](https://en.wikipedia.org/wiki/Special:EditPage/Template:Prog-lang-stub)

---
Adapted from the Wikipedia article [Kaleidoscope (programming language)](https://en.wikipedia.org/wiki/Kaleidoscope_(programming_language)) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Kaleidoscope_(programming_language)?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
