Stepwise Refinement

new topic     » topic index » view thread      » older message » newer message

One feature I've not seen in many languages, but is occasionally useful, it
that of subfunctions that directly support stepwise refinement of routines.
Here's an example from the ABC language:

 HOW TO RETURN index doc:
    PUT {} IN where
    FOR line.no IN keys doc:
       TREAT LINE
    RETURN where
 TREAT LINE:
    FOR word IN split doc[line.no]:
       IF word not.in keys where:
         PUT {} IN where[word]
       INSERT line.no IN where[word]

Any language that thinks 'HOW TO RETURN' is better than 'FUNCTION' deserves
to die a quick death (as ABC did), but that's not the point here. The
support function TREAT LINE shares the local variables with the main
routine; it's *exactly* the same as:

 HOW TO RETURN index doc:
    PUT {} IN where
      FOR line.no IN keys doc:
      FOR word IN split doc[line.no]:
         IF word not.in keys where:
           PUT {} IN where[word]
         INSERT line.no IN where[word]
    RETURN where

Yes, I know the basic premise of Euphoria is to stay small, prevent feature
creep, and so on. On the other hand, there are quite a number of times when
routines have grown so large they are horribly bloated, but splitting them
up requires creating module variables or awkward forward references. For
example:

   procedure parse()
      if is("function") then  parse_function()
      elsif is("procedure") then parse_procedure()
      ...
      end if
   end procedure

The helper procedures here (parse_function, parse_procedure, etc) often need
to refer back to parse, which requires that it be a forward reference. In
fact, if often requires a host of forward references. In addition, since
these sorts of routines are often recursive, which makes the use of local
variables even more useful.

Since Python (the successor of ABC) doesn't include this sort of feature,
it's not clear that the author considered successive refinement a winning
feature. Still, I think it's worth considering adding to Euphoria.

-- David Cuny

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu