| Did you know ... | Search Documentation: |
| Pack starlog -- FIND_QUICK_REF.md |
% Starlog syntax (2 arguments): Result is find(Template, Goal) % Equivalent to: findall(Template, (Goal, !), [Result]) % with automatic evaluation of Starlog expressions in Template % Backward compatible 3-argument form: find(Template, Goal, Result) % Still available for compatibility
The find/2 predicate executes a goal with a cut and collects the first solution. It follows the Starlog pattern of using is for value-returning operations, similar to findall/2.
% Starlog syntax (recommended): Result is find(+Template, +Goal) % Traditional Prolog syntax (backward compatible): find(+Template, +Goal, -Result)
Parameters:
?- starlog_call(Result is find(A, starlog_call([A:a] is [a:a]))). Result = a.
?- starlog_call(Result is find(X, member(X, [1,2,3]))). Result = 1. % Only first solution
?- starlog_call(Result is find(R, starlog_call(R is "hello":"world"))). Result = "helloworld".
?- starlog_call(Result is find(L, starlog_call(L is [1,2]&[3,4]))). Result = [1, 2, 3, 4].
?- starlog_call(Result is find(A, starlog_call(([1]&A) is (B&[2])))). Result = [2].
?- starlog_call(Result is find(X, X is 10+5)). Result = 15.
[C]| Predicate | Syntax | Returns | Solutions |
|---|---|---|---|
| findall/2 | Result is findall(T, G) | List of all solutions | All |
| find/2 | Result is find(T, G) | Single result | First only (cut) |
| once/1 | once(G) | Boolean success | First only (cut) |
The old 3-argument form is still supported for backward compatibility:
% Old syntax (still works): find(A, starlog_call([A:a] is [a:a]), Result). % New syntax (recommended): starlog_call(Result is find(A, starlog_call([A:a] is [a:a]))).
See tests/test_find.pl for comprehensive test suite with 10 test cases.
Run demo_find.pl for interactive examples:
swipl -s demo_find.pl