SWI-Prolog (SWISH): No permission to modify static procedure `(=)/2' -
this question has answer here:
during playing around different list predicates in swi-prolog (swish), trying check if atom a
part of list list1
defined in program list1 = [a,b,c,d]
.
i formulated query member(a, list1).
, expecting along lines of simple 'yes' (just shows in youtube video @ 59:25), instead got warning
singleton variables: [list1]
and error
no permission modify static procedure `(=)/2'
from understand looking online, warning not important here. not understand, however, why error message while a
member of list1
.
i tried in 2 different ways:
1) adding list1 = [a,b,c,d].
program , querying member(a,list1).
(which resulted in error above);
2) passing list1 = [a,b,c,d]
directly interpreter , using same query ( member(a,list1).
), resulted in endless amount of results a
shifted positions in head of list, so:
list1 = [a|_1186] list1 = [_1062, a|_1070] list1 = [_1062, _1068, a|_1076] list1 = [_1062, _1068, _1074, a|_1082] list1 = [_1062, _1068, _1074, _1080, a|_1088]
is specific prolog version using, or missing simple?
edit
i aware similar question posed here , did not manage understand answer (nor question) going things dynamic
have not yet encountered in prolog. looking more general, more 'high-level' answer have found posing question.
i defined in program
list1 = [a,b,c,d].
this not does. define predicate =/2
:
2 ?- write_canonical( (list1 = [a,b,c,d]) ). =(_,[a,b,c,d])
(the ?-
, or 2 ?-
see there, interactive prompt of prolog system; swi prolog in case. whatever goes on line after have typed; , on next line see system's response).
of course tramples on existing built-in definition =
unification predicate. , hence error says precisely that. , yes, is important.
to "define" list in prolog, can define predicate
8 ?- [user]. p([1,2,3,4]).
such can query
9 ?- p(list1). list1 = [1, 2, 3, 4].
and work further list1
,
10 ?- p(list1), member(a,list1). list1 = [1, 2, 3, 4], = 1 ; list1 = [1, 2, 3, 4], = 2 ; list1 = [1, 2, 3, 4], = 3 ; list1 = [1, 2, 3, 4], = 4.
we directly specify list sub-goal of our query,
11 ?- list1 = [1,2,3,4], member(a,list1). list1 = [1, 2, 3, 4], = 1 ; list1 = [1, 2, 3, 4], = 2 ; list1 = [1, 2, 3, 4], = 3 ; list1 = [1, 2, 3, 4], = 4.
making use of predicate =/2
, opposed redefining it, is forbidden.
the above answers 1)
. 2)
, aren't telling whole truth. appear have done, first make query
12 ?- list1 = [a,b,c,d]. list1 = [a, b, c, d].
which fine , dandy; , then make another query,
13 ?- member(a,list1). list1 = [a|_g2181] ; list1 = [_g2180, a|_g2184] ; list1 = [_g2180, _g2183, a|_g2187] ; list1 = [_g2180, _g2183, _g2186, a|_g2190] ; list1 = [_g2180, _g2183, _g2186, _g2189, a|_g2193] .
prolog prompt not repl. don't make definitions @ it. make queries.
Comments
Post a Comment