Ulf Wiger <>
Thu May 30 20:10:17 CEST 2002

On Thu, 30 May 2002, Alex Peake wrote:

>Forgive my lack of Erlang knowledge, but this all seems like a
>standard pattern of "Composition"?
>%%%% Compose functions
>compose([Fn]) ->
>	Fn;
>compose([Fn | FnTail]) ->
>	fun(Args) ->
>		apply(Fn,[apply(compose(FnTail),[Args])])
>	end.

That is certainly a pretty common pattern, but I don't think it
suffices to solve the problem that James refers to (and I have
complained about in previous postings.)

Just to take an example (perhaps not the best one, but rather one
that I could find in about 10 seconds):

scan_xml_decl("encoding" ++ T,
              S0 = #xmerl_scanner{event_fun = Event},
              Decl0 = #xmlDecl{attributes = Attrs}) ->
    %% [80] EncodingDecl
    {T1, S1} = scan_eq(T, S),
    {EncName, T2, S2} = scan_enc_name(T1, S1),
    Attr = #xmlAttribute{name = encoding,
                         parents = [{xml, XMLPos = 1}],
                         value = EncName},
    Decl = Decl0#xmlDecl{encoding = EncName,
                         attributes = [Attr|Attrs]},
    S3 = #xmerl_scanner{} =
      Event(#xmerl_event{event = ended,
                         line = S0#xmerl_scanner.line,
                         col = S0#xmerl_scanner.col,
                         data = Attr}, S2),
    scan_xml_decl(T2, S3, Decl).

This function, I think, reflects the nasty problems you can get
into with this style of programming. There are other functions in
the same module with greater complexity of numbered variables.
The suggestions so far don't offer a solution, as I see it. I
don't have one myself, other than (a) throwing it all out and
rewriting the code using a different programming model, or (b)
trying to live with the problem, carefully tracing by hand all
variable use in each funtion.

(Oh, if you're wondering where T and S came from, the
?bump_col(8) macro binds them (yes, ouch!))


Ulf Wiger, Senior Specialist,
   / / /   Architecture & Design of Carrier-Class Software
  / / /    Strategic Product & System Management
 / / /     Ericsson Telecom AB, ATM Multiservice Networks

More information about the erlang-questions mailing list