jason-lang / jason

Jason is a fully-fledged interpreter for an extended version of AgentSpeak, a BDI agent-oriented logic programming language.
http://jason-lang.github.io
GNU Lesser General Public License v3.0
223 stars 67 forks source link

Develop #74

Closed cleberjamaral closed 4 years ago

cleberjamaral commented 4 years ago

Created tests some meta programming internal actions and created a new internal action called .type/2. I t checks whether a term is of a given type or retrieves all the types of the types of term by backtracking them. E.g.: .type("home page",string) returns true, .type(b,T) unifies T with the term 'atom' and backtracks unifying T with 'literal' and 'ground'.

The approach backtrack was preferred instead of always return the list of types because it seems to be better at least for producing error messages when types do not match. For instance, let us say the programmer was struggling expecting X == Y, but X == "string" and Y == string. In this case, notice that X is a string but Y is an atom. In this case, .type(X,TX) unifies TX with string which is the most "primitive" type of X. But also backtracks ground. .type(Y,TY) unifies TY with atom which is the most "primitive" type of Y, also backtracks ground. So, it is easier to give to the programmer the most primitive type instead of a list. In case of a list is preferred, a .findall can be used, e.g. .findall(T, .type(X,TX) ,TypesOfX).