Alex Gian wrote:
Sorry to post this again, I'll try keep it brief.
I have a choice statement inside a recursive parser "Encode"
implemented in the Prolog-inspired relational style of CTM, ch9.
Basically, what I need is that if the first choice succeeds at any
level of the parse, the second choice must not be attempted at that
level. (I know this is not concurrent or anything, but I'm just
trying to get the basics here! If you want to demonstrate the
concurrent approach/solution too, I won't complain!!!
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...
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
It is used, as expected by Solns =
{SearchAll proc{$ Ws} {Encode NumberStr Ws false} end}
For anyone more interested (the problem was originally a copmuting
challenge which I thought would look elegant in Oz) see my previous
post of 22/8/05 or
http://www.mozart-oz.org/pipermail/mozart-users/2005/006708.html
The program code is here: http://aegean.pwp.blueyonder.co.uk/store/tel.oz
Background:
http://web.archive.org/web/20030204013211/http://alvin.jpl.nasa.gov/gat/ftp/study.txt
TIA
Alex
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users
You could try with cond ... end or something similar (see chapter 12 of
tutorial). You can also write your own search engine (rather than using
SearchAll) which doesn't backtrack certain choice-points. Finally, if
you want to intermix state (cells) and spaces (search), you can use
Port.sendRecv but it's not an easy task.
Yves
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users