Re: [Seed7-users] Compile-time errors
Interpreter and compiler for the Seed7 programming language.
Brought to you by:
thomas_mertes
From: Thomas M. <tho...@gm...> - 2022-06-12 09:01:12
|
On Sat, 11 Jun 2022 07:04:00 +0200 Duke Normadin <dukeof...@gm...> wrote: > s7 sandbox.sd7 > SEED7 INTERPRETER Version 5.1.632 Copyright (c) 1990-2022 Thomas > Mertes *** sandbox.sd7(34):52: Match for {choice ::= "" } failed > end func; > -----------^ Unfortunately this error message refers to the wrong line (34) instead of the correct one (7). I will look into this issue. The error message actually refers to the line var char: choice is ""; where you try to initialize a char variable with a string literal. Char and string are different types so initializing a char with a string is not possible. The error message refers to the ::= operator that is never called explizit. The ::= operator is used only by declaration statements to initialize a variable or constant. To correct this error use var char: choice is ' '; instead. This initializes the char variable choice with the char literal ' '. > *** sandbox.sd7(34):32: Declaration of "choice" failed > end func; > -----------^ This is a follow up error of the previous one. > *** sandbox.sd7(19):52: Match for {choice getc } failed > getc(choice); The function getc has a file a parameter and returns a char. So getc cannot be used with a char parameter (choice). I suggest to use choice := getc(IN); instead. IN refers to the standard input file. > *** sandbox.sd7(34):32: Declaration of "main" failed > end func; > -----------^ This is a follow up error of all previous errors. > The error msgs are not very informative IMHO. I will try to look into that. > You have very detailed language specs, but > very few simple examples of everything possible. Newcomers to Seed7 > have to hut and search and dig for examples at the rosettacode > site. That is /not/ good advocacy! It's too bad that this is the > situation, because you might have a popular and productive language > if there was a comprehensive tutorial to learn it from. Thank you for the hint. I will try to improve the tutorial. Your example uses also 'break' which is not needed in Seed7 case statements. Below is my improved version of your example: ---------- begin sandbox.sd7 ---------- $ include "seed7_05.s7i"; $ include "float.s7i"; const proc: main is func local var char: choice is ' '; var integer: tempF is 0; var float: tempC is 0.0; begin writeln("Temperature Conversion Utitlity"); writeln("-------------------------------"); writeln("a - Fahrenheit TO Celsius"); writeln("b - Celsius TO Fahrenheit"); writeln("q - To exit the program"); writeln("Enter your choice"); choice := getc(IN); case choice of when {'a', 'A'}: writeln("choice is " <& choice); when {'b', 'B'}: writeln("choice is " <& choice); when {'q','Q'}: writeln("Goodye ..."); otherwise: writeln("Bad choice..."); end case; end func; ---------- end sandbox.sd7 ---------- I hope that helps. Regards Thomas |