I’m trying to compare two lists by length and set the output to true or false.
min(List1, List2, output) :-
length(List1, N),
length(List2, M),
output is N<M.
But I keep getting errors, what’s the syntax for the lists?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A couple of problems here; @Enigmativity is right in that you need to make
Outputvariable, butis/2isn’t defined over the operator<(it’s used to evaluate arithmetic expressions such as+, or those that are user defined).Instead, consider the following:
Here,
N < Mis a logical test which either succeeds or fails. IfN < Mis true, implication->directs the interpreter to bind theOutputvariable to the atom'true', else to'false', indicating the length relationship between the lists that you’ve asked for. You can bind anything here as you like, not just atoms.Executing this gives:
If you want
min/3to simply return the smaller of the two input lists, you can try:Executing this on the same example gives: