<commit_before>________________________________________________________________________

This file is part of Logtalk <https://logtalk.org/>  
Copyright 1998-2018 <NAME> <<EMAIL>>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
________________________________________________________________________


% start by loading the example and the required library files:

| ?- logtalk_load(metapredicates(loader)).
...


% note that "user" is a pseudo-object representing the Prolog database;
% therefore, the integer comparisons are performed using the standard
% Prolog built-in predicates

| ?- sort(user)::sort([3, 1, 4, 2, 9], Sorted).

call: partition([1,4,2,9],3,_358,_359)
exit: partition([1,4,2,9],3,[1,2],[4,9])
call: sort([1,2],_740)
call: partition([2],1,_967,_968)
exit: partition([2],1,[],[2])
call: sort([],_1300)
exit: sort([],[])
call: sort([2],_1539)
call: partition([],2,_1765,_1766)
exit: partition([],2,[],[])
call: sort([],_2093)
exit: sort([],[])
call: sort([],_2332)
exit: sort([],[])
exit: sort([2],[2])
exit: sort([1,2],[1,2])
call: sort([4,9],_2831)
call: partition([9],4,_3058,_3059)
exit: partition([9],4,[],[9])
call: sort([],_3391)
exit: sort([],[])
call: sort([9],_3630)
call: partition([],9,_3856,_3857)
exit: partition([],9,[],[])
call: sort([],_4184)
exit: sort([],[])
call: sort([],_4423)
exit: sort([],[])
exit: sort([9],[9])
exit: sort([4,9],[4,9])

Sorted = [1,2,3,4,9]
yes


% test the setof/3 wrapper:

| ?- object::p(L).

L = [1, 2, 3]
yes

| ?- object::q(L).

L = [1, 2, 3]
yes


% call the meta-predicate apply/2 directly:

| ?- metapreds::test_this.

1, metapreds
yes


% send an apply/2 message to self:

| ?- descendant::test_self.

2, descendant
yes


% send an apply/2 message from another object:

| ?- test::test_obj.

3, test
yes


% use the partition/4 meta-predicate with a predicate defined in the
% pseudo-object "user":

| ?- meta::partition(even_integer, [1,2,3,4,5], Included, Excluded).

Included = [2, 4]
Excluded = [1, 3, 5]
yes


% get a visual illustration of the differences between left and right folds:

| ?- folds::left(Left).

Left = '(((((((((0+1)+2)+3)+4)+5)+6)+7)+8)+9)'
yes

| ?- folds::right(Right).

Right = '(1+(2+(3+(4+(5+(6+(7+(8+(9+0)))))))))'
yes


% walk a list using fold left and fold right:

?- meta::fold_left([Y, X, [X|Y]]>>true, [], [1,2,3,4,5,6,7,8,9], R).

R = [9, 8, 7, 6, 5, 4, 3, 2, 1]
yes

?- meta::fold_right([X, Y, [X|Y]]>>true, [], [1,2,3,4,5,6,7,8,9], R)

R = [1, 2, 3, 4, 5, 6, 7, 8, 9].
yes


% use the fold_left/4 meta-predicate with a predicate defined in the
% pseudo-object "user":

| ?- meta::fold_left(sum_squares, 0, [1,2,3], Result).

Result = 34
yes


% use the fold_left/4 and fold_right/4 meta-predicates with the atom_concat/3
% Prolog built-in predicate:

| ?- meta::fold_left(atom_concat, 'PREFIX', [abc,def,ghi], Result).

Result = 'PREFIXabcdefghi'
yes

| ?- meta::fold_right(atom_concat, 'SUFIX', [abc,def,ghi], Result).

Result = abcdefghiSUFIX
yes
<commit_msg>Fix typo in `metapredicates` example sample call<commit_after>________________________________________________________________________

This file is part of Logtalk <https://logtalk.org/>  
Copyright 1998-2018 <NAME> <<EMAIL>>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
________________________________________________________________________


% start by loading the example and the required library files:

| ?- logtalk_load(metapredicates(loader)).
...


% note that "user" is a pseudo-object representing the Prolog database;
% therefore, the integer comparisons are performed using the standard
% Prolog built-in predicates

| ?- sort(user)::sort([3, 1, 4, 2, 9], Sorted).

call: partition([1,4,2,9],3,_358,_359)
exit: partition([1,4,2,9],3,[1,2],[4,9])
call: sort([1,2],_740)
call: partition([2],1,_967,_968)
exit: partition([2],1,[],[2])
call: sort([],_1300)
exit: sort([],[])
call: sort([2],_1539)
call: partition([],2,_1765,_1766)
exit: partition([],2,[],[])
call: sort([],_2093)
exit: sort([],[])
call: sort([],_2332)
exit: sort([],[])
exit: sort([2],[2])
exit: sort([1,2],[1,2])
call: sort([4,9],_2831)
call: partition([9],4,_3058,_3059)
exit: partition([9],4,[],[9])
call: sort([],_3391)
exit: sort([],[])
call: sort([9],_3630)
call: partition([],9,_3856,_3857)
exit: partition([],9,[],[])
call: sort([],_4184)
exit: sort([],[])
call: sort([],_4423)
exit: sort([],[])
exit: sort([9],[9])
exit: sort([4,9],[4,9])

Sorted = [1,2,3,4,9]
yes


% test the setof/3 wrapper:

| ?- object::p(L).

L = [1, 2, 3]
yes

| ?- object::q(L).

L = [1, 2, 3]
yes


% call the meta-predicate apply/2 directly:

| ?- metapreds::test_this.

1, metapreds
yes


% send an apply/2 message to self:

| ?- descendant::test_self.

2, descendant
yes


% send an apply/2 message from another object:

| ?- test::test_obj.

3, test
yes


% use the partition/4 meta-predicate with a predicate defined in the
% pseudo-object "user":

| ?- meta::partition(even_integer, [1,2,3,4,5], Included, Excluded).

Included = [2, 4]
Excluded = [1, 3, 5]
yes


% get a visual illustration of the differences between left and right folds:

| ?- folds::left(Left).

Left = '(((((((((0+1)+2)+3)+4)+5)+6)+7)+8)+9)'
yes

| ?- folds::right(Right).

Right = '(1+(2+(3+(4+(5+(6+(7+(8+(9+0)))))))))'
yes


% walk a list using left and right folds (note the lambda parameters order):

?- meta::fold_left([Y, X, [X|Y]]>>true, [], [1,2,3,4,5,6,7,8,9], R).

R = [9, 8, 7, 6, 5, 4, 3, 2, 1]
yes

?- meta::fold_right([X, Y, [X|Y]]>>true, [], [1,2,3,4,5,6,7,8,9], R).

R = [1, 2, 3, 4, 5, 6, 7, 8, 9].
yes


% use the fold_left/4 meta-predicate with a predicate defined in the
% pseudo-object "user":

| ?- meta::fold_left(sum_squares, 0, [1,2,3], Result).

Result = 34
yes


% use the fold_left/4 and fold_right/4 meta-predicates with the atom_concat/3
% Prolog built-in predicate:

| ?- meta::fold_left(atom_concat, 'PREFIX', [abc,def,ghi], Result).

Result = 'PREFIXabcdefghi'
yes

| ?- meta::fold_right(atom_concat, 'SUFIX', [abc,def,ghi], Result).

Result = abcdefghiSUFIX
yes

{'fraction_non_alphanumeric': 0.1927658963685948, 'fraction_numerical': 0.06688675183005598, 'mean_word_length': 5.177304964539007, 'pattern_counts': {'":': 4, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '1766075', 'n_tokens_mistral': 2811, 'n_tokens_neox': 2587, 'n_words': 746}