To find maximum and minimum of a list in prolog
domains list = integer*//shows error in swish saying "syntax error operator expected" Max = integer predicates maximum_no(list,integer) clauses maximum_no(,Max):- write("Maximum No in List is:: ",Max),nl. maximum_no([H|T],Max):- H>Max, N = H, maximum_no(T,N). maximum_no(L,Max):- maximum_no(L,Max). Can someone please tell me how do I solve this error ? I do find the code is correct but it still says an error? I also have to write the code to find the minimum number of a list!!
The following alone works in order to find the max of a list : % the maximum of a list of one element is this element maximum_no([X],X). % the maximum of a list is either the head or the maximum of the tail % depending on if the head is lower than the max of the tail. maximum_no([H|T],Max):- maximum_no(T,Max), H #< Max. maximum_no([Max|T],Max):- maximum_no(T,M), M #< Max. Then, finding the min of a list shouldn't be too complicated.
Zenity - different returned values
Removing value from range
Creating a new prolog list using existing elements
Groovy/Grails: Declaring a JsonBuilder inside a loop without overwriting previously generated jsons
Haskell Trouble with Lists
Scala: split Map size n to List(Maps max size 3)
Scheme function to reverse a list
Are List and List<String> the same in Groovy?
What is the syntax logic behind: typedef char AirportCode?
Adding element to scala set which is a IMMUTABLE map
heterogeneous lists through flexible types
Outputting a string result from a list [closed]
Converting a Map to a List in Scala without map keys?
Haskell: pass tuple and secondary value into Boolean-Returning Predicate for “any”?
Changing a for loop to a while loop in Python
Erlang creating list by splitting a list of tuples