Hi,

To implement this I have used a Cell ("FoundWord", marked *** below), assigned initially to "false", which is set to "true", if the first branch succeeds, hoping that it could be used as a guard, to prevent the second choice.

Trouble is, it doesn't work. All the rest of the parser works fine, but "FoundWord" always seems to be "false" when accessed in the second choice, even if it certain that it has been previously assigned true.

Which makes me realise that I have completely failed to understand something, probably to do with the scoping, but my logic might be wrong, too, who knows...

Yes, the cell's value is logically "backtracked" as well as everything else when you reach the second choice. This is because "choice" creates computational spaces, try reading chapter 12 of the language tutorial.

Here's the basic code:

proc {Encode NumberStr Words PrevIsNum}
    First Rest Word WList CurrIsNum
    FoundWord = {NewCell false} % <---- ***
in
    choice
        NumberStr = nil
        Words = nil
    []
        Words = Word|WList
{Splitter First Rest NumberStr} % NonDet - Works like a kind of backward append/3 choice %% NonDet - "Corresp" is based on member/2 and checks a dict
            {Corresp First Word}
            CurrIsNum = false
            {Assign FoundWord true} % <---- ***
        []
            % there was no word, use the single digit
            {Length First 1}
            % check that we are not following a digit
            PrevIsNum = false
            {Access FoundWord false} % <---- ***
            First = Word
            CurrIsNum = true
        end
        {Encode Rest WList CurrIsNum}  % Recursive Call
    end
end

What about this:

 proc {Encode NumberStr Words PrevIsNum}
     First Rest Word WList CurrIsNum
     FoundWord
 in
     choice
         NumberStr = nil
         Words = nil
     []
         Words = Word|WList
         {Splitter First Rest NumberStr}
         choice
             {Corresp First Word}
             CurrIsNum = false
             FoundWord=true
         []
             FoundWord=false
         end
         if {Not FoundWord} then
             % there was no word, use the single digit
             {Length First 1}
             % check that we are not following a digit
             PrevIsNum = false
             First = Word
             CurrIsNum = true
         end
         {Encode Rest WList CurrIsNum}  % Recursive Call
     end
 end

I hope I didn't screw it up :-)

Cheers,
Filip
_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to