maplist/3, maplist/4, maplist/5, maplist/6,
maplist/7, maplist/8, maplist/9, same_length/2, nth0/3, nth0/4, nth1/3, nth1/4,
sum_list/2, transpose/2, list_to_set/2, list_max/2,
- list_min/2, permutation/2, filter/3]).
+ list_min/2, permutation/2]).
/* Author: Mark Thom, Jan Wielemaker, and Richard O'Keefe
Copyright (c) 2018-2021, Mark Thom
perm(List, [First|Perm]) :-
select(First, List, Rest),
perm(Rest, Perm).
-
-
-%% filter(+Predicate, ?Xs1 ?Xs2).
-%
-% Succeeds if Xs2 is the list of elements X from Xs1 for which call(Pred, X) succeeds.
-%
-filter(_, [], []).
-filter(Pred, [X1|XS1], XS) :- call(Pred, X1) -> filter(Pred, XS1, XS2), XS = [X1|XS2] ; filter(Pred, XS1, XS).
\ No newline at end of file
:- use_module(library(error)).
:- use_module(library(iso_ext)).
-:- use_module(library(lists), [member/2, maplist/2, filter/3]).
+:- use_module(library(lists), [member/2, maplist/2]).
+:- use_module(library(reif), [tfilter/3]).
%% process_create(+Exe, +Args:list, +Options).
check_options([], _).
check_options([X | XS], Options) :-
(Kinds, Pred, Default, Choice) = X,
- filter(process:find_option(Kinds), Options, Solutions),
+ tfilter(process:find_option(Kinds), Options, Solutions),
(
Solutions = [] -> Choice = Default;
Solutions = [Provided] -> call(Pred, Provided), Choice = Provided ;
),
check_options(XS, Options).
-find_option([Kind|_], Found) :- Found =.. [Kind,_].
-find_option([_|Kinds], Found) :- find_option(Kinds, Found).
+find_option(Names, Found, T) :- (functor(Found, Name, 1), member(Name, Names)) -> T = true ; T = false.
-valid_stdio(IO) :- IO =.. [_, Arg],
+valid_stdio(IO) :- arg(1, IO, Arg),
(
+ var(Arg) -> instantiation_error(process_create/3) ;
valid_stdio_(Arg) -> true ;
domain_error(process_create_option, Arg, process_create/3)
).
valid_stdio_(pipe(Stream)) :- must_be(var, Stream).
valid_stdio_(file(Path)) :- must_be(chars, Path).
-valid_env(env(E)) :- (
+valid_env(env(E)) :-
+ must_be(list, E),
+ (
valid_env_(E) -> true ;
domain_error(process_create_option, env(E), process_create/3)
).
-valid_env(environment(E)) :- (
+valid_env(environment(E)) :-
+ must_be(list, E),
+ (
valid_env_(E) -> true ;
domain_error(process_create_option, environment(E), process_create/3)
).
ArenaHeaderTag::InputChannelStream => {
Stream::InputChannel(unsafe { ptr.as_typed_ptr() })
}
+ ArenaHeaderTag::PipeReader => Stream::PipeReader(unsafe { ptr.as_typed_ptr() }),
+ ArenaHeaderTag::PipeWriter => Stream::PipeWriter(unsafe { ptr.as_typed_ptr() }),
_ => unreachable!(),
}
}
| Stream::Readline(_)
| Stream::StaticString(_)
| Stream::InputFile(..)
+ | Stream::PipeReader(_)
| Stream::Null(_) => true,
_ => false,
}
| Stream::Byte(_)
| Stream::OutputFile(..)
| Stream::Callback(_)
+ | Stream::PipeWriter(_)
| Stream::Null(_) => true,
_ => false,
}
#[allow(unused_braces)]
$code
}};
+ ($ptr:ident, PipeReader, $listener:ident, $code:expr) => {{
+ #[allow(unused_mut)]
+ let mut $listener = unsafe { $ptr.as_typed_ptr::<PipeReader>() };
+ #[allow(unused_braces)]
+ $code
+ }};
+ ($ptr:ident, PipeWriter, $listener:ident, $code:expr) => {{
+ #[allow(unused_mut)]
+ let mut $listener = unsafe { $ptr.as_typed_ptr::<PipeWriter>() };
+ #[allow(unused_braces)]
+ $code
+ }};
($ptr:ident, ChildProcess, $listener:ident, $code:expr) => {{
#[allow(unused_mut)]
let mut $listener = unsafe { $ptr.as_typed_ptr::<std::process::Child>() };
| ArenaHeaderTag::InputChannelStream
| ArenaHeaderTag::StandardOutputStream
| ArenaHeaderTag::StandardErrorStream
+ | ArenaHeaderTag::PipeReader
+ | ArenaHeaderTag::PipeWriter
};
($tag:ident) => {
ArenaHeaderTag::$tag