<commit_before>:- module(coroutines, [freeze/2, when/2, frozen/2, block/1]).

% *****************************************************
% *                  F R E E Z E                      *
% *****************************************************

freeze(X, Goal) :-
	nonvar(X),
	this_module(M),
	call(M:(Goal)).

freeze(X, Goal) :- 
	var(X),
	this_module(M),
	\+ get_attr(X, freeze, _),
	put_attr(X, freeze, M:(Goal)).

freeze(X, Goal) :-
	var(X),
	this_module(M),
	get_attr(X, freeze, Old_Goals),
	put_attr(X, freeze, (Old_Goals, M:(Goal))).

% * FROZEN *

frozen(X, true) :-
	nonvar(X).

frozen(X, true) :-
	var(X),
	\+ get_attr(X, freeze, _).

frozen(X, R) :-
	var(X),
	get_attr(X, freeze, R).

% *****************************************************
% *                    W H E N                        *
% *****************************************************

put_when_attributes([], _).
put_when_attributes([X|Rest], When_Goal) :-
	(get_attr(X, when, Current_Goals)
	->
		put_attr(X, when, (Current_Goals, When_Goal))
	;
		put_attr(X, when, When_Goal)
	),
	put_when_attributes(Rest, When_Goal).

when_impl(nonvar(X), Goal) :-
	(var(X)
	->
		put_when_attributes([X], Goal)
	;
		Goal
	).

when_impl(ground(X), Goal) :-
	term_variables(X, Varlist),
	(Varlist == []
	->
		Goal
	;
		[Var|_] = Varlist,
		put_when_attributes([Var], coroutines:when_impl(ground(Varlist), Goal))
	).

when_impl((A, B), Goal) :-
	when_impl(A, coroutines:when_impl(B, Goal)).

call_when_disjoint(Var, Goal) :-
	var(Var),
	Goal,
	Var = a.

call_when_disjoint(Var, _) :-
	nonvar(Var).<commit_msg>Replaced identical comparison with unification.<commit_after>:- module(coroutines, [freeze/2, when/2, frozen/2, block/1]).

% *****************************************************
% *                  F R E E Z E                      *
% *****************************************************

freeze(X, Goal) :-
	nonvar(X),
	this_module(M),
	call(M:(Goal)).

freeze(X, Goal) :- 
	var(X),
	this_module(M),
	\+ get_attr(X, freeze, _),
	put_attr(X, freeze, M:(Goal)).

freeze(X, Goal) :-
	var(X),
	this_module(M),
	get_attr(X, freeze, Old_Goals),
	put_attr(X, freeze, (Old_Goals, M:(Goal))).

% * FROZEN *

frozen(X, true) :-
	nonvar(X).

frozen(X, true) :-
	var(X),
	\+ get_attr(X, freeze, _).

frozen(X, R) :-
	var(X),
	get_attr(X, freeze, R).

% *****************************************************
% *                    W H E N                        *
% *****************************************************

put_when_attributes([], _).
put_when_attributes([X|Rest], When_Goal) :-
	(get_attr(X, when, Current_Goals)
	->
		put_attr(X, when, (Current_Goals, When_Goal))
	;
		put_attr(X, when, When_Goal)
	),
	put_when_attributes(Rest, When_Goal).

when_impl(nonvar(X), Goal) :-
	(var(X)
	->
		put_when_attributes([X], Goal)
	;
		Goal
	).

when_impl(ground(X), Goal) :-
	term_variables(X, Varlist),
	(Varlist = []
	->
		Goal
	;
		[Var|_] = Varlist,
		put_when_attributes([Var], coroutines:when_impl(ground(Varlist), Goal))
	).

when_impl((A, B), Goal) :-
	when_impl(A, coroutines:when_impl(B, Goal)).

call_when_disjoint(Var, Goal) :-
	var(Var),
	Goal,
	Var = a.

call_when_disjoint(Var, _) :-
	nonvar(Var).
{'fraction_non_alphanumeric': 0.3016022620169651, 'fraction_numerical': 0.0025133521834747093, 'mean_word_length': 3.780780780780781, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '802977', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1274, 'n_words': 207}