seed7-users Mailing List for Seed7
Interpreter and compiler for the Seed7 programming language.
Brought to you by:
thomas_mertes
You can subscribe to this list here.
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2008 |
Jan
|
Feb
(9) |
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
(4) |
Aug
|
Sep
(4) |
Oct
(4) |
Nov
|
Dec
(1) |
| 2011 |
Jan
(2) |
Feb
|
Mar
(8) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2012 |
Jan
|
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
(2) |
Aug
(6) |
Sep
(7) |
Oct
(3) |
Nov
(10) |
Dec
(4) |
| 2013 |
Jan
(2) |
Feb
|
Mar
(2) |
Apr
|
May
(1) |
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
(5) |
Nov
|
Dec
(1) |
| 2014 |
Jan
(1) |
Feb
|
Mar
|
Apr
(1) |
May
(6) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(4) |
Nov
(1) |
Dec
(1) |
| 2015 |
Jan
(2) |
Feb
(2) |
Mar
(2) |
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(3) |
Dec
|
| 2016 |
Jan
|
Feb
(3) |
Mar
(2) |
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2017 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2018 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2019 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
|
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(3) |
Dec
(3) |
| 2021 |
Jan
(2) |
Feb
(6) |
Mar
(1) |
Apr
(1) |
May
(1) |
Jun
(2) |
Jul
|
Aug
(1) |
Sep
(12) |
Oct
(4) |
Nov
(17) |
Dec
(3) |
| 2022 |
Jan
(1) |
Feb
(2) |
Mar
|
Apr
(2) |
May
|
Jun
(17) |
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2023 |
Jan
|
Feb
(1) |
Mar
(4) |
Apr
|
May
|
Jun
(3) |
Jul
|
Aug
(1) |
Sep
(1) |
Oct
(1) |
Nov
|
Dec
|
| 2024 |
Jan
|
Feb
(5) |
Mar
(7) |
Apr
|
May
|
Jun
|
Jul
(4) |
Aug
(12) |
Sep
|
Oct
|
Nov
|
Dec
(2) |
| 2025 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(11) |
Nov
(6) |
Dec
(1) |
|
From: Thomas M. <mer...@gm...> - 2025-12-06 09:24:09
|
Hey Zachary, Great that you are working on a Seed7 graphics driver for Wayland. You could fork the Seed7 GitHub repository (https://github.com/ThomasMertes/seed7) and commit changes to your fork. Regarding the keycode combinations with one modifier key (like Shift-F1): I consider combinations with one modifier key much more common than combinations with multiple modifier keys. KEY_SFT_F1 carries the modifier information. This way KEY_SFT_F1 can be used in arrays, hashes and case statements. Several example programs use this possibility. I assume that other Seed7 developers also use this possibility. I don't want to break backward compatibility. Sorry that this creates a bunch of extra work for your driver. Regarding holding off pushing the rending changes that arise from the drawing functions (circle(), rect(), put(), etc) until the flushGraphic function is called: This would be possible. You have to consider that reading from GRAPH_KEYBOARD (and checking if something can be read with inputReady()) also needs to flush the graphic. In Seed7 programs the function flushGraphic() is used before await(() or before long computations. GRAPH_KEYBOARD functions do not need an explicit flushGraphic() because flushing is considered in these functions. Could the code become more complicated because of this performance optimization? If this is the case I suggest postponing this performance optimization. The rule "First make it correct and then make it fast" makes sense in many cases. Best regards Thomas |
|
From: Zaakari <Za...@pr...> - 2025-11-22 19:26:19
|
Hey Thomas, I'm working on a Seed7 graphics driver for Wayland (I figured I'd start here and move to GDI+ after); but I have a couple of questions regarding driver implementation in general: - Seed7 has a lot of keycodes for combinations (like Shift-F1, Control-Backspace, Alt-A, etc.); and I know--in the past--they were necessary as there didn't used to be the ability to check for modifier keys via the buttonPressed function. But now that we can, having all those extra key-codes is not only redundant, but creates a bunch of extra work for each driver. Would you consider cutting them from the code (and users can simply utilize buttonPressed, which hase to get used for more complex or rare combinations anyway)? - In the graph library, there is a flushGraphic function for sending all requests to the "server". In designing this driver, would it be acceptable to hold-off pushing the rending changes that arise from the drawing functions (circle(), rect(), put(), etc) until the flushGraphic function is called? This way, I could implement significant performance improvements, by being able to avoid requesting and committing a new buffer for every drawing action the user performs. Basically, a user's changes might show up before he calls flushGraphic, but it wouldn't be guaranteed unless he calls it. Thanks, Zachary |
|
From: Zachary M. <za...@ma...> - 2025-11-13 12:46:07
|
Huh, interesting; is that due to how C deals with the ternary operator? Regardless, I appreciate that you aim for optimized code; and it's not a big deal for me to just use an if-else statement (it just seemed strange that it threw an error). Though, you might want to add a note to the section on hashes/arrays about it. Thanks for looking into it, Zachary |
|
From: Thomas M. <mer...@gm...> - 2025-11-13 09:24:56
|
Hey Zachary, For struct types the = and <> operators are not automatically defined. If you want these operators you need to define them yourself. E.g.: const func boolean: (in Box: box1) = (in Box: box2) is return box1.x = box2.x and box1.y = box2.y; const func boolean: (in Box: box1) <> (in Box: box2) is return not box1 = box2; This allows that some fields of the struct are not considered for equality. E.g.: In time.s7i the time comparison = does not consider timeZone and daylightSavingTime. Normalizing values before doing the actual comparison would also be an option. I will consider a way to quickly define the simple case where all elements are compared for equality. Best regards Thomas |
|
From: Thomas M. <mer...@gm...> - 2025-11-13 09:00:57
|
Hey Zachary, The only reason for not supporting ternary expressions for arrays or hashes is: There could be cases where whole arrays or hashes would be copied unnecessarily. If one of the branches of a ternary operation creates a temporary value the other branch is forced to create a temporary value as well (by copying the data). In your example (with assignments) the copying always takes place. So your case is not the problem. If the ternary operator is defined for a type it can be used for any purpose and not just for assignments. Nothing hinders you to introduce the ternary operator for the type StringHash with: DECLARE_TERNARY(StringHash); If you define an array type you can do the same with it. I will consider introducing the ternary operator for arrays and hashes. I will search for ways to avoid unnecessary copies. Best regards Thomas |
|
From: Zachary M. <za...@ma...> - 2025-11-12 16:19:35
|
Hey Thomas,
It seems like comparing two objects in the current Github code always
triggers a syntax error when using '=' or '<>' (on Windows, anyway):
$ include "seed7_05.s7i";
const type: Box is new struct
var integer: x is 0;
var integer: y is 0;
end struct;
const proc: main is func
local
var Box: a is Box.value;
begin
a.x := 5;
if a = Box.value then
writeln("yes");
else
writeln("no");
end if;
end func;
Running that yields:
SEED7 INTERPRETER Version 5.4.13 Copyright (c) 1990-2025 Thomas Mertes
*** test.sd7(14):57: Match for {a = {Box . value } } failed
if a = Box.value then
*** test.sd7(8):42: Declaration of "main" failed
const proc: main is func
Zachary |
|
From: Zachary M. <za...@ma...> - 2025-11-05 16:26:48
|
Hey Thomas, Is there a reason why assignment via ternary expression is not supported for arrays or hashes? var array string: strings is 0 times ""; const type: StringHash is hash [string] integer; var StringHash: aHash is StringHash.value; strings := 1 > 0 ? 3 times "" : 2 times ""; aHash := 1 > 0 ? [] (["a":1], ["b":2]) : StringHash.value; Zachary |
|
From: Zachary M. <za...@ma...> - 2025-10-31 14:08:09
|
Ah, toInterface; yes, that works. Clearly I was looking in the wrong places in the manual/faq. Thank you, Zachary |
|
From: Thomas M. <mer...@gm...> - 2025-10-31 08:45:58
|
Hi Zachary,
I suggest you use:
const func array Area: fetch_areas (in database: connection, in
string: lineage, in boolean: children) is forward;
const func Area: fetch_area (in database: connection, in
sqlStatement: statement, in boolean: children) is func
result
var Area: area is EmptyArea.value;
local
var TreeArea: anArea is TreeArea.value;
var integer: index is 1;
var Area: child is EmptyArea.value;
begin
anArea.id := column(statement, index, integer); incr(index);
anArea.path := column(statement, index, string); incr(index);
if children then
for child range fetch_areas(connection, anArea.path, TRUE) do
anArea.children &:= child;
end for;
end if;
area := toInterface(anArea);
end func;
const func array Area: fetch_areas (in database: connection, in
string: lineage, in boolean: children) is func
result
var array Area: areas is 0 times TreeArea.value;
local
var sqlStatement: statement is sqlStatement.value;
var string: query is "";
var TreeArea: anArea is TreeArea.value;
var integer: index is 1;
var TreeArea: child is TreeArea.value;
begin
query := join([]
( "SELECT",
join([]
( "areas.id",
"areas.path"
), ","),
"FROM areas",
"WHERE lineage = ?",
"ORDER BY areas.path"
), "\n");
statement := prepare(connection, query);
bind(statement, 1, lineage);
execute(statement);
while fetch(statement) do
areas &:= fetch_area(connection, statement, children);
end while;
end func;
The function fetch_area() creates a new 'Area' with the function toInterface().
After 'area := toInterface(anArea)' the local variable anArea (with
the implementation
type TreeArea) is referred by 'area' (with the interface type Area).
The ownership of the anArea struct moves to the interface value of 'area'.
At the end of fetch_area() the reference count of anArea is reduced but
the struct is not freed, because the interface variable 'area' still
refers to it.
I hope this helps.
Best regards
Thomas
|
|
From: Thomas M. <mer...@gm...> - 2025-10-31 08:19:29
|
Hi Zachary, As far as I know only MySQL allows backslash as escape character in SQL string literals. So this SELECT statement is just for MySQL. If it fails somehow for other databases this is not an issue. BTW.: You opened DB2 via ODBC WITH: connection := openDatabase(DB_ODBC, "", "", "DSN", "user", "password"); There is also the DB2 database driver DB_DB2 which can be used with: connection := openDatabase(DB_DB2, "www.example.org", 0, "databaseName", "user", "password"); or connection := openDatabase(DB_DB2, "", 0, "databaseAlias", "user", "password"); See: https://seed7.net/manual/database.htm#Opening_a_Db2_database_connection Please tell me if connecting with DB_DB2 succeeds or fails. Thank you in advance for your effort. Best regards Thomas |
|
From: Zachary M. <za...@ma...> - 2025-10-30 18:59:35
|
Hey Thomas,
I ran into an issue when trying to create a recursive structure: namely,
that I can't allocate new elements without them going out-of-scope and
getting automatically de-allocated.
The use-case is that I am making an object (i.e. Area below) that
represents a storage facility. Each area would have dimensions as well
as the possibility to contain sub-areas (which could also contain other
sub-areas, etc.). Imagine a 3D-grid. However, I obviously couldn't just
do something like this:
const type: Area is new struct
var integer: id is 0;
var string: path is "";
var array Area: children is 0 times Area.value;
end struct;
As I can't use the Area type until after its definition. So, instead, I
built it using an interface:
const type: Area is new interface;
const type: EmptyArea is new struct
end struct;
type_implements_interface(EmptyArea, Area);
const type: TreeArea is sub EmptyArea struct
var integer: id is 0;
var string: path is "";
var array Area: children is 0 times EmptyArea.value;
end struct;
type_implements_interface(TreeArea, Area);
That worked, but when I try to populate the children (which--for my
use-case--can be up to seven deep) by fetching the data from a database,
they lose scope and get dropped (I'm guessing freed by the garbage
collector, since their references vanish):
const func array TreeArea: fetch_areas (in database: connection, in
string: lineage, in boolean: children) is func
result
var array TreeArea: areas is 0 times TreeArea.value;
local
var sqlStatement: statement is sqlStatement.value;
var string: query is "";
var TreeArea: anArea is TreeArea.value;
var integer: index is 1;
var TreeArea: child is TreeArea.value;
begin
query := join([]
( "SELECT",
join([]
( "areas.id",
"areas.path"
), ","),
"FROM areas",
"WHERE lineage = ?",
"ORDER BY areas.path"
), "\n");
statement := prepare(connection, query);
bind(statement, 1, lineage);
execute(statement);
while fetch(statement) do
anArea := TreeArea.value;
index := 1;
anArea.id := column(statement, index, integer); incr(index);
anArea.path := column(statement, index, string); incr(index);
areas &:= anArea;
if children then
# Can't do this.
# anArea.children &:= fetch_areas(connection, anArea.path);
for child range fetch_areas(connection, anArea.path, TRUE) do
# Can't do this either.
# anArea.children &:= xalloc(child);
anArea.children &:= child; # This works, but the data is
lost once the function exits.
end for;
end if;
end while;
end func;
As you can see in the code snippet, I had tried using xalloc (as noted
in the manual under Object Orientation); but it looks like that function
was removed back in 2016 (there is a change-log entry about it).
Now, I think I could work around this by defining 6 more structures that
each supported one extra level of children (avoiding the use of an
interface array), something like:
const type: Area is new struct
var integer: id is 0;
var string: path is "";
end struct;
const type: TreeArea1 is sub Area struct
var array Area: children is 0 times Area.value;
end struct;
const type: TreeArea2 is sub Area struct
var array TreeArea1: children is 0 times TreeArea1.value;
end struct;
# etc.
But--as I imagine this would be somewhat cumbersome to use--I wanted to
check with you to see if I'm missing something; that is: what is the
proper way to implement a recursive object in Seed7 (or is this frowned
upon)?
Zachary |
|
From: Zachary M. <za...@ma...> - 2025-10-30 14:55:10
|
Yes, that results in no error.
However, I'm not sure that this produces the correct result for DB2. The
error was not due to backslashes being selected, but rather due to the
lack of a FROM clause. DB2 seems to require one, as even "select 1"
would fail with the same error (prior to doPrepare and doExecute); which
would result in your check giving a flawed result.
I did some digging, and it looks like DB2 is about the only one that
requires a FROM clause. This could be solved by doing something like:
SELECT * FROM (VALUES('\\\\'))
But apparently that would cause a similar problem for MySQL (which can't
use the VALUES expression like that).
So (though preventing a database error from propagating might still be a
good idea), would it be possible to also adjust the check when the
database type is DB2 to include a FROM clause?
Thanks,
Zachary
On 2025-10-30 09:05, Thomas Mertes wrote:
> Hi Zachary,
>
> The statement "SELECT '\\\\'" is on purpose.
> MySQL databases might allow a backslash as escape character in string
> literals (in a prepared statement).
> This depends on the setting of a MySQL database.
> The statement should determine if backslash is an escape character or not.
> As such it should never trigger a DATABASE_ERROR.
> If something goes wrong the backslash is obviously not an escape character.
>
> I just commited "Introduce doPrepare() and doExecute()"
> (see:https://github.com/ThomasMertes/seed7/commit/d3a24aaef0179b0031e9cbcb864b5f1bc243a244
> ).
>
> With this commit the statement "SELECT '\\\\'" is prepared with
> doPrepare() and executed with doExecute().
> These functions do not raise a DATABASE_ERROR if something fails.
>
> Please test accessing DB2 again with this FIX and tell me the results.
>
> Best regards
> Thomas
>
>
> _______________________________________________
> Seed7-users mailing list
> See...@li...
> https://lists.sourceforge.net/lists/listinfo/seed7-users
--
Zachary Menzies
/Developer | 519.323.4289/
Maple Lane Farm Service
/9545 Concession 6 N | Mount Forest, ON | N0G 2L0/ |
|
From: Thomas M. <mer...@gm...> - 2025-10-30 13:06:08
|
Hi Zachary, The statement "SELECT '\\\\'" is on purpose. MySQL databases might allow a backslash as escape character in string literals (in a prepared statement). This depends on the setting of a MySQL database. The statement should determine if backslash is an escape character or not. As such it should never trigger a DATABASE_ERROR. If something goes wrong the backslash is obviously not an escape character. I just commited "Introduce doPrepare() and doExecute()" (see: https://github.com/ThomasMertes/seed7/commit/d3a24aaef0179b0031e9cbcb864b5f1bc243a244 ). With this commit the statement "SELECT '\\\\'" is prepared with doPrepare() and executed with doExecute(). These functions do not raise a DATABASE_ERROR if something fails. Please test accessing DB2 again with this FIX and tell me the results. Best regards Thomas |
|
From: Zachary M. <za...@ma...> - 2025-10-29 20:55:17
|
Hey Thomas,
I was using Seed7 again to connect to a DB2/AS400 via an ODBC connection
using something like this:
connection := openDatabase(DB_ODBC, "", "", "DSN", "user", "password");
But it was producing the following error:
[IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0104 - Token
<END-OF-STATEMENT> was not valid. Valid tokens: , FROM INTO.
SQLState: 42000
NativeError: -104
I thought it strange, since the error was thrown on connection--I hadn't
run any queries yet. But using a trace and doing some digging, I found
the issue was related to a select statement that gets automatically
called in "src/sql_cli.c" at line 6394:
statementStri = cstri_to_stri("SELECT '\\\\'");
It seems the reason for this is that DB2-based databases don't permit
selecting from nothing. However, I was able to fix the issue by changing
the line to select from a CTE:
statementStri = cstri_to_stri("WITH slashes AS (VALUES('\\\\')) SELECT *
FROM slashes");
Would you be willing to implement a similar fix into the source?
Thanks,
Zachary
|
|
From: Zaakari <Za...@pr...> - 2025-10-20 22:24:49
|
Ah, it never registered with me before that I had to use interfaces to pass references around. So then, given: const type: Point is new interface; const type: Flashy is new struct type_implements_interface(Flashy, Point); Not only is your example possible (same-level reassignment): var Point: a is Flashy.value; var Flashy: b is Flashy.value; var Flashy: c is Flashy.value; a := b; # make adjustments to b using a... a := c; # make adjustments to c using a... But also reassignment via function (given that a, b and c were all declared outside the function): (* A simple example here, but--in reality--the second parameter would end up being either an array or a containing object *) const proc: switch_to (inout Point: base, in Point: target) is func begin base := target; # target isn't local, so all is well.end func; switch_to(a, b); # make adjustments to b using a... switch_to(a, c); # make adjustments to c using a... In the past, I was doing something similar to this without templates, and it was a huge pain (basically using integers to remember object offsets within arrays); so thank you for clearing up the confusion for me (my desire to use Seed7 has been renewed ;). Zachary |
|
From: Thomas M. <mer...@gm...> - 2025-10-18 15:26:57
|
Hi Zachary, There in no way for a function to return a reference to a variable (or to an element of a struct). Seed7 has no pointer types which would allow this. This is by design as it could trigger a memory corruption. I just added a section to the FAQ which explains this: https://seed7.net/faq.htm#return_reference_to_struct_element As you said passing by reference into functions in the downward direction is supported. This has not the danger of a memory corruption. I added a section to the FAQ about that: https://seed7.net/faq.htm#parameter_referencing_struct_element Object orientation allows that two or more variables refer to the same object. Regarding this I just added a section to the FAQ: https://seed7.net/faq.htm#variables_referring_same_object The type reference (see: https://seed7.net/manual/types.htm#reference ) describes a reference to an object in the abstract syntax tree (AST) of a program.If you parse a program the type reference can be used to refer to a part of the AST (see: https://seed7.net/faq.htm#access_AST ). The type reference cannot be used as pointer type. I hope this helps. Best regards Thomas |
|
From: Zaakari <Za...@pr...> - 2025-10-08 20:58:23
|
Hey Thomas, I know that values can be bassed by reference into functions--and this, along with templates allows a pointe-like function in a downward direction; but is there a way to have functions return references to variables (upward direction)? And is there a way to create references to variables, such that I could have x and y both refer to the same object? One simple use case for this would be to pass a complex object to a function, and have the function return a reference to a nested property within said object. I see there is the 'reference' type in the manual, but I''ve never been able to get it to work; that is, I don't know how to properly use it, or if it is supposed to used for these sort of examples. Zachary |
|
From: יהודה ג. <gurovich@g.jct.ac.il> - 2025-03-27 16:26:29
|
Hi Thomas, I hope you're doing well! I noticed that you're still actively developing Seed7, as I saw your recent update on Reddit. I was wondering if you're available to answer any emails related to questions or inquiries about Seed7? Looking forward to hearing from you! Best regards, Yehuda Gurovich |
|
From: Thomas M. <tho...@gm...> - 2024-12-10 11:53:18
|
Hi Simon,
The parse operator is the inverse operation of the str() function.
The parse operator converts a string to the given type.
Many types have a parse operator. E.g.:
integer parse "12345" returns 12345
float parse "3.2425" returns 3.1415
For the sake of completeness, the type string also defines the function str()
and the parse operator. Both only return their parameter. E.g.:
str("hello") returns "hello"
string parse "hello" returns "hello"
These uses of str() and the parse operator do not make sense.
But inside of templates they make sense. Inside a template you use a generic
type specified by a template parameter.
The template CONVERSION_CHECK below defines the function conversionOkay().
The function conversionOkay() returns TRUE if the given string stri can be
successfully converted to the given type aType.
$ include "seed7_05.s7i";
include "float.s7i";
const proc: CONVERSION_CHECK (in type: aType) is func
begin
const func boolean: conversionOkay (in string: stri, attr aType) is func
result
var boolean: okay is FALSE;
local
var aType: dest is aType.value;
begin
okay := succeeds(dest := aType parse stri);
end func;
end func;
CONVERSION_CHECK(integer);
CONVERSION_CHECK(float);
CONVERSION_CHECK(string);
const proc: main is func
begin
writeln(conversionOkay("1234", integer));
writeln(conversionOkay("zero", integer));
writeln(conversionOkay("3.14", float));
writeln(conversionOkay("3,14", float));
writeln(conversionOkay("hello", string));
end func;
The program above writes:
TRUE
FALSE
TRUE
FALSE
TRUE
Best regards
Thomas
|
|
From: Simon D. <sim...@ao...> - 2024-12-08 16:10:28
|
Hello , I can't figure out what the parse function in string.sd7 does or how it is used. Simon |
|
From: Thomas M. <tho...@gm...> - 2024-08-27 10:33:38
|
Hi Simon,
Thank you for your error report. This helps me to improve Seed7.
The types 'array baseType' (defined in array.s7i) and
'array [indexType] baseType' (defined in idxarray.s7i) are not related to each other.
Some functions are declared for both types. The statements
DECLARE_MY_PRINT_ARRAY(integer, integer);
redeclares functions which 'array integer' already had declared.
This triggers the error messages.
I found a simple solution. At the end of idxarray.s7i I added:
const func type: array [ (attr integer) ] (in type: baseType) is
return array baseType;
This maps 'array [integer] baseType' to 'array baseType'.
I checked this change into GitHub as "Map 'array [integer] baseType' to 'array baseType'".
You can either use the GitHub version or just add
const func type: array [ (attr integer) ] (in type: baseType) is
return array baseType;
to the end of idxarray.s7i.
With this fix my test program writes:
SEED7 INTERPRETER Version 5.2.72 Copyright (c) 1990-2024 Thomas Mertes
-----------------------------------------
the type of the array index is integer
the type of the array elements is integer
size of the array is 5
minimum index is 1
maximum index is 5
1: 10
2: 20
3: 30
4: 40
5: 50
Best regards
Thomas
|
|
From: Simon D. <sim...@ao...> - 2024-08-23 10:57:50
|
I noticed an array on the website with a non-integer index: Something like this:
var array [char] string : unusual_index is ['0'] ("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine");
So I made a separate two-types templated function to print information on this array:
const proc: DECLARE_MY_PRINT_ARRAY(in type: aType1, in type: aType2) is funcbegin const proc: myPrintArray(in array [aType1] aType2: the_array) is func local var aType1: the_index is aType1.value; begin writeln("-----------------------------------------"); writeln("the type of the array index is " & str(aType1) ); writeln("the type of the array elements is " & str(aType2)); writeln("size of the array is " & str(length(the_array))); writeln("minimum index is " & str(minIdx(the_array))); writeln("maximum index is " & str(maxIdx(the_array))); if length(the_array) = 0 then writeln("***** The array is empty ******"); else for key the_index range the_array do writeln(str(the_index) & ": " & str(the_array[the_index])); end for; end if; end func;end func;
That works with these statements;DECLARE_MY_PRINT_ARRAY(char, string);
var array [char] string : unusual_index is ['0'] ("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine");
myPrintArray(unusual_index);
But it occurred to me that I should also be able to call that function with standard integer index arrays:
var array integer: integer_array is [1] (10, 20, 30, 40,50);
DECLARE_MY_PRINT_ARRAY(integer, integer);
myPrintArray(integer_array);
However, that doesn't work. I am not sure if I am doing something wrong. The interpreter gives errors and they start in array.s7i :
*** /c/seed7/lib/idxarray.s7i(107):34: Redeclaration of "[ (val integer: start) ] (ref TST_1: aTuple)" const func arrayType: [ (in indexType: startIndex) ] (in tupleType: arr_tuple) is
*** /c/seed7/lib/array.s7i(92):35: Previous declaration of "[ (val integer: start) ] (ref TST_1: aTuple)" const func arrayType: [ (in integer: start) ] (in tupleType: aTuple) is action "ARR_ARRLIT2";
*** /c/seed7/lib/idxarray.s7i(108):52: Match for {arrayType conv func *ANONYM_TYPE* : <DECLAREDOBJECT> ({[ INT_ICONV1({startIndex ord }) ] arr_tuple }) } failed return arrayType conv ([ord(startIndex)] arr_tuple);
*** /c/seed7/lib/idxarray.s7i(110):34: Redeclaration of "[ (val integer: start) ] (val integer: anElement)" const func arrayType: [ (in indexType: startIndex) ] (in baseType: base_elem) is
*** /c/seed7/lib/array.s7i(93):35: Previous declaration of "[ (val integer: start) ] (val integer: anElement)" const func arrayType: [ (in integer: start) ] (in baseType: anElement) is action "ARR_BASELIT2";
*** /c/seed7/lib/idxarray.s7i(111):52: Match for {arrayType conv func *ANONYM_TYPE* : <DECLAREDOBJECT> ({[ INT_ICONV1({startIndex ord }) ] base_elem }) } failed return arrayType conv ([ord(startIndex)] base_elem);
*** /c/seed7/lib/idxarray.s7i(221):52: Match for {arrayType conv func *ANONYM_TYPE* : <DECLAREDOBJECT> ({[ INT_ICONV1({integer: <INTOBJECT> ({integer . first }) ord }) ] ARR_CONV({tupleType conv anArray }) }) } failed anArray := arrayType conv ([ord(indexType.first)] (tupleType conv anArray));
*** /c/seed7/lib/idxarray.s7i(216):32: Declaration of "(attr type) times (val integer: base_value)" failed const func arrayType: (attr indexType) times (in baseType: base_value) is func
*** /c/Users/sdash/OneDrive/code/Seed7/Exploring/my_print_array.sd7(78):52: Match for {integer_array ::= func *ANONYM_TYPE* : <DECLAREDOBJECT> ({[ 1 ] ARR_EXTEND({ARR_EXTEND({ARR_EXTEND( *** details suppressed *** ) , 40 }) , 50 }) }) } failedend func;---------^*** /c/Users/sdash/OneDrive/code/Seed7/Exploring/my_print_array.sd7(66):32: Declaration of "integer_array" failed var array integer: integer_array is [1] (10, 20, 30, 40,50);
*** /c/Users/sdash/OneDrive/code/Seed7/Exploring/my_print_array.sd7(73):52: Match for {integer_array myPrintArray } failed myPrintArray(integer_array);
*** /c/Users/sdash/OneDrive/code/Seed7/Exploring/my_print_array.sd7(64):32: Declaration of "main" failedconst proc: main is func
Simon |
|
From: Simon D. <sim...@ao...> - 2024-08-21 02:55:21
|
Hi Thomas,
Everything working well now including the templates. I did a template with two types passed in. Worked great and so much easier or cleaner than in other languages!
Thanks,Simon
On Friday, August 16, 2024 at 02:49:25 AM PDT, Thomas Mertes via Seed7-users <see...@li...> wrote:
Hi Simon,
There is a bug in the Seed7 installer seed7_05_20240630_win.exe.
It fails to recognize a 64-bit Windows.
It always thinks that the computer is 32-bit:
POINTER_SIZE: 32
This problem is solved with the new Seed7 installer for Windows:
https://sourceforge.net/projects/seed7/files/bin/seed7_05_20240812_win.exe/download
You probably just need to use the new installer.
Using the GitHub version of Seed7 is currently not necessary.
Best regards
Thomas
_______________________________________________
Seed7-users mailing list
See...@li...
https://lists.sourceforge.net/lists/listinfo/seed7-users
|
|
From: Thomas M. <tho...@gm...> - 2024-08-16 09:49:10
|
Hi Simon,
There is a bug in the Seed7 installer seed7_05_20240630_win.exe.
It fails to recognize a 64-bit Windows.
It always thinks that the computer is 32-bit:
POINTER_SIZE: 32
This problem is solved with the new Seed7 installer for Windows:
https://sourceforge.net/projects/seed7/files/bin/seed7_05_20240812_win.exe/download
You probably just need to use the new installer.
Using the GitHub version of Seed7 is currently not necessary.
Best regards
Thomas
|
|
From: Thomas M. <tho...@gm...> - 2024-08-13 08:16:59
|
Hi Simon,
I have a theory about the errors in chkarr.sd7:
For some reason you use a GCC which produces 32-bit executables.
This can be checked when you do (in the seed7\prg directory):
s7 confval
Please send me the output of confval.
Confval writes a list of values. One of them is POINTER_SIZE.
A POINTER_SIZE of 32 would explain the errors you get in chkarr.sd7.
The confval value C_COMPILER_VERSION shows which GCC version is used.
Something with 13.2.0 indicates that the 64-bit gcc provided in the seed7\gcc directory is used.
Something with 4.8.1 indicates that the 32-bit gcc provided in the seed7\gcc directory is used.
Other values of C_COMPILER_VERSION indicate that the gcc is not from the seed7\gcc directory.
The command
where gcc
might give a hint which other gcc is used.
For the gcc from the seed7\gcc directory the "where" command gives wrong results.
You can also use the command:
call_gcc --version
to find out which gcc version from the seed7\gcc directory is used.
The last time I added tests to chkarr.sd7 I did not consider 32-bit programs.
The minimum and maximum possible indices differ between 32-bit and 64-bit.
As a consequence in a 32-bit system the chkarr.sd7 test will not succeed.
I changed chkarr.sd7 to work for a POINTER_SIZE of 32-bit and 64-bit.
I committed this to GitHub as "Fix chkarr.sd7 to work if POINTER_SIZE is 32".
With this change tests with chkarr.sd7 should succeed with a 32-bit gcc.
You should definitely find the root cause why a 32-bit gcc is used.
One possibility would be:
The seed7\gcc directory does not exist (you forgot to copy it).
In this case the command bin\call_gcc.bat would use a gcc found
in the search path (PATH environment variable).
Best regards,
Thomas
|