2 ms·
My favourite part of Prolog is that if you ask it if something is in a list it will decide to add it to the list so that it can return true!
by curiousdannii 13y ago
My favourite part of Prolog is that if you ask it if something is in a list it will decide to add it to the list so that it can return true!
- fusiongyro 13y agoYou must be referring to this: ?- member(what, X). X = [what|_G2122] ; X = [_G2121, what|_G2125] ... If what you have isn't a variable, it is totally reasonable: ?- member(what, []). false. This is because, lacking other evidence about what X might be, it can't distinguish between making an assertion about a new quantity ("there is a list X which 'what' is a member of") and a query ("is 'what' in the list?"). Making an assertion like that, however, is pretty normal. It's a perfectly reasonable declarative way to understand this behavior, it's just that this thinking is unusual, so it's weird. Maybe this little demonstration will give the flavor of why you might want this: ?- length(X, 3), member(what, X). X = [what, _G942, _G945] ; X = [_G939, what, _G945] ; X = [_G939, _G942, what].