]> git.leonardobizzoni.com Git - ObjectOriented-Prolog-Lisp/commitdiff
Fixato chiamata ricorsiva di un metodo con `this`
authorLeonardoBizzoni <leo2002714@gmail.com>
Sat, 23 Dec 2023 07:34:48 +0000 (08:34 +0100)
committerLeonardoBizzoni <leo2002714@gmail.com>
Sat, 23 Dec 2023 07:34:48 +0000 (08:34 +0100)
Prolog/README.org
Prolog/oop.pl

index 499e417cba0e3e682dcc339edea5d7590fba0e87..ffc0f24fb658d95e322a55a2a3840a4f84991996 100644 (file)
@@ -279,9 +279,11 @@ define_this([=(Key, Value) | Other]) :-
 #+begin_src prolog :tangle oop.pl
 call_method(Instance, ClassName, Body) :-
     is_instance(Instance, ClassName),
+    asserta(is_instance(this, ClassName)),
     define_this(Instance),
-    call(Body),
-    retractall(field(this, _, _)).
+    call_cleanup(call(Body), (
+                    retractall(is_instance(this, ClassName)),
+                    retractall(field(this, _, _)))).
 #+end_src
 
 ** check_value_type
index 97f659f648686757175c1213d01647bc49870ffa..f42fa2be4c572ed8139553019a0340a20a411343 100644 (file)
@@ -207,9 +207,11 @@ define_this([=(Key, Value) | Other]) :-
 
 call_method(Instance, ClassName, Body) :-
     is_instance(Instance, ClassName),
+    asserta(is_instance(this, ClassName)),
     define_this(Instance),
-    call(Body),
-    retractall(field(this, _, _)).
+    call_cleanup(call(Body), (
+                    retractall(is_instance(this, ClassName)),
+                    retractall(field(this, _, _)))).
 
 check_value_type(nil, _X) :- !.
 check_value_type(var, X) :- var(X), !.