-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🧠 Logic: ⛓️ foldl/4
predicate
#788
Comments
That's an important I agree. I also think it is easier to implement it in Prolog directly than as a custom Go predicate: foldl(Goal, [H|T], Result) :-
foldl(Goal, T, H, Result).
foldl(Goal, [H|T], Acc, Result) :-
call(Goal, Acc, H, NewAcc),
foldl(Goal, T, NewAcc, Result).
foldl(_Goal, [], Result, Result). I'd like to propose to allow implementing new predicates directly in prolog, which would be added to the I recall for example that we've implemented the What do you think @ccamel ? We may lose in performance though, maybe some benchmarks could help us on that |
Hey! I agree. IMHO, native predicate implementations should be reserved for:
Regarding foldl(Goal, List, V0, V) :-
foldl_(List, Goal, V0, V).
foldl_([], _, V, V).
foldl_([H|T], Goal, V0, V) :-
call(Goal, H, V0, V1),
foldl_(T, Goal, V1, V). Further considerations.
Note:
If you want to move forward on these topics, we should create tickets to address the different steps. Also, some topics need to be addressed in axone-protocol/prolog. |
Hi, Christope, sorry for leaving comment here without your agreement and respecting the team rule. Because I wanna contribute to Axone team's development and join your team, so I am going to solve issues. So could you give me some issue to be solved quickly as test task? |
@solthereum please contact us on our discord server. |
thanks @ccamel, I left message to you. |
📝 Purpose
Implement the
foldl/4
Prolog predicate. This predicate performs a fold (left-fold) over a list, applying a goal to each element in the list, starting with an initial accumulator value and producing a final value after all elements are processed.Rationale
This predicate is quite common and can facilitate the expression of certain governance rules, especially in scenarios where an aggregate decision or value must be derived from a list of inputs by applying a consistent operation across them...
🧪 Expected behavior
foldl/4
folds a list head-to-tail (“fold-left”), applying each element to the specified Goal.V0
serves as the initial accumulator value, andV
is the final result of the folding operation.Where:
Goal
: A predicate that is applied to the elements of List and the accumulator. It should accept three arguments: an element of List, the current accumulator, and the new accumulator.List
: A list of elements to be folded over.V0
: The initial accumulator value.V
: The final value of the accumulator after folding the entire list.🎯 Example
✅ Acceptance Criteria
🔗 References and linked predicate
The text was updated successfully, but these errors were encountered: