Created the library random and moved some predicates from iso_ext

This commit is contained in:
notoria
2020-04-26 23:33:10 +02:00
parent 3fd557c74a
commit de7a408903
2 changed files with 24 additions and 23 deletions

View File

@@ -4,10 +4,10 @@
%% ?- use_module(library(iso_ext)). %% ?- use_module(library(iso_ext)).
:- module(iso_ext, [bb_b_put/2, bb_get/2, bb_put/2, call_cleanup/2, :- module(iso_ext, [bb_b_put/2, bb_get/2, bb_put/2, call_cleanup/2,
call_with_inference_limit/3, forall/2, maybe/0, call_with_inference_limit/3, forall/2,
partial_string/1, partial_string/3, partial_string/1, partial_string/3,
partial_string_tail/2, set_random/1, partial_string_tail/2, setup_call_cleanup/3,
setup_call_cleanup/3, variant/2]). variant/2]).
forall(Generate, Test) :- forall(Generate, Test) :-
\+ (Generate, \+ Test). \+ (Generate, \+ Test).
@@ -144,21 +144,6 @@ call_with_inference_limit(_, _, R, Bb, B) :-
variant(X, Y) :- '$variant'(X, Y). variant(X, Y) :- '$variant'(X, Y).
% succeeds with probability 0.5.
maybe :- '$maybe'.
set_random(Seed) :-
( nonvar(Seed) ->
( Seed = seed(S) ->
( var(S) -> throw(error(instantiation_error, set_random/1))
; integer(S) -> '$set_seed'(S)
; throw(error(type_error(integer(S), set_random/1)))
)
)
; throw(error(instantiation_error, set_random/1))
).
partial_string(String, L, L0) :- partial_string(String, L, L0) :-
( String == [] -> ( String == [] ->
L = L0 L = L0

16
src/prolog/lib/random.pl Normal file
View File

@@ -0,0 +1,16 @@
:- module(random, [maybe/0, set_random/1]).
% succeeds with probability 0.5.
maybe :- '$maybe'.
set_random(Seed) :-
( nonvar(Seed) ->
( Seed = seed(S) ->
( var(S) -> throw(error(instantiation_error, set_random/1))
; integer(S) -> '$set_seed'(S)
; throw(error(type_error(integer(S), set_random/1)))
)
)
; throw(error(instantiation_error, set_random/1))
).