Re: [Seed7-users] Dynamic dispatch strange behaviour
Interpreter and compiler for the Seed7 programming language.
Brought to you by:
thomas_mertes
From: Thomas M. <tho...@gm...> - 2008-02-11 10:59:47
|
"Leonardo Cecchi" <leo...@gm...> wrote: > I was reading the new manual chapter (it's the chapter I was looking > for) I discovered a strange issue. > I don't know if it's a bug but I can't explain to myself the behaviour > of the following program: > > $ include "seed7_05.s7i"; > > const type: strangeInterface is new interface; > const func string: getNome(in strangeInterface param) is DYNAMIC; > > const type: astronave is new struct > var string: nome is ""; > end struct; > type_implements_interface(astronave, strangeInterface); > > const func astronave: astronave(in string: nome) is func > result > var astronave: result is astronave.value; > begin > result.nome := nome; > end func; > > const func string: getNome(in astronave: a1) is func > result > var string: result is ""; > begin > result:=a1.nome; > end func; > > const proc: main is func > local > var strangeInterface: enterprise is astronave("Enterprise galactica"); > begin > writeln("one"); > writeln("the name:" & getNome(enterprise)); > writeln("two"); > end func; As far as I can see you discovered a bug. It has to do with the initialisation of interface variables. When you change the 'main' program to const proc: main is func local var strangeInterface: enterprise is astronave("Enterprise galactica"); begin enterprise := astronave("Enterprise galactica"); writeln("one"); writeln("the name:" & getNome(enterprise)); writeln("two"); end func; it works (at least for me). Does it work for you? I have not investigated more about the bug than that. It is obvious that I need to revise the initialisation of interface variables. In the meantime it is necessary to assign a value with := to an interface variable. There is more to revise in this area: It can happen that several interface variables point to one implementation value. Since this is sometimes desired and sometimes not I may move to the use of an explicit 'new' function. What do you think? Greetings Thomas Mertes Seed7 Homepage: http://seed7.sourceforge.net Seed7 - The extensible programming language: User defined statements and operators, abstract data types, templates without special syntax, OO with interfaces and multiple dispatch. -- Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer |