| Did you know ... | Search Documentation: |
| Pack starlog -- IMPLEMENTATION_SUMMARY_CALL_TO_VARIABLE.md |
Date: 2025-12-26 Feature: Save Prolog and Starlog calls to variables
This feature adds predicates to explicitly save the results of Prolog and Starlog calls to variables. While variables already work through Prolog's unification mechanism, these new predicates make it more explicit and provide convenient helpers for working with eval() and no_eval().
Signature: starlog_call(+Goal, -Result)
Purpose: Execute a Starlog goal and explicitly return the result in a variable.
Usage:
?- starlog_call(X is "hello":"world", Result). Result = "helloworld". ?- starlog_call(Y is [1,2] & [3,4], Result). Result = [1, 2, 3, 4]. ?- starlog_call(Z is reverse([1,2,3]), Result). Result = [3, 2, 1].
Implementation:
Var is ExprVar is Expr
Signature: starlog_eval(+Expr, -Result)
Purpose: Evaluate a Starlog expression and return the result. This forces evaluation of the expression, similar to wrapping it in eval().
Usage:
?- starlog_eval("x":"y", Result).
Result = "xy".
?- starlog_eval(1+1, Result).
Result = 2.
?- starlog_eval([a] & [b,c], Result).
Result = [a, b, c].
Implementation:
starlog_call((Result is eval(Expr)), Result)eval() wrapper ensures the expression is evaluated
Signature: starlog_no_eval(+Expr, -Result)
Purpose: Preserve a Starlog expression without evaluation and return it. This prevents evaluation of the expression, similar to wrapping it in no_eval().
Usage:
?- starlog_no_eval(1+1, Result).
Result = 1+1.
?- starlog_no_eval("hello":"world", Result).
Result = "hello":"world".
?- starlog_no_eval([a] & [b], Result).
Result = [a] & [b].
Implementation:
starlog_call((Result is no_eval(Expr)), Result)no_eval() wrapper ensures the expression is preserved as-is?- starlog_call(A is "First":"Part", R1), starlog_call(B is R1:" Complete", R2). R1 = "FirstPart", R2 = "FirstPart Complete".
?- starlog_no_eval(x*2 + y, Formula). Formula = x*2+y. % Formula can now be used in symbolic computation
?- starlog_eval("a":"b", Evaluated),
starlog_no_eval("a":"b", Preserved).
Evaluated = "ab",
Preserved = "a":"b".
% Store template
?- starlog_no_eval("Welcome, " : username : "!", Template).
Template = "Welcome, ":username:"!".
% Template can later be evaluated with actual username
Comprehensive tests have been added in tests/test_call_to_variable.pl:
Updated README.md with:
A demonstration file demo_call_to_variable.pl shows practical examples of using these predicates.
These additions are fully backward compatible:
starlog.pl: Added three new predicates and updated module exportsREADME.md: Added documentation for the new predicatestests/test_call_to_variable.pl: Comprehensive test suite (new file)demo_call_to_variable.pl: Demonstration examples (new file)