# [racket] [bug?] Racklog cut differs from Prolog cut

 From: Matthias Felleisen (matthias at ccs.neu.edu) Date: Mon Aug 13 14:48:20 EDT 2012 Previous message: [racket] [bug?] Racklog cut differs from Prolog cut Next message: [racket] [bug?] Racklog cut differs from Prolog cut Messages sorted by: [date] [thread] [subject] [author]

```The Prolog program looks like this (alpha renamed):

a(X) :- b(X).
a(Z) :- c(Z).
b(1) :- !.
b(2).
c(2).

1. a(Y) unifies with [the head of] the first line, which gives us Y = X, and b(Y) as the goal.
2. b(Y) unifies with the third line, which gives us Y = 1.
3. Solution found: 1
4. Reject solution.
5. Backtracking on b fails due to prompt.
6. Backtrack on 2 and therefore on 1.
7. a(Y) unifies with the second line, which once again gives us Y = Z and c(Y) as the goal.
8. c(Y) unifies with the fourth line, which yields Y = 2.

A cut is an exit continuation to the current relation that undoes local bindings.

-- Matthias

On Aug 13, 2012, at 2:15 PM, Jay McCarthy wrote:

> Can you help me understand this example and why x should be 2? My
> understanding of cut and prolog is that this should happen:
>
> a(X)                [X = _ ]
> ---->
> b(X) ; c(X)       [ X = _ ]
> ---->
> b(1) ; b(2); c(X) [ X = _ ]
> ---->
> X = 1; ! ; b(2) ; c(X)    [ X = _ ]
> ---->
> ! ; b(2) ; c(X)              [ X = 1 ]
>
> ! evaluates to succeed and then we get the X = 1 solution.
>
> But because we cut, the change to the X logic variable won't be
> undone, so when we try we get to...
>
> b(2) ; c(X)
> ----->
> 1 = 2 ; c(X)
> ---->
> fail ; c(X)
> ---->
> c(X)
> ---->
> c(2)
> ----->
> 1 = 2
> ---->
> fail
>
> and never see that X = 2
>
> I must be wrong because you show that prologs actually give 2, but
> could you help me see why?
>
> Jay
>
> On Sat, Aug 11, 2012 at 11:32 PM, Erik Dominikus
> <erik.dominikus71 at gmail.com> wrote:
>> Racket version:
>>
>> 5.2.
>>
>> Output of 'uname -a':
>>
>> Linux kire 2.6.32-41-generic #91-Ubuntu SMP Wed Jun 13 11:43:55 UTC 2012
>> x86_64 GNU/Linux
>>
>> Symptom:
>>
>> In SWI Prolog (or any Prolog interpreter I think), querying a(X) gives
>> X=1 and X=2. Racklog only gives x=1.
>>
>> How to reproduce:
>>
>> Run 'prolog -f a.pl' (if using SWI Prolog).
>> Enter 'a(X).'.
>> Press ';' (semicolon) key until it prints false.
>>
>> Run 'racket a.rkt'.
>>
>> Expectation:
>>
>> Racklog gives x=1 and x=2.
>>
>>
>> Thank you.
>>
>> ____________________
>>  Racket Users list:
>>  http://lists.racket-lang.org/users
>>
>
>
>
> --
> Jay McCarthy <jay at cs.byu.edu>
> Assistant Professor / Brigham Young University
> http://faculty.cs.byu.edu/~jay
>
> "The glory of God is Intelligence" - D&C 93
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4373 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20120813/eb772360/attachment.p7s>
```

 Posted on the users mailing list. Previous message: [racket] [bug?] Racklog cut differs from Prolog cut Next message: [racket] [bug?] Racklog cut differs from Prolog cut Messages sorted by: [date] [thread] [subject] [author]