Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsfeed.cit.cornell.edu!newsstand.cit.cornell.edu!news.kei.com!newsfeed.internetmci.com!btnet!news.compulink.co.uk!cix.compulink.co.uk!usenet
From: alanw@cix.compulink.co.uk ("Alan Westwood")
Subject: Re: HELP: Emulating soft cut
Message-ID: <DHzMqA.E7K@cix.compulink.co.uk>
Organization: Compulink Information eXchange
References: <47q8s9INN2a5@bhars12c.bnr.co.uk>
Date: Mon, 13 Nov 1995 15:22:58 GMT
X-News-Software: Ameol
Lines: 44

J.S.Fletcher writes:

>I have program which must run on a standard commercial PC Prolog - so 
both
>space and speed are important. The 'top level' of the program has the 
form:

>% assimilate( +Inputs, +State0, -State1 ) where State1 is the result of
applying
>% Inputs to State0.

>assimilate( [], State, State ).
>assimilate( [Input|Inputs0], State0, State1 ):-
>       transition_without_change( Input, State0, Results ),
>       merge( Results, Inputs0, Inputs1 ),
>       assimilate( Inputs1, State0, State1 ).
>assimilate( [Input|Inputs0], State0, State1 ):-
>       \+ transition_without_change( Input, State0, _Results ),
>       transition_with_change( Input, State0, State2, Results ),
>       merge( Results, Inputs0, Inputs1 ),
>       assimilate( Inputs1, State2, State1 ).


If transition_without_change/3 is too expensive, how about reversing the 
test? Otherwise, you will have to restructure your program.

assimilate_1( [], State, State ).

assimilate_1( [Input|Inputs0], State0, State1 ):-
        \+ transition_with_change( Input, State0, _, _ ),
        !,
        transition_without_change( Input, State0, Results ),
        merge( Results, Inputs0, Inputs1 ),
        assimilate_1( Inputs1, State0, State1 ).

assimilate_1( [Input|Inputs0], State0, State1 ):-
        transition_with_change( Input, State0, State2, Results ),
        merge( Results, Inputs0, Inputs1 ),
        assimilate_1( Inputs1, State2, State1 ).

regards,
Alan Westwood
Software Engineer
LPA Ltd.
