| Did you know ... | Search Documentation: |
| Pack starlog -- ARITHMETIC_IN_BUILTINS_SUMMARY.md |
Complete support for: A is number_string(2^2):2
Added automatic evaluation of arithmetic expressions when used as arguments to builtin functions in Starlog.
starlog_expand.plAdded a new clause to compile_value/3 (lines 390-392):
% Arithmetic expressions should be evaluated when used as builtin arguments
compile_value(Expr, Value, [Value is Expr]) :-
is_arithmetic(Expr),
!.
This ensures that when an arithmetic expression (like 2^2, 10+5, etc.) is used as an argument to a builtin function, it gets evaluated first before being passed to the function.
tests/test_arithmetic_in_builtins.pl)Comprehensive test suite covering:
number_string: number_string(2^2) → "4"number_string(2^2) : 2 → "42"number_string(3*4+5) → "17"string_length(number_string(10+5)) → 2number_string(1+1) : number_string(2*2) → "24"^, *, /, +, -demo_arithmetic_in_builtins.pl)Demonstration file showcasing:
?- starlog_call(A is number_string(2^2):2). ERROR: number_string/2: Type error: `number' expected, found `2^2' (a compound)
?- starlog_call(A is number_string(2^2):2). A = "42".
The expression is evaluated step by step:
2^2 is evaluated to 4 (arithmetic evaluation)number_string(4) converts to "4" (builtin call)"4" : 2 concatenates to "42" (string concatenation with auto-conversion)The implementation distinguishes between two use cases:
A is 2^2
A is number_string(2^2)
This design:
All tests pass:
test_arithmetic_in_builtins.pl (10 tests)test_basic.pl, test_nested.pl, test_arithmetic_is.pl, etc.test_number_string_number.pl% Basic ?- starlog_call(A is number_string(2^2)). A = "4". % With concatenation ?- starlog_call(A is number_string(2^2):2). A = "42". % Complex arithmetic ?- starlog_call(A is number_string((2+3)*(4+1))). A = "25". % Multiple concatenations ?- starlog_call(A is number_string(1+1):"-":number_string(2*2)). A = "2-4". % Nested builtins ?- starlog_call(A is string_length(number_string(10^2))). A = 3.
+, -, *, /, //, mod, **, ^No security issues detected by CodeQL analysis.