If you replace
case X of Y then {Browse 'in pair'#X#Y} end
with simple unification
X = Y
to get
local A B
proc {Pair X Y}
X = Y
end
in
{Pair a A}
{Browse 1#A#B}
{Pair A b}
{Browse 2#A#B}
{Pair A B}
{Browse 3#A#B}
A = z
{Browse 4#A#B}
end
the output is
'in pair'#a#a1#a#_
followed by a tell a = b exception. This is what I would expect from straight unification.
But then I tried:
local A B
proc {Pair X Y}
{Browse 'before case'#X#Y}
case X of Y then {Browse 'after case'#X#Y} end
end
in
{Pair A b}
{Browse 1#A#B}
{Pair a A}
{Browse 2#A#B}
{Pair A B}
{Browse 3#A#B}
A = z
{Browse 4#A#B}
end
and got
'before case'#z#b'after case'#z#z1#z#_'before case'#a#z'after case'#a#a2#z#_'before case'#z#_'after case'#z#z3#z#_4#z#_
How did Y change from b to z between the first line and the second? Similar questions arise for the rest of the execution. How should this be understood? Or is there a bug somewhere in the implementation ?
-- Russ
_____________________________________________
Russ Abbott
Professor, Computer Science
California State University, Los Angeles
o Check out my blog at http://russabbott.blogspot.com/
Russ Abbott
Professor, Computer Science
California State University, Los Angeles
o Check out my blog at http://russabbott.blogspot.com/
On 9/26/05, Russ Abbott <[EMAIL PROTECTED]> wrote:
Here's an extension of the program below, which I admit has me completely confused.local A B
proc {Pair X Y}
case X of Y then {Browse 'in pair'#X#Y} end
end
in
{Pair a A}
{Browse 1#A#B}
{Pair A b}
{Browse 2#A#B}
{Pair A B}
{Browse 3#A#B}
A = z
{Browse 4#A#B}
endThe output is'in pair'#a#a1#z#_'in pair'#z#z2#z#_'in pair'#z#z3#z#_4#z#_
On 9/26/05, Russ Abbott <[EMAIL PROTECTED] > wrote:Well, I'll admit to being a bit mind twisted. (Actually I like that state.) I learned prolog about 2 decades ago and have not kept up with newer developments. I think in terms of Edinburgh prolog. I use setof/3, etc. (But I don't do asserts.) But I'm still not convinced that the way case is defined is the best approach.For example, on p 80 in CTM we see thatlocal <pattern> = <_expression_> in ... enddoes full unification even though it is not recommended to use it that way.Inlocal X in
case X of 3 then {Browse X} end
case 3 of X then {Browse X} end
endthe first of these suspends while the second succeeds. And inlocal A
proc {Pair X Y}
case X of Y then {Browse X#Y} end
end
in
{Pair 3 A}
{Pair A 3}
endboth succeed although they give different results: 3#3 and _#_ respectively! (Why didn't the second call not suspend, and since it didn't suspend, why didn't it bind Y to 3?)I still think the semantics of case should be re-analyzed.-- Russ
_____________________________________________
Russ Abbott
Professor, Computer Science
California State University, Los Angeles
o Check out my blog at http://russabbott.blogspot.com/
On 9/26/05, Raphael Collet <[EMAIL PROTECTED] > wrote:Russ Abbott wrote:
> One solution would be to have two versions of the case statement (case
> and caseunify), one that suspends if the pattern aribiter is not
> completely bound and one that does full unification.
No, this is definitely not a good idea. Prolog does pattern matching by
*speculative* unification! It works only because Prolog is *sequential*
and search is built-in.
Oz is concurrent, and search is encapsulated. The latter makes that we
don't need a "cut" statement in Oz. Unification is more the functional
style one.
> Not only would
> that offer a nice feature, it would solve the problem that new-comers
> tend to get confused about this. If both language features were
> presented together in the documentation, there would be no confusion.
Most newcomers are not from the Prolog world, and many find the "case"
statement quite natural. Prolog programmers are sometimes a bit
mind-twisted, and need some rehabilitation to normality ;-) I am sure
you will quickly get used to Oz.
Cheers,
raph
_________________________________________________________________________________
mozart-users mailing list [email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users
_________________________________________________________________________________ mozart-users mailing list [email protected] http://www.mozart-oz.org/mailman/listinfo/mozart-users
