I am using SWI-Prolog and am confused why the option library would be written to give the following outputs:
?- option(a(A), [a=1, a=2, a(3)]).
A = 3.
?- option(b(B), [b=1, b=2]).
B = 1.
I would expect A=1 ... Looking through the option library code though, this result is clearly intended (git link), but why is this not a bug?
option(Opt, Options) :- % make option processing stead-fast
arg(1, Opt, OptVal),
nonvar(OptVal), !,
functor(Opt, OptName, 1),
functor(Gen, OptName, 1),
option(Gen, Options),
Opt = Gen.
option(Opt, Options) :-
get_option(Opt, Options), !.
get_option(Opt, Options) :-
memberchk(Opt, Options), !.
get_option(Opt, Options) :-
functor(Opt, OptName, 1),
arg(1, Opt, OptVal),
memberchk(OptName=OptVal, Options), !.