Alexander Burger wrote:
Hi Cle,
Hi Alex,
(...)
But please note that there is one difference (or bug?) that Jon
Kleiser found out about two years ago, and which I could not
resolve:
Anonymous variables ('@' in Pilog, '_' in Prolog) may not work as
expected, when there is more than one of them in a complex rule,
with each in a different context.
I could not find a solution for that problem, and finally decided to
live with it. I hope this is acceptable.
urghs! This is a severe difference from Prolog. I would call it a bug
;-) But I do not know, if it is acceptable or if it comes into my way
and make me stumble.
But anyway, the most important thing is, to *know* about that
restriction! Then -- perhaps -- one can solve or work-around it ... so,
thank you for this hint!
Now coming to another problem, I am already fiddle for several hours
now. There is no Pilog 'retract'. So I decided to implement one. But I
would like it to have the same semantic as in Prolog. In Prolog,
'retract' will first try to match and bind a clause, and then remove
that clause from the database. Something like this:
foo(1).
foo(2).
foo(3).
retract(foo(N)), print(N), nl.
Would try to match the clause foo(N). Success with foo(1). Therefore N
would be bound to 1 and the clause foo(1) would be retracted.
For this, however, I would have to be able to pass a predicate to
'retract' execute it and retract afterwards.
If I try it interactively I can perform the operation like this:
(be foo (1))
(be foo (2))
(be foo (3))
(? (@CL list 'foo '(@N)) (equal (@P . (@A)) @CL) (call @P . @A) (@
retract (-> @CL))
Here the predicate I want to retract is the first one unifying with
'(foo @N)'. This should be the first one '(foo 1)'. So '@N' is bound to
'1' and the corresponding clause is retracted.
This works as I expect!
But I seem not to be able to get the code into another clause. I tried
it like this:
(be retract (@CL)
(equal (@P . (@A)) @CL)
(call @P . @A)
(@ retract (-> @CL)) )
But this does not work. If I try
(? (retract (foo (@N))))
'@N' got not bound to anything, an no fact was retracted. I have tried
several other implementations of 'retract' but I cannot get it to work.
So perhaps you can shed any light over me, what I do miss?
Thanks and ciao,
Cle.
--------------000509060708050706030409
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
<br>
Alexander Burger wrote:<br>
<span style="white-space: pre;">> Hi Cle,<br>
</span><br>
Hi Alex,<br>
<span style="white-space: pre;"><br>
(...)</span><br>
<br>
<span style="white-space: pre;">> But please note that there is one
difference (or bug?) that Jon<br>
> Kleiser found out about two years ago, and which I could not<br>
> resolve:<br>
> <br>
> Anonymous variables ('@' in Pilog, '_' in Prolog) may not work as <br>
> expected, when there is more than one of them in a complex rule,<br>
> with each in a different context.<br>
> <br>
> I could not find a solution for that problem, and finally decided
to <br>
> live with it. I hope this is acceptable.<br>
</span><br>
urghs! This is a severe difference from Prolog. I would call it a bug
;-) But I do not know, if it is acceptable or if it comes into my way
and make me stumble.<br>
<br>
But anyway, the most important thing is, to *know* about that
restriction! Then -- perhaps -- one can solve or work-around it ... so,
thank you for this hint!<br>
<br>
Now coming to another problem, I am already fiddle for several hours
now. There is no Pilog 'retract'. So I decided to implement one. But I
would like it to have the same semantic as in Prolog. In Prolog,
'retract' will first try to match and bind a clause, and then remove
that clause from the database. Something like this:<br>
<br>
foo(1).<br>
foo(2).<br>
foo(3).<br>
<br>
retract(foo(N)), print(N), nl.<br>
<br>
Would try to match the clause foo(N). Success with foo(1). Therefore N
would be bound to 1 and the clause foo(1) would be retracted.<br>
<br>
For this, however, I would have to be able to pass a predicate to
'retract' execute it and retract afterwards.<br>
<br>
If I try it interactively I can perform the operation like this:<br>
<br>
(be foo (1))<br>
(be foo (2))<br>
(be foo (3))<br>
<br>
(? (@CL list 'foo '(@N)) (equal (@P . (@A)) @CL) (call @P . @A) (@
retract (-> @CL))<br>
<br>
Here the predicate I want to retract is the first one unifying with
'(foo @N)'. This should be the first one '(foo 1)'. So '@N' is bound to
'1' and the corresponding clause is retracted.<br>
<br>
This works as I expect!<br>
<br>
But I seem not to be able to get the code into another clause. I tried
it like this:<br>
<br>
(be retract (@CL)<br>
(equal (@P . (@A)) @CL)<br>
(call @P . @A)<br>
(@ retract (-> @CL)) )<br>
<br>
But this does not work. If I try<br>
<br>
(? (retract (foo (@N))))<br>
<br>
'@N' got not bound to anything, an no fact was retracted. I have tried
several other implementations of 'retract' but I cannot get it to work.<br>
<br>
So perhaps you can shed any light over me, what I do miss?<br>
<br>
<br>
Thanks and ciao,<br>
Cle.<br>
<br>
<br>
</body>
</html>
--------------000509060708050706030409--
--
UNSUBSCRIBE: mailto:[email protected]?subject=unsubscribe