]> git.leonardobizzoni.com Git - ObjectOriented-Prolog-Lisp/commitdiff
Fatta la `fieldx`
authorLeonardoBizzoni <leo2002714@gmail.com>
Sun, 17 Dec 2023 09:35:58 +0000 (10:35 +0100)
committerLeonardoBizzoni <leo2002714@gmail.com>
Sun, 17 Dec 2023 09:35:58 +0000 (10:35 +0100)
Prolog/README.org
Prolog/oop.pl

index 560b835875034f145d3e3fd1827fa5fa747b9c14..e9d4925602c6653c82bb48f02ce3864f58b8e5c0 100644 (file)
@@ -107,7 +107,7 @@ make(InstanceName, ClassName, Fields) :-
     is_instance(InstanceName, ClassName),
     check_fields(InstanceName, Fields).
 
-check_fields(InstanceName, []).
+check_fields(_InstanceName, []).
 check_fields(InstanceName, [=(Field, Value) | Other]) :-
     field(InstanceName, Field, Value),
     check_fields(InstanceName, Other).
@@ -127,12 +127,21 @@ check_fields(InstanceName, [=(Field, Value) | Other]) :-
 
 *** Esempio pratico
 
-** fields
+** fieldx
 *** Definizione
-
+- Non ho capito se così va bene
+- Non ho capito a cosa serve
+- Non ho capito quando va usato
 
 *** Implementazione
 #+begin_src prolog :tangle oop.pl
+fieldx(Instance, [FieldName], Res) :-
+    field(Instance, FieldName, Res),
+    !.
+fieldx(Instance, [FieldName | Others], Res) :-
+    is_instance(Instance),
+    field(Instance, FieldName, Value),
+    fieldx(Value, Others, Res).
 #+end_src
 
 *** Esempio pratico
index 24325bc7dd63a33bc2bbe412f19157739747076b..452d7668476132e789f1faff0a8c04f94d13ad69 100644 (file)
@@ -81,14 +81,20 @@ make(InstanceName, ClassName, Fields) :-
     is_instance(InstanceName, ClassName),
     check_fields(InstanceName, Fields).
 
-check_fields(InstanceName, []).
+check_fields(_InstanceName, []).
 check_fields(InstanceName, [=(Field, Value) | Other]) :-
     field(InstanceName, Field, Value),
     check_fields(InstanceName, Other).
 
 :- dynamic field/3.
 
-
+fieldx(Instance, [FieldName], Res) :-
+    field(Instance, FieldName, Res),
+    !.
+fieldx(Instance, [FieldName | Others], Res) :-
+    is_instance(Instance),
+    field(Instance, FieldName, Value),
+    fieldx(Value, Others, Res).
 
 :- dynamic is_class/1.
 :- dynamic is_child_of/2.