Re: OON: "Subclassing" algorithms

From: Konrad Hinsen (hinsen@ibs.ibs.fr)
Date: Fri Apr 25 1997 - 12:49:41 EST


First of all, thanks for all the replies to my question about
"inheriting" from algorithms. The solution that is closest to my
expectations is the function template parameter approach described by
Todd Veldhuizen, but it still falls short of what I think is necessary
in practice. For this approach to work, I must decide from the
beginning which parts of an algorithm I want to be able to replace. If
I want full flexibility, I must make each step a separate function,
with explicit parameter passing etc., which makes the code completely
unreadable.

What I am really looking for is something like a safer version of
conditional compilation via the C preprocessor. Something like the
following (using a fictitious language):

   function integrate(integrand, a, b, sample_points):
       step initialize:
          sum = 0
          delta = (b-a)/sample_points
       for i in [1..sample_points]:
          step evaluate:
             value = integrand(a+i*delta)
          step add:
             sum += value
       return sum

and then for example:

   function integrate_and_print<integrate>:
       step evaluate:
          x = a+i*delta
          value = integrand(x)
          print x, value

-- 
-------------------------------------------------------------------------------
Konrad Hinsen                          | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire   | Tel.: +33-4.76.88.99.28
Institut de Biologie Structurale       | Fax:  +33-4.76.88.54.94
41, av. des Martyrs                    | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France         | Nederlands/Francais
-------------------------------------------------------------------------------



This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 03:20:05 EST