seed7-users Mailing List for Seed7 (Page 4)
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
(5) |
Dec
|
|
From: Thomas M. <tho...@gm...> - 2022-04-12 18:57:25
|
Hi Anders,
You wrote in a private mail:
> I have a question which in a general way is: How to define a general type in a library
> which will be decided later on in the specific application?
> To illustrate what I am looking for I have created a test application and a library, ...
> The heap-library (heapV9.s7i) defines a heap structure and organises it as a binary tree.
> As it is now the heap-value needs to be a string. However I want it to be more dynamic and
> defined later on when using the heap-structure in an application.
> Until now I have not succeeded to solve it. I have been looking at how arrays can be built
> for different datatypes but have not been able to apply it for the heap-library.
> Maybe this is not the right way to do it.
> So my question is if there is a good way to do this?
In your mail you attached the files test19.sd7 and heapV9.s7i.
I have ommited these files here.
I post my answer also to see...@li... because I think that
it is also useful for others.
I assume that an abstract data type will probably fit your needs.
I have attached the heap-library heapV9x.s7i.
This library defines the function heapT which uses baseType as parameter.
The heapT function creates the actual structure and defines the functions for it.
Like with arrays a second call of heapT with the same type as baseType will refer to the same heapType.
This is done with the lines
heapType := get_type(getfunc(heapT (attr baseType)));
if heapType = void then
The then part of the if-statement is executed when there is no previous declaration of heapT with this baseType.
The line
elmHashT := hash [integer] baseType;
defines elmHashT as helping type. The type elmHashT is only used inside of the heapT function.
The actual declarations are done inside a
global
...
end global;
construct. This makes sure that the declarations are done at a global level.
My solution does not need the type daEnum and the functions lessThan() and init().
---------- begin heapV9x.s7i ----------
const func type: heapT (in type: baseType) is func
result
var type: heapType is void;
local
var type: elmHashT is void;
begin
heapType := get_type(getfunc(heapT (attr baseType)));
if heapType = void then
global
elmHashT := hash [integer] baseType;
heapType := new struct
var elmHashT: elmH is elmHashT.EMPTY_HASH;
var integer: keyMax is 0; # Max of key to the hash-table
var array integer: ptrArr is [0 len 0] times integer.value; # indexes to the element stored in elmH
end struct;
const func integer: length(in heapType: aHeap) is
return length(aHeap.ptrArr);
const func baseType: readMin(in heapType: aHeap) is func
result
var baseType: aResultVal is baseType.value;
begin
if length(aHeap.ptrArr) > 0 then
aResultVal := aHeap.elmH[aHeap.ptrArr[minIdx(aHeap.ptrArr)]];
end if;
end func;
const proc: swap(inout heapType: aHeap, in integer: id1, in integer: id2) is func
local
var integer: temp is integer.value;
begin
temp := aHeap.ptrArr[id1];
aHeap.ptrArr[id1] := aHeap.ptrArr[id2];
aHeap.ptrArr[id2] := temp;
end func;
const proc: add(inout heapType: aHeap, in baseType: aValue) is func
local
var integer: idx is integer.value;
var integer: idx2 is integer.value;
var integer: idh is integer.value;
begin
incr(aHeap.keyMax);
incl(aHeap.elmH,aHeap.keyMax,aValue);
aHeap.ptrArr &:= aHeap.keyMax;
idx := maxIdx(aHeap.ptrArr);
if idx > 0 then
idx2 := (idx+1) div 2 - 1; # Has to calculate on pairs {even, odd} not {odd, even}
while aHeap.elmH[aHeap.ptrArr[idx]] < aHeap.elmH[aHeap.ptrArr[idx2]] do
swap(aHeap,idx,idx2);
idx := idx2;
idx2 := idx > 0 ? (idx+1) div 2 - 1 : 0; # Has to stop when reaches the root node
end while;
end if;
end func;
const func baseType: getFirst(inout heapType: aHeap) is func
result
var baseType: aResultVal is baseType.value;
local
var integer: elmPtr is integer.value;
var integer: idx is integer.value;
var integer: idx1 is integer.value;
var integer: idx2 is integer.value;
begin
if length(aHeap.ptrArr) > 0 then
elmPtr := remove(aHeap.ptrArr,minIdx(aHeap.ptrArr));
aResultVal := aHeap.elmH[elmPtr];
excl(aHeap.elmH,elmPtr);
if length(aHeap.ptrArr) > 0 then
elmPtr := remove(aHeap.ptrArr, maxIdx(aHeap.ptrArr));
insert(aHeap.ptrArr,0,elmPtr);
idx := minIdx(aHeap.ptrArr); # 0;
idx1 := 1;
idx2 := 2;
while (idx1 <= maxIdx(aHeap.ptrArr) and
aHeap.elmH[aHeap.ptrArr[idx1]] < aHeap.elmH[aHeap.ptrArr[idx]]) or
(idx2 <= maxIdx(aHeap.ptrArr) and
aHeap.elmH[aHeap.ptrArr[idx2]] < aHeap.elmH[aHeap.ptrArr[idx]]) do
if idx2 <= maxIdx(aHeap.ptrArr) and
aHeap.elmH[aHeap.ptrArr[idx2]] < aHeap.elmH[aHeap.ptrArr[idx1]] then
swap(aHeap,idx,idx2);
idx := idx2;
else
swap(aHeap,idx,idx1);
idx := idx1;
end if;
idx1 := 2*idx+1;
idx2 := 2*idx+2;
end while;
end if;
end if;
end func;
end global;
end if;
end func;
---------- end heapV9x.s7i ----------
I have also modified the test program test19x.sd7 to use the new parameterized heapT.
---------- begin test19x.s7i ----------
$ include "seed7_05.s7i";
include "time.s7i";
include "array.s7i";
include "heapV9x.s7i";
const integer: MAX is 10000;
const type: intHeapType is heapT(integer);
const proc: main is func
local
var intHeapType: aHeap is intHeapType.value;
var integer: idx is integer.value;
var boolean: correct is TRUE;
var array integer: checkArr is 0 times integer.value;
var integer: aRVal is integer.value;
var integer: heapValue is integer.value;
begin
writeln("\nAdding " <& MAX <& " values to the heap...");
writeln("Before: " <& time(NOW));
for idx range 1 to MAX do
aRVal := rand(1,100);
checkArr &:= aRVal;
add(aHeap,aRVal); #The value added to the heap needs NOT to be converted to a string
end for;
writeln("After: " <& time(NOW));
checkArr := sort(checkArr);
writeln("\nChecking the heap...");
writeln("Before: " <& time(NOW));
idx := 1;
while length(aHeap) > 0 do
heapValue := getFirst(aHeap);
#The value retrieved from the heap is an integer and needs NOT to be converted
correct := correct and idx <= MAX and heapValue = checkArr[idx];
incr(idx);
end while;
writeln("After: " <& time(NOW));
if correct then
writeln("Test result correct!");
else
writeln("Test result incorrect!");
end if;
end func;
---------- end test19x.s7i ----------
I hope that this is what you searched for.
Regards
Thomas
|
|
From: Thomas M. <tho...@gm...> - 2022-04-02 22:39:46
|
Hi Anders,
You wrote:
> I get a raise RANGE_ERROR when running the time-function in seed7 program.
> As I remember I did not get this error in the previous versions.
> Is this something which has been changed with the new version 2022-03-12?
> See the attached testprogram.
This is the attached test program:
---------- begin test21.sd7 ----------
$ include "seed7_05.s7i";
include "time.s7i";
const proc: main is func
local
var time: aTime is time.value;
var string: aStr is string.value;
begin
aStr := str(time(NOW));
writeln(aStr);
aTime := time(aStr);
writeln(str(aTime));
end func;
---------- end test21.sd7 ----------
Running test21.sd7 leads to:
C:\seed7\myprg\Test>s7 test21
SEED7 INTERPRETER Version 5.1.621 Copyright (c) 1990-2021 Thomas Mertes
2022-04-02 06:13:20.211221 UTC+2 (DST)
*** Uncaught exception RANGE_ERROR raised with
{raise RANGE_ERROR }
Stack:
in time (in varstring: stri) at /c/seed7/lib/time.s7i(360)
in main at test21.sd7(11)
C:\seed7\myprg\Test>
I can confirm that I also get this RANGE_ERROR and this should not happen.
The RANGE_ERROR is triggered because the date string ends with " (DST)".
DST means daylight saving time. In "2022-04-02 06:13:20.211221 UTC+2 (DST)"
the ending UTC+2 (DST) refers to Middle european summer time.
The error is: The function time (string) does not check for " (DST)".
Instead it raises RANGE_ERROR. With "2022-04-02 06:13:20.211221 UTC+2"
it would work correclty. So the summertime introduced this error.
The fix is: I changed time (string) to consider the " (DST)".
You can find this fix at GitHub ( https://github.com/ThomasMertes/seed7 ).
The change in time.s7i is:
end if;
end if;
end if;
+ if stri = " (DST)" then
+ aTime.daylightSavingTime := TRUE;
+ stri := "";
+ end if;
end if;
- aTime.daylightSavingTime := FALSE;
if stri <> "" then
raise RANGE_ERROR;
end if;
I hope this helps.
Regards
Thomas
|
|
From: Thomas M. <tho...@gm...> - 2022-02-22 18:59:07
|
Hi Zachary, Thank you for the fix of fwd.x11.c. I have already updated Seed7 at GitHub (see: https://github.com/ThomasMertes/seed7 ). The next release will contain this fix also. Btw. fwd_x11.c is only used if linking with the X11 library fails. This is recognized by chkccomp.c. In this case it is assumed that a X11 shared object library is available at run-time. Regards Thomas |
|
From: Zaakari <Za...@pr...> - 2022-02-01 02:47:08
|
Hey Thomas, Thanks for those new arc() functions! Also--as you'll probably notice soon yourself--there are two typos in the fwd_x11.c file that caused the "make" process to fail. It's just two little things. It was simple enough to fix them for my own build; but I've attached a file containing the error messages from gcc if you want to see them. |
|
From: Zaakari <Za...@pr...> - 2022-01-06 02:14:41
|
Hey Thomas, Would you be able to add a function similar to arc() (within draw.s7i library) but with the addition of a thickness parameter? Or do the underlying graphics libraries not support this? Points can be expanded by drawing filled circles; and lines can be expanded by drawing filled polygons; but--apart from calculating every pixel--I don't know of a way to "expand" arcs. Zachary |
|
From: Zaakari <Za...@pr...> - 2021-12-18 14:07:24
|
Ah, clipping, yes that's a better idea. I guess it would take about 10 4K monitors before that number would be insufficient. I guess I can get a little too focused on one method. Thanks for the suggestion, Zachary |
|
From: Thomas M. <tho...@gm...> - 2021-12-15 13:58:24
|
Hi Zachary,
you guessed it. It is a limitation of the underlying X11 function XDrawLines().
XDrawLines() uses an array of XPoint elements. Unfortunately an XPoint is
defined as
typedef struct {
short x, y;
} XPoint;
Therefore the function genPointList() needs to raise RANGE_ERROR, when
a coordinate does not fit into a short.
You are magnifying the scene such that coordinates greater than 32767 are
computed. Such large values will probably never been drawn as they are beyond
the normal size of a window.
I suggest you use your own data structure to do the magnification and generate
the point list just when it is needed. In this case the values could be limited.
You could use 32767 for all values greater than 32767 and -32768 for all
values less than -32768. Since this probably far beyond the window borders
your magnification probably looks ok.
You must also consider the coordinates you use with polyLine(), when the
lines are drawn. These coordinates need also to be in the range of a short.
Regards
Thomas
|
|
From: Zaakari <Za...@pr...> - 2021-12-14 20:46:11
|
Hey Thomas, I ran across what seems to be a bug (or, perhaps, just an oversight) with the "genPointList" function in the "graph.s7i" library. For some reason, when I pass values in that are higher than 32767, then it throws a range error. Are these getting bound to small integers, perhaps? I'm using this function within "fpolyLine" to draw slanted rectangles, and need to be able to pass in large values in order to support magnifying the scene they are drawn in. Is there a way to draw a filled polygon without using "genPointList", or could it be modified to accept the full range of integers? It's probably not needed, but I attached a short script as an example to reproduce the issue. It contains some commented-out sections that show the path I took to get to the error, but the last (uncommented) section shows the issue most plainly. Thanks, Zachary |
|
From: Cleverson <cl...@di...> - 2021-11-20 18:29:13
|
Hi, I forgot to answer what I know about Linux as you asked earlier. There appears not to be a default solution for sound playing in Linux, at least judging by the solutions they implemented for this Rosetta Code's task, where they use a command line tool instead of an API: http://rosettacode.org/wiki/Play_recorded_sounds Greetings Cleverson Em 20/11/2021 09:03, Cleverson escreveu: > Hi Thomas, thanks for your kind answer. My intention in principle is to > use PlaySound, see: > https://docs.microsoft.com/en-us/windows/win32/multimedia/the-playsound-function > > Usually, it comes defined in a header called mmsystem.h (or mmsystem.pas > in a FreePascal / Delphi installation). > > thanks for pointing me to Seed7's foreign interface; I'll try figuring > it out. > > Greetings,, > Cleverson > > > _______________________________________________ > Seed7-users mailing list > See...@li... > https://lists.sourceforge.net/lists/listinfo/seed7-users |
|
From: Cleverson <cl...@di...> - 2021-11-20 12:03:53
|
Hi Thomas, thanks for your kind answer. My intention in principle is to use PlaySound, see: https://docs.microsoft.com/en-us/windows/win32/multimedia/the-playsound-function Usually, it comes defined in a header called mmsystem.h (or mmsystem.pas in a FreePascal / Delphi installation). thanks for pointing me to Seed7's foreign interface; I'll try figuring it out. Greetings,, Cleverson |
|
From: Thomas M. <tho...@gm...> - 2021-11-20 08:09:41
|
Hi Cleverson, with sound you hit an interesting area. As you already found out the standard lib does not implement sound. I planned to do a sound lib, but up to now I did not take the time to implement it. The lunar lander (see: http://seed7.sourceforge.net/scrshots/lander.htm ) has something prepared to send frequencies and durations to some sound system. I have some questions: Which sound API functions from Windows do you want to use? Is there a similar sound API under Linux or other Unix systems? Could a combined Windows/Linux sound API be created from it? Seed7 tries to achieve portability between operating systems. For that reason direct calls from an application program to OS API functions are not desireable. To support portability something needs to balance the differences. In the end driver libraries for Windows and Linux (UNIX, BSD, MacOS) would be needed. That said nothing hinders you to write something for Windows. In the Seed7 manual there is a chapter about the foreign function interface (see: http://seed7.sourceforge.net/manual/ffi.htm ). In the first moment this looks complicated, but is not so complicated as it seems. Having sound for Windows could be a starting point. And it would be great if the same API can be supported from Linux in the future. I suggest using a file named snd_win.c for the Windows sound driver. The Linux/Unix one could use the name snd_unx.c. The common header for both APIs would be in snd_drv.h. Please be patient since I have no idea how a sound API looks today. Greetings Thomas |
|
From: Cleverson <cl...@di...> - 2021-11-20 02:35:18
|
Hi, I'm new to the language, apreciating it so far. How easy is it to do basic audio playing / stoping, especially under Windows? Since the standard lib appears not to implement this, is it possible to e.g. call OS API functions directly? Greetings, Cleverson |
|
From: Thomas M. <tho...@gm...> - 2021-11-14 08:51:14
|
Hi Zachary
In your example the two occurrences of 'array array string' are considered as
two different types. This triggers the error. If you introduce a named type
for the two dimensional array the error vanishes:
const type: stringArray2D is array array string;
const func stringArray2D: test_multiplication (in string: value) is func
result
var stringArray2D: data is 0 times 0 times "";
begin
data := 3 times 2 times value;
end func;
You are right that this happens with all types of multi-dimensional arrays.
Declaring a named type helps in all these situations.
I also added an explanation to the FAQ at
http://seed7.sourceforge.net/faq.htm#two_dimensional_array .
I hope this helps
Regards Thomas
|
|
From: Duke N. <sid...@gm...> - 2021-11-13 20:15:25
|
On Sat, 13 Nov 2021 19:36:50 +0100 Thomas Mertes <tho...@gm...> wrote: > Hi Duke, > > In your code are line breaks in strings. But this > was easy to fix. I can reproduce a RANGE_ERROR when I > enter aa in response to the question [snip] Before my first post about my difficulty with the code, I was trying to run the temperature converter program from within the jEdit editor. I just now ran my code from a Linux terminal and it works just fine without any modification. So I must have done something correctly. :) Sorry for all the botherand thanks for your time!! -- Duke |
|
From: Thomas M. <tho...@gm...> - 2021-11-13 18:37:04
|
Hi Duke,
In your code are line breaks in strings. But this
was easy to fix. I can reproduce a RANGE_ERROR when I
enter aa in response to the question
Enter your choice
With aa I get the stack trace:
*** Uncaught exception RANGE_ERROR raised with
{raise RANGE_ERROR }
Stack:
in raise (ref EXCEPTION: anException) at seed7_05.s7i(323)
in (attr type) parse (ref string: stri) at seed7_05.s7i(463)
in readln (inout file: inFile, inout char: aVar) at enable_io.s7i(102)
in readln (inout char: aVar) at enable_io.s7i(170)
in main at tst303.sd7(27)
The function readln() (in enable_io.s7i(102)) has read the string
"aa" and then tries to convert it into a character and this
triggers a RANGE_ERROR (in seed7_05.s7i(463)).
This can be avoided by reading single characters from the KEYBOARD.
See below for the improved example.
A RANGE_ERROR could also be triggered when no number is entered for
readln(temp);
This situation can be recognized with the function
succeeds(readln(temp))
The function succeeds() returns TRUE when no exception occurred.
If an exception occurred it is caught and the function returns
FALSE.
I suggest the following fix:
[code]
$ include "seed7_05.s7i";
include "float.s7i";
include "console.s7i";
include "editline.s7i";
const func float: fahr2cels (in float: temp) is
return 0.5556 * (temp - 32.0);
const func float: cels2fahr (in float: temp) is
return (temp * 1.8) + 32.0;
const proc: main is func
local
var float: temp is 0.0;
var char: choice is ' ';
var text: console is STD_NULL;
begin
OUT := open(CONSOLE);
IN := openEditLine(KEYBOARD, OUT);
clear(STD_CONSOLE);
while choice <> 'q' do
writeln("\nTemperature Conversion Utility");
writeln("------------------------------");
writeln("a - Fahrenheit TO Celsius");
writeln("b - Celsius TO Fahrenheit");
writeln("q - To exit the program");
write("Enter your choice ");
choice := getc(KEYBOARD);
writeln(choice);
case choice of
when {'a'}:
write("Enter a number to convert ");
if succeeds(readln(temp)) then
writeln("\nYour input was " <& temp <& " degrees Fahrenheit!");
write("That's " <& fahr2cels(temp) <& " degrees Celsius!");
else
writeln("\nThis is not a number.");
end if;
write("\nPress any key to continue ..");
readln;
clear(STD_CONSOLE);
when {'b'}:
write("Enter a number to convert ");
if succeeds(readln(temp)) then
writeln("Your input was " <& temp <& " degrees Fahrenheit!");
write("That's " <& cels2fahr(temp) <& " degrees Celsius!");
else
writeln("\nThis is not a number.");
end if;
writeln("\nPress any key to continue ..");
readln;
clear(STD_CONSOLE);
when {'q'}:
writeln("Good bye!");
writeln("\nPress any key to continue ..");
readln;
otherwise:
writeln("Sorry! Invalid choice!");
writeln("\nPress any key to continue ..");
readln;
clear(STD_CONSOLE);
end case;
end while;
end func;
[/code]
Regards Thomas
|
|
From: Zaakari <Za...@pr...> - 2021-11-13 16:54:46
|
Hey Thomas, I ran into a strange error today: when I make a function to return a 2-dimensional string array, seed7 throws a "Match for ... failed" error. I can make local multi-dimensional arrays without issue, it's just when I try to use them as the result of a function that an error is raised. I'm guessing this happens with all types of multi-dimensional arrays--though I only tested string and integer arrays. I've attached an example program in which I have a local 2-dimensional string array that I loop through, echoing its contents. But if you un-comment the "test_multiplication" function then the program throws the error. I feel like I must be doing something wrong. But if so, I can't see what it is. If you would take a look at this, that would be great. Thanks, Zachary |
|
From: Duke N. <sid...@gm...> - 2021-11-13 14:23:49
|
This is my first ever Seed7 program! I can't seem to find the bug
in the code. Line 30 I think is the problem, but why?
*** Uncaught exception RANGE_ERROR raised with
{raise RANGE_ERROR }
Stack:
in raise (ref EXCEPTION: anException)
at /home/dnormandin/git/seed7/s(323) in (attr ) (ref : ) at (463)
in (inout : , inout : ) at (102)
in (inout : ) at (170)
in at (31)
Process s7 exited with code 0
[code]
$ include "seed7_05.s7i";
$ include "complex.s7i";
$ include "char.s7i";
$ include "console.s7i";
const func float: fahr2cels (in float: temp) is
return 0.5556 * (temp - 32.0);
const func float: cels2fahr (in float: temp) is
return (temp * 1.8) + 32.0;
const proc: main is func
local
var float: temp is 0.0;
var char: choice is ' ';
var text: console is STD_NULL;
begin
console := open(CONSOLE);
clear(console);
while choice <> 'q' do
writeln("\nTemperature Conversion Utility");
writeln("------------------------------");
writeln("a - Fahrenheit TO Celsius");
writeln("b - Celsius TO Fahrenheit");
writeln("q - To exit the program");
write("Enter your choice ");
readln(choice);
case choice of
when {'a'}:
write("Enter a number to convert ");
readln(temp);
writeln("\nYour input was " <& temp <& " degrees
Fahrenheit!");
write("That's " <& fahr2cels(temp) <& " degrees
Celsius!");
write("\nPress any key to continue ..");
readln;
clear(console);
when {'b'}:
write("Enter a number to convert ");
readln(temp);
writeln("Your input was " <& temp <& " degrees
Fahrenheit!");
write("That's " <& cels2fahr(temp) <& " degrees
Celsius!");
writeln("\nPress any key to continue ..");
readln;
clear(console);
when {'q'}:
writeln("Good bye!");
writeln("\nPress any key to continue ..");
readln;
otherwise:
writeln("Sorry! Invalid choice!");
writeln("\nPress any key to continue ..");
readln;
clear(console);
end case;
end while;
end func;
[/code]
--
Duke Normandin <sid...@gm...>
|
|
From: Duke N. <sid...@gm...> - 2021-11-12 20:28:10
|
On Fri, 12 Nov 2021 21:20:17 +0100 Thomas Mertes <tho...@gm...> wrote: > There are two things that use the keyword 'func'. > > 1. There are types like 'func integer' or 'func boolean'. > 2. There is the 'func ... begin ... end func' construct. [snip the rest of the Good Stuff] > I hope this helps. Thanks! I'm sure that it will once I digest the different nuances. -- Duke |
|
From: Thomas M. <tho...@gm...> - 2021-11-12 20:20:25
|
There are two things that use the keyword 'func'.
1. There are types like 'func integer' or 'func boolean'.
2. There is the 'func ... begin ... end func' construct.
The type 'proc' is defined as 'func void'. The type 'void'
describes that there is no value. In fact 'void' has a value,
but there is just one value: 'empty'. So the type 'func void'
aka 'proc' means: A function that returns nothing. In Pascal
and other languages this is called procedure. In Seed7 the
name function refers also to procedures as they are functions
that return 'void'.
The 'func ... begin ... end func' construct comes in several
variants.
An example of a procedure declarations is:
const proc: main is func
begin
writeln("hello world");
end func;
The 'func ... begin ... end func' construct is used to initialize
the 'main' procedure.
A variant of this func construct is used to define a procedure
with local variables. E.g.:
const proc: main is func
local
var integer: number is 0;
begin
for number range 10 downto 0 do
writeln(number);
end for;
end func;
Functions (that do not return void) are initialized with
another variant of the construct:
'func result ... begin ... end func'.
const func string: foo is func
result
var string: stri is "";
begin
for 3 do
stri &:= rand('a', 'z');
end for;
end func;
A function with a local variable is:
const func string: bar is func
result
var string: stri is "";
local
var integer: number is 0;
begin
for number range 1 to rand(1, 10) do
stri &:= str(number);
end for;
end func;
So 'func begin ...' and 'func local ...' are used to
define procedures (aka proc).
And 'func result ...' is used to define functions (except
func void aka proc).
As you figured out the 'func ...' construct is overloaded.
There is another way to define a function. This way is
used when an expression can describe the function body:
const func integer: random10 is
return rand(1, 10);
I hope this helps.
Regards Thomas
|
|
From: Duke N. <sid...@gm...> - 2021-11-12 19:02:18
|
I'm totally confused with Seed7's use of "func".
In other languages - pascal, oberon2, modula2 etc - a procedure
DOES something, but returns nothing.
On the other hand, a function can return a value, and sometimes
modify an existing value.
Seed7 appears to overload the term "func" to mean:
- a function declaration, and
- begin ... end or { ... }
Is that correct?
Are procedures and functions specifically explained somewhere? I
could not find it in the manual OR the tutorial. I had to go to
rosettacode.org for a simple explanation of a seed7 function
construct. However, there was nothing there about how to properly
write a seed7 procedure. TIA ...
--
Duke Normandin <sid...@gm...>
|
|
From: Duke N. <sid...@gm...> - 2021-11-12 14:27:14
|
On Fri, 12 Nov 2021 09:23:00 +0100 Thomas Mertes <tho...@gm...> wrote: > Hi Duke, > > Welcome to Seed7. > Sorry for the delay. The motherboard of my main computer broke > down and it was necessary to get a replacement. I understand! Thank you for your point-by-point replies! All very helpful. Now that I know that the list is still active, I'll continue learning Seed7. So far, it has been a lot of fun. -- Duke |
|
From: Thomas M. <tho...@gm...> - 2021-11-12 08:25:54
|
Hi Duke,
Welcome to Seed7.
Sorry for the delay. The motherboard of my main computer broke down
and it was necessary to get a replacement.
Regarding editor recommendations:
Up to now there is neither an Emacs mode nor a jEdit syntax file
for Seed7.
The following things might be used as inspiration:
Renato Lenzi wrote a wordfile for Ultraedit (see: doc/seed7.uew)
and a syntax definition file for Textpad (see: doc/seed7.syn).
The script to create the Seed7 Homepage uses the following
definitions to do the syntax highliting:
keywordList:
"begin", "case", "const", "do", "downto", "else",
"elsif", "end", "enum", "for", "forward", "func",
"if", "in", "include", "inout", "is", "local",
"new", "of", "otherwise", "param", "range", "ref",
"repeat", "return", "struct", "sub", "syntax", "system",
"then", "to", "until", "val", "var", "when",
"while"
operatorList:
"and", "conv", "digits", "div", "exp", "in",
"lpad", "lpad0", "mdiv", "mod", "mult", "not",
"or", "parse", "rem", "rpad", "sci", "times",
"varConv"
abstractTypeList:
"array", "func", "hash", "set", "varfunc"
typeList:
"bigInteger", "bigRational", "bitset", "boolean", "char",
"clib_file", "color", "complex", "duration", "expr",
"file", "float", "integer", "object", "proc",
"program", "rational", "reference", "ref_list", "string",
"text", "time", "type", "void",
"PRIMITIVE_WINDOW"
Regarding the jEdit seed7 mode:
Great that you created a jEdit syntax highlighting mode for seed7.
It would ge great to add your jEdit syntax file to the Seed7
release (if it is licensed as open source).
You asked what programming language does resemble the seed7 syntax
most. I would suggest Ada, Modula 2, or Pascal.
Regarding Function Declarations:
Seed7 functions must be declared before they can be used. So
functions must be declared before main() or some other function uses
them.
Yes, there is something similar to prototyping like in C. If it is
not possible to declare a function (e.g. two functions calling
each other) a function can be declared forward:
const proc: syncFile (in string: sourcePath, in string: destPath,
in syncFlags: flags) is forward;
You can see that the keyword forward is used instead of the
function body. After the forward declaration syncFile() can be
used by another function (e.g. in the function syncDir):
syncFile(sourcePath & "/" & sourceName,
destPath & "/" & destName, flags);
Of course, later the real declaration of syncFile() needs to be
done.
Regarding your October posts:
Your October post have not been nuked. I was just too busy
with other things. Sorry for the inconveniance again.
Regards Thomas
|
|
From: Duke N. <sid...@gm...> - 2021-11-11 21:17:43
|
Have they cleared the moderator review yet? Or have they been nuked? -- Duke -- Duke Normandin <sid...@gm...> |
|
From: Thomas M. <tho...@gm...> - 2021-11-07 13:32:45
|
Hi Anders, Sorry for the delay. The motherboard of my main computer broke down and it was necessary to get a replacement. You wrote: > I have a new question which is about writing to different windows. > To illustrate this I have created a small test program (test9.sd7), > which is appended below. > The program opens a window which is the curr_win window. By pressing > F1 a second window is opened named testWindow. When pressing F1 in > the second window it is supposed to write the string "Test", but > instead of writing it in testWindow it is written in the curr_win > window. This confuses me since when I check the "openPixmapFontFile" > function it sets the specified window (testwindow) as the destination > window. Also I am a bit confused about the write-function for the > pixmap font file. > So my question is how is this working? and How should one do this? You discovered an error in pixmap_file.s7i. Several functions were drawing to curr_win instead of fontFile.win. I just checked in the fix to GitHub (see https://github.com/ThomasMertes/seed7). The next release will contain this fix also. Thank you for reporting the bug. Regards Thomas |
|
From: Duke N. <sid...@gm...> - 2021-10-11 20:00:34
|
Please - do they need to be "prototyped" like in C? Must they be declared before "main"? TIA ... -- Duke |