52 lines
1.4 KiB
Plaintext
52 lines
1.4 KiB
Plaintext
$ include "seed7_05.s7i";
|
|
|
|
const type: setListType is array array string;
|
|
|
|
const func array string: amb (in string: word1, in setListType: listOfSets) is func
|
|
result
|
|
var array string: ambResult is 0 times "";
|
|
local
|
|
var string: word2 is "";
|
|
begin
|
|
for word2 range listOfSets[1] do
|
|
if length(ambResult) = 0 and word1[length(word1) len 1] = word2[1 len 1] then
|
|
if length(listOfSets) = 1 then
|
|
ambResult := [] (word1) & [] (word2);
|
|
else
|
|
ambResult := amb(word2, listOfSets[2 ..]);
|
|
if length(ambResult) <> 0 then
|
|
ambResult := [] (word1) & ambResult;
|
|
end if;
|
|
end if;
|
|
end if;
|
|
end for;
|
|
end func;
|
|
|
|
const func array string: amb (in setListType: listOfSets) is func
|
|
result
|
|
var array string: ambResult is 0 times "";
|
|
local
|
|
var string: word1 is "";
|
|
begin
|
|
for word1 range listOfSets[1] do
|
|
if length(ambResult) = 0 then
|
|
ambResult := amb(word1, listOfSets[2 ..]);
|
|
end if;
|
|
end for;
|
|
end func;
|
|
|
|
const proc: main is func
|
|
local
|
|
var array string: ambResult is 0 times "";
|
|
var string: word is "";
|
|
begin
|
|
ambResult := amb([] ([] ("the", "that", "a"),
|
|
[] ("frog", "elephant", "thing"),
|
|
[] ("walked", "treaded", "grows"),
|
|
[] ("slowly", "quickly")));
|
|
for word range ambResult do
|
|
write(word <& " ");
|
|
end for;
|
|
writeln;
|
|
end func;
|