Seed7
- Appeared in:
- 2005
- Paradigm:
- Typing discipline:
- File extensions:
- .sd7 (source code), .s7i (libraries)
- Versions and implementations (Collapse all | Expand all):
Seed7 is an extensible general-purpose language.
Seed7 is developed by Thomas Mertes.
The main concept of Seed7 is its extensibility: new statements and operators can be declared easily. Actually, most of language features are implemented as a library seed7_05.s7i
. Seed7 enables programming in object-oriented style but is is used only when it is convenient, and isn’t required.
Although Seed7 contains concepts of other programming languages and resembles several of them, the author doesn’t consider it to be a descendant of any particular language.
Key features of Seed7:
- extensibility: support for user-defined statements and operators.
- types are first-class objects (i.e., templates and generics can be defined easily and don’t require special syntax).
- predefined constructs like arrays or for-loops are declared in the language itself.
- support for object-orientated paradigm with interfaces and multiple dispatch.
- static type-checking, no automatic casts.
-
support for
bigInteger
andbigRational
numbers of unlimited size. - built-in exception handling.
- overloading of procedures/functions/operators/statements.
- various predefined types like resizable arrays, hashes, sets, structs, color, time, duration, etc.
Links:
Examples:
Hello, World!:
Example for versions Seed7 2012-01-01$ include "seed7_05.s7i";
const proc: main is func
begin
writeln("Hello, World!");
end func;
Factorial:
Example for versions Seed7 2012-01-01This example uses built-in factorial function !n
. It is defined only for integer
data type, so trying to calculate 13! causes an overflow. The program output looks as follows:
0! = 1
1! = 1
2! = 2
...
11! = 39916800
12! = 479001600
13! =
*** Uncaught EXCEPTION NUMERIC_ERROR raised with
{! integer <80ba990>: <SYMBOLOBJECT> 0 }
{! (in integer <80ba990> param) } at factorial-builtin.sd7(10)
main no POSINFO
$ include "seed7_05.s7i";
const proc: main is func
local
var integer: n is 0;
begin
for n range 0 to 16 do
writeln(n <& "! = " <& !n);
end for;
end func;
Factorial:
Example for versions Seed7 2012-01-01This example uses recursive factorial definition. Factorial values are stored as bigInteger
, so there is no overflow.
$ include "seed7_05.s7i";
include "bigint.s7i";
const func bigInteger: factorial (in var bigInteger: n) is func
result
var bigInteger: result is 1_;
begin
if n = 0_ then
result := 1_;
else
result := n * factorial(n - 1_);
end if;
end func;
const proc: main is func
local
var integer: n is 0;
begin
for n range 0 to 16 do
write(n);
write("! = ");
write(factorial(bigInteger conv n));
writeln;
end for;
end func;
Fibonacci numbers:
Example for versions Seed7 2012-01-01This example uses recursive definition of Fibonacci numbers.
$ include "seed7_05.s7i";
const func integer: fibonacci (in var integer: n) is func
result
var integer: result is 1;
begin
if n < 2 then
result := 1;
else
result := fibonacci(n - 1) + fibonacci(n - 2);
end if;
end func;
const proc: main is func
local
var integer: n is 0;
begin
for n range 0 to 15 do
write(fibonacci(n) <& ", ");
end for;
writeln("...");
end func;
CamelCase:
Example for versions Seed7 2012-01-01This example uses character-by-character processing.
$ include "seed7_05.s7i";
const proc: main is func
local
var string: text is "";
var string: camel_case is "";
var char: ch is ' ';
var boolean: was_space is TRUE;
begin
readln(text);
text := lower(text);
for ch range text do
if ch in {'a' .. 'z'} then
if was_space then
ch := upper(ch);
end if;
camel_case &:= ch;
was_space := FALSE;
else
was_space := TRUE;
end if;
end for;
writeln(camel_case);
end func;
Quadratic equation:
Example for versions Seed7 2012-01-01$ include "seed7_05.s7i";
include "float.s7i";
include "math.s7i";
const proc: main is func
local
var float: a is 0.0;
var float: b is 0.0;
var float: c is 0.0;
var float: d is 0.0;
begin
readln(a);
if a = 0.0 then
writeln("Not a quadratic equation.");
else
readln(b);
readln(c);
d := b ** 2 - 4.0 * a * c;
if d = 0.0 then
writeln("x = " <& (-b / 2.0 / a));
else
if d > 0.0 then
writeln("x1 = " <& ((-b + sqrt(d)) / 2.0 / a));
writeln("x2 = " <& ((-b - sqrt(d)) / 2.0 / a));
else
writeln("x1 = (" <& (-b / 2.0 / a) <& "," <& (sqrt(-d) / 2.0 / a) <& ")");
writeln("x2 = (" <& (-b / 2.0 / a) <& "," <& (-sqrt(-d) / 2.0 / a) <& ")");
end if;
end if;
end if;
end func;
Comments
]]>blog comments powered by Disqus
]]>