I hope you are well. I write this because I have been trying to implement user-defined types within my application, but I seem to be running into trouble getting it work, and am also observing some strange behaviour, which I would hope you could help shed some light on, or perhaps point me in the right direction to be able to solve it. Here is the code I have implemented for these tests (the underlying prolog engine is SWI, if that helps):
Code: Select all
:- category(my_types).
% register a new parametric temperature type
:- multifile(type::type/1).
type::type(attackPlan).
type::type(attackAction).
type::type(asset).
% add the actual checking code for the new type
:- multifile(type::check/2).
type::check(attackPlan, _P_) :-
check_attackPlan(_P_).
type::check(attackAction, _P_) :-
check_attackAction(_P_).
type::check(asset, _P_) :-
check_asset(_P_).
check_attackAction(_P_) :-
_{risk:Risk, asset:Asset, impact:Impact, type:Type} :< _P_,
type::check(integer, Risk),
type::check(integer, Impact),
type::check(atomic, Type),
type::check(asset, Asset).
check_attackPlan(_P_) :-
_{a:AAs} :< _P_,
type::check(property(list, [AttackActions]>>(
meta::map([AA]>>(
type::check(attackAction, AA)
), AttackActions)
)), AAs).
check_asset(_P_) :-
_{id:Id, os:OS, ip:IP} :< _P_,
meta::map([Attr]>>(type::check(atomic, Attr)), [Id, OS, IP]).
:- end_category.
Code: Select all
debugger::trace
Code: Select all
?- R = _{a:[
_{impact:5, risk:50, asset:_{id:"1", os:"linux", ip:"1.1.1.1"}, type:"dos", id:"1"},
_{impact:5, risk:50, asset:_{id:"2", os:"linux", ip:"1.1.1.2"}, type:"malware", id:"2"},
_{impact:5, risk:50, asset:_{id:"3", os:"linux", ip:"1.1.1.3"}, type:"dos", id:"3"},
_{impact:5, risk:50, asset:_{id:"4", os:"linux", ip:"1.1.1.4"}, type:"malware", id:"4"},
_{impact:5, risk:50, asset:_{id:"5", os:"linux", ip:"1.1.1.5"}, type:"networkRecon", id:"5"},
_{impact:5, risk:50, asset:_{id:"6", os:"linux", ip:"1.1.1.6"}, type:"networkRecon", id:"6"}
]},
type::check(attackPlan, R).
Thank you very much for your time.
-K
P.S. I have also been using Logtalk's VSCode extension, which, when analyzing its source code, it seems to be using the logtalk compiler (the swilgt executable) to perform linting on the files, however the linter seems to find a permission error when defining the multifile predicates as it says the type object is not modfiable:
Code: Select all
type::type/1
type::check/1