Only one class per file. The text of class PERSON goes to person.e
and the text of class APPLICATION goes to application.e.
When that done, the code will still not compile because it is not
void-safe. You will have to specify a creation procedure in class
PERSON. And you need a setter for `age`. And `main` needs to be
declared as creation procedure in APPLICATION. In the end you
should have that:
~~~~~~~
class PERSON
create
set_name
feature
name: STRING
age: INTEGER
set_name (new_name: STRING)
do
name := new_name
ensure
name_set: name = new_name
end
set_age (new_age: INTEGER)
require
new_age_not_negative: new_age >= 0
do
age := new_age
ensure
age_set: age = new_age
end
print_info
do
print ("Name: " + name + ", Age: " + age.out)
end
end
~~~~~~~
class APPLICATION
create
main
feature
main
local
p: PERSON
do
create p.set_name ("Alice")
p.set_age (30)
p.print_info
end
end
~~~~~~~
Then type: gec application.e
PS: It looks like the person who wrote this post on
https://programming.muthu.co has never programmed in
Eiffel. None of the examples will compile as is.
It might a good way to learn Eiffel though, trying to
fix the examples by understanding what the error
messages are complaining about.
--
Eric Bezault
mailto:
er...@gobosoft.com
http://www.gobosoft.com
On 09/12/2025 7:20, Claude “Duke” Normandin wrote:
> Reading:
https://programming.muthu.co/posts/beginners-guide-to-eiffel/
> #what-is-eiffel
>
> `gec' chokes on the following code with:
>
> *gec person.e
> Syntax error:
> line 21 column 1 in person.e*
>
> The code is copied right off the above article! What's going on? TIA ...
>
> /class MAIN
> ^
> feature/
> /class PERSON
> feature
> name: STRING
> age: INTEGER
> set_name (new_name: STRING)
> do
> name := new_name
> ensure
> name_set: name = new_name
> end
> print_info
> do
> print ("Name: " + name + ", Age: " + age.out)
> end
> end
> class APPLICATION
> feature
> main
> local
> p: PERSON
> do
> create p.set_name ("Alice")
> p.age := 30
> p.print_info
> end
> end/