Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/hyperpose_primes.metta
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

(= (find-divisor $n $test-divisor)
(if (> (* $test-divisor $test-divisor) $n)
$n
Expand All @@ -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
Expand Down
13 changes: 11 additions & 2 deletions src/translator.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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).
Expand Down
Loading