Re: operation on module arguments




gottoomanyaccounts@xxxxxxxxx wrote:

Maybe I didn't describe very clearly. The relation of c to a and b is
of course supplied by me in the module which defines a, b, and c. If I
want c=a+b, then it is c=a+b, if I want c=a**b, then it should be
c=a**b. But the fact I understand is, even if I defined the relation in
the module, such as

module foo
real :: a, b, c

contains
subroutine getc
c = a + b
end subroutine getc
end module foo

Then in the main program, when a or b is modified, I still need to
explicitly
call getc
to update c. What I want is how I can write a module foo such that in
the main program, when a or b is modified, c is updated automatically,
so I can get rid of "call getc".
The original movitation is that, I have three variables a, b, and c.
The variables a and b are initially read from an external file, and get
changed later on in the main program, but the variable c is so closely
related to a and b, and it plays the same pole as a and b anywhere
else. Thus it is natural to declare a, b, and c in a module and their
relation in this module.
If the cocept of "module as a black box" really applies, then there
should be a mechanism to update c upon a and b just inside their host
module. If I have to manually update c=a+b outside the module, then I
won't bother to define c in module foo, instead I can declare it in the
main program, but this makes the main program less elegant because c is
so close to a and b and I really want put it the same place as a and
b............


I will just add a little bit redundant information below my post.

From Richard Maine and other people, I understand now there is no easy
way to do what I want. But the logic to have this feature in the
language is pretty reasonable, so I was not too greedy, was I ? :)

When "use module" appears in any program unit, compiler knows it at
compilation time. Then during execution time, whenever variables
defined in the module that has been used here are modified, the rest of
the variables defined in that same module should get updated
automatically, upon the relation also defined in the same module, if
that relation exists. Otherwise why we bother to "use module"? By "use"
it, we really want to use all information in there.

Does all of this even make sense to implement in the language? How many
people would appreciate this feature? :P

.



Relevant Pages

  • Re: operation on module arguments
    ... It's late and I may be a bit thick, but how are you supposed to specify what update ... end module foo ... end subroutine getc ... Thus it is natural to declare a, b, and c in a module and their ...
    (comp.lang.fortran)
  • Re: PLT Scheme Language Levels
    ... (module foo johanns-language ... Which begs a related question. ... The initial import defines the language that the module code will be ... to start itself from mzScheme? ...
    (comp.lang.scheme)