| Did you know ... | Search Documentation: |
| Pack starlog -- IMPLEMENTATION_ALL_COMBINATIONS.md |
Implement all combinations and configurations of: A is (1:1 >> string_number) * (+(1,1))
Successfully implemented comprehensive support for combining:
: operator>> operatorstarlog_expand.pl
% contains_starlog_in_arithmetic(+Expr)
% Check if an arithmetic expression contains Starlog sub-expressions
contains_starlog_in_arithmetic(Expr) :-
compound(Expr),
functor(Expr, _Op, Arity),
Arity > 0,
Expr =.. [_|Args],
member(Arg, Args),
(is_starlog_expr(Arg) ; contains_starlog_in_arithmetic(Arg)),
!.
% compile_arithmetic_with_starlog(+ArithExpr, -CompiledArithExpr, -PreGoals) % Compile an arithmetic expression that contains Starlog sub-expressions % Pre-evaluates the Starlog parts and returns a pure arithmetic expression
This recursively processes arithmetic expressions, detecting Starlog sub-expressions and compiling them first.
% Arithmetic expression with Starlog sub-expressions: Out is ArithExpr
% Handle cases like: A is (1:1 >> string_number) * 2
expand_goal_internal((Out is Expr), Expanded) :-
is_arithmetic(Expr),
contains_starlog_in_arithmetic(Expr),
!,
compile_starlog_expr(Expr, Out, Goals),
list_to_conjunction(Goals, Expanded).
This ensures arithmetic expressions with Starlog parts are properly expanded.
% Arithmetic expression - check if it contains Starlog sub-expressions
compile_starlog_expr(Expr, Out, Goals) :-
is_arithmetic(Expr),
!,
(contains_starlog_in_arithmetic(Expr) ->
compile_arithmetic_with_starlog(Expr, ArithExpr, PreGoals),
append(PreGoals, [Out is ArithExpr], Goals)
;
Goals = [Out is Expr]
).
A is (1:1 >> string_number) * (+(1,1))* operator)(1:1 >> string_number) as a Starlog sub-expression1:1 → string_concat(1, 1, _T1) → _T1 = "11""11" >> string_number → string_number("11", _T2) → _T2 = 11+(1,1) → 2_T2 * 2 → 11 * 2 → 22
The expansion produces:
string_concat(1, 1, _T1), string_number(_T1, _T2), A is _T2 * 2
Created comprehensive test suite tests/test_all_combinations_configurations.pl with 29 tests covering:
+-*///mod** and ^======================================== Test Summary ======================================== Total: 29 Passed: 29 Failed: 0 ✓ All tests passed!
?- use_module(starlog). ?- starlog_call(A is (1:1 >> string_number) * (+(1,1))). A = 22.
?- starlog_call(A is (2:3 >> string_number) * (+(1,1))). A = 46. % "23" -> 23 * 2
?- starlog_call(A is (1:1 >> string_number) + (+(1,1))). A = 13. % 11 + 2 ?- starlog_call(A is (2:0 >> string_number) ** (+(1,1))). A = 400. % 20 ** 2
?- starlog_call(A is ((1:1) : (2:2) >> string_number) * 2). A = 2244. % "1122" -> 1122 * 2 ?- starlog_call(A is (1:1 >> string_number) * (+(1,1) + +(1,1))). A = 44. % 11 * (2 + 2)
tests/test_all_combinations_configurations.pl - Comprehensive test suitedemo_all_combinations_configurations.pl - Interactive demonstrationALL_COMBINATIONS_CONFIGURATIONS.md - User documentationIMPLEMENTATION_ALL_COMBINATIONS.md - This filestarlog_expand.pl - Added arithmetic with Starlog sub-expression supportThis implementation enables:
✓ Fully compatible with all existing Starlog features ✓ All existing tests continue to pass ✓ No breaking changes ✓ Works with all arithmetic operators ✓ Works with all Starlog operators ✓ Supports arbitrary nesting depth
The pattern A is (1:1 >> string_number) * (+(1,1)) and all its combinations and configurations are now fully supported and tested. The implementation: