<commit_before>
:- object(metacircle,			% avoid infinite metaclass regression by
	instantiates(metacircle)).	% making the class its own metaclass

	:- public(new/4).
	:- mode(new(+float, +float, +float, -object_identifier), one).
	:- info(new/4, [
		comment is 'Creates a new circle in a given position and with a given radius.',
		argnames is ['X', 'Y', 'Radius', 'Cicle']]).

	new(Radius, X, Y, Circle) :-
		self(Self),
		create_object(Circle, [instantiates(Self)], [], [position(X, Y), radius(Radius)]).

	:- public(area/2).
	:- mode(area(+float, -float), one).
	:- info(area/2, [
		comment is 'Calculates the area of a circle given its radius.',
		argnames is ['Radius', 'Area']]).

	area(Radius, Area) :-
		Area is 4*atan(1.0)*Radius*Radius.

:- end_object.


:- object(circle,
	instantiates(metacircle)).

	:- public(position/2).
	:- mode(position(?float, ?float), zero_or_one).
	:- info(position/2, [
		comment is 'Circle position.',
		argnames is ['X', 'Y']]).

	position(0.0, 0.0).		% default position

	:- public(radius/1).
	:- mode(radius(?float), zero_or_one).
	:- info(radius/1, [
		comment is 'Circle radius.',
		argnames is ['Radius']]).

	radius(1.0).			% default radius

	:- public(area/1).
	:- mode(area(-float), one).
	:- info(area/1, [
		comment is 'Circle area.',
		argnames is ['Area']]).

	area(Area) :-
		::radius(Radius),
		Area is 4*atan(1.0)*Radius*Radius.

:- end_object.


:- object(c42,
	instantiates(circle)).

	position(3.7, 4.5).
	radius(2.8).

:- end_object.<commit_msg>Improved documentation of the "classmethods" example.<commit_after>
% avoid infinite metaclass regression by making "metacircle" its own metaclass;
% another option would be to define "metacircle" as a subclass or instance of
% the built-in object "logtalk", which can be used as root of both class and
% prototype hierarchies

:- object(metacircle,
	instantiates(metacircle)).
			
	:- public(new/4).
	:- mode(new(+float, +float, +float, -object_identifier), one).
	:- info(new/4, [
		comment is 'Creates a new circle in a given position and with a given radius.',
		argnames is ['X', 'Y', 'Radius', 'Circle']]).

	new(Radius, X, Y, Circle) :-	% this would be a "constructor" in other languages 
		self(Self),					% we may be instantiating a subclass of "circle"
		create_object(Circle, [instantiates(Self)], [], [position(X, Y), radius(Radius)]).

	:- public(area/2).
	:- mode(area(+float, -float), one).
	:- info(area/2, [
		comment is 'Calculates the area of a circle given its radius.',
		argnames is ['Radius', 'Area']]).

	area(Radius, Area) :-
		Area is 4*atan(1.0)*Radius*Radius.

:- end_object.


:- object(circle,
	instantiates(metacircle)).

	:- public(position/2).
	:- mode(position(?float, ?float), zero_or_one).
	:- info(position/2, [
		comment is 'Circle position.',
		argnames is ['X', 'Y']]).

	position(0.0, 0.0).		% default position

	:- public(radius/1).
	:- mode(radius(?float), zero_or_one).
	:- info(radius/1, [
		comment is 'Circle radius.',
		argnames is ['Radius']]).

	radius(1.0).			% default radius

	:- public(area/1).
	:- mode(area(-float), one).
	:- info(area/1, [
		comment is 'Circle area.',
		argnames is ['Area']]).

	area(Area) :-
		::radius(Radius),	% ask the circle's instance that received the area/1 message its radius
		Area is 4*atan(1.0)*Radius*Radius.

:- end_object.


:- object(c42,				% a static instance of "circle"
	instantiates(circle)).

	position(3.7, 4.5).
	radius(2.8).

:- end_object.
{'fraction_non_alphanumeric': 0.1835075493612079, 'fraction_numerical': 0.017711962833914054, 'mean_word_length': 3.7127222982216144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5921848', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1214, 'n_words': 332}