Seed7 2012年01月01日

Version of implementation Seed7 of programming language Seed7

A version of Seed7, released on January 1st, 2012.

Changes:

  • pollData type moved from socket.s7i to poll.s7i; it supports the following functions: clear, addCheck, removeCheck, getCheck, poll, getFinding, hasNext, iterChecks, iterFindings, nextFile, for. -inetListener type moved from socket.s7i to listener.s7i; it supports the following functions: openInetListener, close, signOff, listen, accept, waitForRequest.
  • socketAddress type moved from socket.s7i to sockbase.s7i; it supports the following functions: numericAddress, inetSocketAddress, inetListenerAddress, getHostname.
  • Support for POL_ADD_READ_CHECK POL_ADD_WRITE_CHECK, POL_FILES, POL_HAS_NEXT_READ_FILE, POL_HAS_NEXT_WRITE_FILE, POL_NEXT_READ_FILE, POL_NEXT_WRITE_FILE, POL_READY_FOR_READ, POL_READY_FOR_WRITE, POL_REMOVE_READ_CHECK, POL_REMOVE_WRITE_CHECK, SOC_SELECT_INPUT removed from compiler and interpreter.
  • Support for POL_ADD_CHECK, POL_GET_CHECK, POL_GET_FINDING, POL_HAS_NEXT, POL_ITER_CHECKS, POL_ITER_FINDINGS, POL_NEXT_FILE, POL_REMOVE_CHECK, SOC_GET_ADDR added to compiler and interpreter.
  • Files pollib.c, pollib.h, pol_dos.c, pol_sel.c, pol_unx.c, pol_drv.h, soclib.c, soclib.h, soc_rtl.c, soc_dos.c added or improved.
  • Example ftpserv.sd7 is improved.
  • Console driver con_win.c is improved (so that keypressed recognizes Ctrl-C as regular keyboard input).
  • Function socGets improved to avoid calling realloc() if the string is shorter than requested.

Links:

Examples:

Hello, World! - Seed7 (396):

$ include "seed7_05.s7i";
const proc: main is func
begin
 writeln("Hello, World!");
end func;

Factorial - Seed7 (397):

This 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 - Seed7 (398):

This 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 - Seed7 (399):

This 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 - Seed7 (400):

This 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 - Seed7 (401):

$ 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;

AltStyle によって変換されたページ (->オリジナル) /