CLAIRE
The Towers of Hanoi as a CLAIRE program.
According to the CLAIRE website:
Claire is an object-oriented language designed to express complex algorithms in an elegant manner. Some of its features are:
- Simple and readable, because reuse of algorithms requires a readable expression of the ideas, but also because CLAIRE was part of a research and teaching project and we needed an "executable pseudo-code" to demonstrate algorithms;
- Multi-paradigm (supporting logic, imperative and functional programming styles), with few simple and well-understood concepts, such as objects, functions, rules and versioning for building search trees;
- Compiled efficiently so that using a high-level language is no longer a burden when writing algorithms that will compete against C++ or FORTRAN implementations.
// The Towers Of Hanoi
// CLAIRE
// Copyright (C) 2003 Amit Singh. All Rights Reserved.
// http://hanoi.kernelthread.com
//
// Last tested under CLAIRE 3.3.14
// http://groups.yahoo.com/group/claireprogramminglanguage/
//
// Usage:
// % sclaire # launch the CLAIRE environment
// claire> load("hanoi") # load hanoi.cl
// claire> hanoi(3) # run with 3 disks
//
[
H(n:integer, f:integer, u:integer, t:integer) : void ->
if (n > 0) (
H(n - 1, f, t, u),
printf("~S --> ~S\n", f, t),
H(n - 1, u, f, t)
) else (
true
)
]
[
hanoi(n:integer) : void ->
if (n > 0) (
H(n, 1, 2, 3)
)
]