Skip to content

Commit

Permalink
no_match_behavior(throw_type_error_on_no_match)
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed Jan 3, 2025
1 parent fb2e92c commit 39ef7b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion prolog/metta_lang/metta_testing.pl
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@
% @example
% % Log the details of a test with a passing status:
% ?- write_pass_fail(['source', 'category', 'type'], 'PASS', some_goal(arg1, arg2)).
write_pass_fail([P, C, _], PASS_FAIL, G) :-
write_pass_fail([P, C| _], PASS_FAIL, G) :- !,
% Ensures deterministic logging of the test result.
must_det_ll((
% Retrieves the current test number.
Expand All @@ -437,6 +437,7 @@
write_pass_fail(TestName, P, C, PASS_FAIL, G1, G2))).

write_pass_fail(LIST, PASS_FAIL, G) :- is_list(LIST), PCC = [P, _, _], member(PCC,LIST), nonvar(P), !, write_pass_fail(PCC, PASS_FAIL, G).
write_pass_fail(LIST, PASS_FAIL, G) :- is_list(LIST), PCC = [P|_], member(PCC,LIST), nonvar(P), !, write_pass_fail(PCC, PASS_FAIL, G).

%! write_pass_fail(+TestName, +Source, +Category, +Status, +GoalArg1, +GoalArg2) is det.
%
Expand Down
25 changes: 16 additions & 9 deletions prolog/metta_lang/metta_types.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2235,26 +2235,33 @@
% Enums for Guarded Type Handling in Prolog

% GuardMatchResult: Describes the result of evaluating several type guards against the function arguments.
mo_match_behavior(fail_on_no_match).
mo_match_behavior(return_original_on_no_match).
mo_match_behavior(fail_on_no_match).
mo_match_behavior(throw_type_error_on_no_match).
% EvaluationOrder: Describes how the type guards are prioritized during evaluation.
evaluation_order(fittest_first_priority).
evaluation_order(clause_order_priority).
evaluation_order(fittest_first_priority).
% ExecutionResult: Describes the outcome of executing the guarded expression.
execution_result_behavior(cut_on_first_success).
execution_result_behavior(continue_on_success).
execution_result_behavior(cut_on_first_success).
% ExecutionResult: Describes the outcome of executing the guarded expression.
execution_failed_behavior(cut_on_first_failure).
execution_failed_behavior(continue_on_failure).
execution_failed_behavior(cut_on_first_failure).
% What do when there are no successfull bodies
out_of_clauses_behavior(fail_on_no_success).
out_of_clauses_behavior(return_original_on_no_success).
out_of_clauses_behavior(fail_on_final_failure).
out_of_clauses_behavior(return_original_on_final_failure).




%predicate_behavior(Predicate, Len, NoMatchBehavior, EvaluationOrder, SuccessBehavior, FailureBehavior, OutOfClausesBehavior)
predicate_behavior_impl('get-type', 1, fail_on_no_match, clause_order_priority, continue_on_success, continue_on_failure, fail_on_no_success).
predicate_behavior_impl('get-type', 1, fail_on_no_match, clause_order_priority, continue_on_success, continue_on_failure, fail_on_final_failure).

predicate_behavior_impl('foo', 2, return_original_on_no_match, fittest_first_priority, continue_on_success, continue_on_failure, return_original_on_final_failure).

predicate_behavior_impl('match', 4, fail_on_no_match, clause_order_priority, continue_on_success, continue_on_failure, fail_on_final_failure).
% default
predicate_behavior_fallback(_, _, return_original_on_no_match, clause_order_priority, continue_on_success, continue_on_failure, return_original_on_no_success).
predicate_behavior_fallback(_, _, return_original_on_no_match, clause_order_priority, continue_on_success, continue_on_failure, return_original_on_final_failure).

predicate_behavior(Predicate, Len, NoMatchBehavior, EvaluationOrder, SuccessBehavior, FailureBehavior, OutOfClausesBehavior):-
predicate_behavior_impl(Predicate, Len, NoMatchBehavior, EvaluationOrder, SuccessBehavior, FailureBehavior, OutOfClausesBehavior)
Expand Down Expand Up @@ -2312,7 +2319,7 @@
(FailureBehavior == cut_on_first_failure -> (!, fail) ; fail)) % vs continue_on_failure
*->
true ;
(OutOfClausesBehavior == fail_on_no_success -> fail ; throw(metta_notreducable([Predicate | Parameters])))). % vs return_original_on_no_success
(OutOfClausesBehavior == fail_on_final_failure -> fail ; throw(metta_notreducable([Predicate | Parameters])))). % vs return_original_on_final_failure



Expand Down

0 comments on commit 39ef7b4

Please sign in to comment.