bertrand@eiffel.UUCP (Bertrand Meyer) (03/09/89)
I received the following message by mail, with a mention that it was meant for posting but did not leave Europe. It seems appropriate to repost it. Apologies to any reader who as a consequence will see the message twice (or more...). I may post a response later. Bertrand Meyer bertrand@eiffel.com ------------ BEGIN REPOSTED MESSAGE ------------------------- Hi, this was posted in comp.lang.eiffel, but there seems that it didn't leave Europe. So I decided to send it to you. Here's the text : We are just beginning to use Eiffel and are confronted with some problems. One of them is the following : We would like to apply routines on sets of objects, but there seems to have problems with types. Here is an example (let us suppose that our set is implemented as a list, and the routine that we want to distribute is like a "procedure") : class A feature set_do_all (action : X) is do from set.start until set.offright loop set.value.action; set.forth; end; end ; -- set_do_all end; -- class A Our problem here is to determine what is X (the type of action). Is there a type "routine" ? If not, we cannot define such a routine. A second problem resides in our need to share objects between two Eiffel process via UNIX sockets. Champ-de-Mars tells that, in release 2.2, the routine Out will permit to flatten an object, i.e. to transform it into a string. So, we can send it to the second process via a socket. How can we recuperate an object at the other side (i.e. to "unflatten" it) ? Perhaps, these questions are not relevant. But can anyone help us ? Any information would be appreciable. Thanks in advance. My electronic address : ...!mcvax!inria!cnetlu!cornily My postal address : Jean-Michel Cornily CNET LAA/SLC/LCM Route de Tregastel 22300 Lannion FRANCE You can reply by mail or news in comp.lang.eiffel By the way, we'd like to know the electronic ou postal address of a French Eiffel users in French Navy : Mr J. Rousselot and M. Larignon. We saw in Champ-de-Mars that they built a real-time graphical simulation application. Maybe, they could help us in the use of graphical classes. Thank you. ------------ BEGIN REPOSTED MESSAGE -------------------------
florman@randvax.UUCP (Bruce Florman) (03/11/89)
In article <112@eiffel.UUCP> Jean-Michel Cornily writes: >We are just beginning to use Eiffel and are confronted with some >problems. One of them is the following : >We would like to apply routines on sets of objects, but there seems to >have problems with types. Here is an example (let us suppose that our >set is implemented as a list, and the routine that we want to distribute >is like a "procedure") : > >class A >feature > > set_do_all (action : X) is > do > from set.start > until set.offright > loop > set.value.action; > set.forth; > end; > end ; -- set_do_all > >end; -- class A > >Our problem here is to determine what is X (the type of action). Is there >a type "routine" ? If not, we cannot define such a routine. One way of doing this sort of thing is to create a class of objects which know how to be applied to other objects. This class would look something like the following (my apologies to anyone offended by my use of all caps for reserved words, but this terminal doesn't have a boldface key). CLASS INSTRUCTION [T] EXPORT apply_to FEATURE apply_to (target: T) IS REQUIRE NOT target.Void; DEFERRED END; END -- CLASS INSTRUCTION Using this class, we can now implement a set of objects that knows how to apply an instruction to all of its members. It would look something like this: CLASS SET [T] EXPORT apply_to_all INHERIT LINKED_LIST [T]; FEATURE apply_to_all (action: INSTRUCTION [T]) IS DO FROM start UNTIL offright LOOP action.apply_to(value); forth; END; END; END -- CLASS SET A drawback of this method is that you now have to create a new class for every instruction that you want to apply somewhere. However, such classes should be pretty small. For example, the following class knows how to call a string's left_adjust routine. CLASS LEFT_ADJUST_INSTRUCTION INHERIT INSTRUCTION [STRING] REDEFINE execute; FEATURE apply_to (target: STRING) IS REQUIRE NOT target.Void; DO target.left_adjust; END; END -- CLASS LEFT_ADJUST_INSTRUCTION To use this class, you would have to declare the following entities somewhere in your code. my_string_set: SET [STRING]; left_adjust: LEFT_ADJUST_INSTRUCTION; Now when the two Eiffel instructions below are executed, every string in my_string_set will become left adjusted. left_adjust.Create; my_string_set.apply_to_all(left_adjust); This is obviously quite a bit more verbose than it would be in languages which can pass procedural parameters (eg. Pascal), but it does accomplish what you wanted. Hope this helps, -Bruce Florman florman@rand-unix.ARPA
florman@randvax.UUCP (Bruce Florman) (03/11/89)
In article <1905@randvax.UUCP> florman@rand-unix.UUCP I write:
: CLASS LEFT_ADJUST_INSTRUCTION
: INHERIT
:
: INSTRUCTION [STRING]
: REDEFINE execute;
^^^^^^^
:
: FEATURE
:
: apply_to (target: STRING) IS
: REQUIRE
: NOT target.Void;
: DO
: target.left_adjust;
: END;
:
: END -- CLASS LEFT_ADJUST_INSTRUCTION
Of course the routine being redefined is named "apply_to" not "execute."
I guess I should have run this stuff through the compiler once before posting
it. Sorry about that.
-Bruce Florman