diff --git a/examples/hyperpose_primes.metta b/examples/hyperpose_primes.metta index a6a67da8..98f9581b 100644 --- a/examples/hyperpose_primes.metta +++ b/examples/hyperpose_primes.metta @@ -1,3 +1,4 @@ + (= (find-divisor $n $test-divisor) (if (> (* $test-divisor $test-divisor) $n) $n @@ -8,6 +9,10 @@ (= (prime? $n) (== $n (find-divisor $n 2))) +;hyperpose should work with a list passed through a variable +!(test (msort (collapse (let $xs (3 1 2) (hyperpose $xs)))) + (1 2 3)) + ;multi-threaded concurrency running each option till the bitter end: !(test (collapse (hyperpose ((prime? 5353725700019) ;cheap (prime? 5378181100003) ;cheap diff --git a/src/translator.pl b/src/translator.pl index 4e1985f9..86f1e34e 100644 --- a/src/translator.pl +++ b/src/translator.pl @@ -124,8 +124,13 @@ append(G2, [test(Actual, ExpVal, Out)], Goals) ; HV == once, T = [X] -> translate_expr_to_conj(X, Conj, Out), append(GsH, [once(Conj)], Goals) - ; HV == hyperpose, T = [L] -> build_hyperpose_branches(L, Branches), - append(GsH, [concurrent_and(member((Goal,Res), Branches), (call(Goal), Out = Res))], Goals) + ; HV == hyperpose, T = [L] + -> ( nonvar(L), is_list(L) + -> build_hyperpose_branches(L, Branches), + append(GsH, [concurrent_and(member((Goal,Res), Branches), (call(Goal), Out = Res))], Goals) + ; translate_expr(L, GsL, LV), + append(GsH, GsL, Inner), + append(Inner, [hyperpose_runtime(LV, Out)], Goals) ) ; HV == with_mutex, T = [M,X] -> translate_expr_to_conj(X, Conj, Out), append(GsH, [with_mutex(M,Conj)], Goals) ; HV == transaction, T = [X] -> translate_expr_to_conj(X, Conj, Out), @@ -411,6 +416,10 @@ build_hyperpose_branches([E|Es], [(Goal, Res)|Bs]) :- translate_expr_to_conj(E, Goal, Res), build_hyperpose_branches(Es, Bs). +%Runtime hyperpose path for variable/computed list arguments. +hyperpose_runtime(Exprs, Out) :- is_list(Exprs), + concurrent_and(member(Expr, Exprs), eval(Expr, Out)). + %Like membercheck but with direct equality rather than unification memberchk_eq(V, [H|_]) :- V == H, !. memberchk_eq(V, [_|T]) :- memberchk_eq(V, T).