Closed unthingable closed 6 months ago
There are no parameter variables in your example. Their syntax, as documented, requires their names to start and end with an underscore. Write _Name_
instead of _Name
and _Arity_
instead of _Arity
.
The this/1
built-in execution context method is working as intended, returning the object importing the category, as documented.
Thanks! That fixes it.
In the examples I've seen parameters be _Name_
, _Name
and Name
— was under the wrong impression that was a stylistic suggestion. Even the parametric category documentation lists this as an example immediately following the snippet above:
:- object(speech(Season, Event),
imports([dress(Season), speech(Event)])).
...
:- end_object.
In parametric objects documentation states:
Object parameters can be accessed using parameter variables or built-in execution context methods. Parameter variables is the recommended solution to access object parameters. Although they introduce a concept of entity global variables, their unique syntax, ParameterName, avoids conflicts and makes them easily recognizable.
An explicit mention that this syntax is also required for named parameter var resolution to work would have made this clearer, I think.
See also:
https://logtalk.org/manuals/userman/objects.html#accessing-object-parameters
Note that _Name
is a named (but otherwise ) anonymous variable. Name
is a variable that is expected to occur two or more times in a directive or clause (otherwise it will be reported as a singleton variable). Parameter variables are named anonymous variables that are recognized (and thus distinguished from other named anonymous variables) and specifically handled by the compiler thanks to their syntax. In that snippet, that syntax is not required as both Season
and Event
variables occur more than once.
I will look into improving the documentation. Thanks for the feedback.
Docs say:
However:
Unless I'm mistaken:
pamareter/2
indeed works as expectedthis/1
kind of works, would have expected it to befunctor(foo, 1)