Did you know ... Search Documentation:
Pack starlog -- FOLDR_QUICK_REF.md

foldr Quick Reference

Syntax

Prolog Style

foldr(Operation, List, Accumulator, Result)

Starlog Style

Result is foldr(Operation, List, Accumulator)

Examples

String Reversal (Problem Statement)

% Prolog
?- string_chars("abc", C), reverse(C, R), foldr(string_concat, R, "", Result).
Result = "cba".

% Starlog
?- starlog_call(R is foldr(string_concat, reverse(string_chars("abc")), "")).
R = "cba".

List Concatenation

% Prolog
?- foldr(append, [[1], [2], [3]], [], Result).
Result = [1, 2, 3].

% Starlog
?- starlog_call(R is foldr(append, [[1], [2], [3]], [])).
R = [1, 2, 3].

String Building from Characters

?- foldr(string_concat, [h, e, l, l, o], "", Result).
Result = "hello".

How It Works

foldr(f, [x1, x2, x3], acc) computes: f(x1, f(x2, f(x3, acc)))

Processing order: right to left (processes x3 first, then x2, then x1)

See Also