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.
Misunderstanding of the cons operator
Check if a list is sorted on Scheme
Scala vs F# on List range from 1 to 100000000
Swap two elements from list with specified indices
How to seperate list elements if key is not present using scala?
SML - Alternating Sum Using Pattern Matching
Abstract List Functions in Racket/Scheme - Num of element occurrences in list
Implementing iter for list in F#
How to find numbers from a list, the result are sequences based on a given number?
LISP - is returning lists full of#
How to trim first N elements from in List in prolog
Ocaml Pattern matching not doing as I expect
Delphi - Must I free all elements inside TObject before release itself?
Match List Items in Any Order
Multiline and wordWrap in a List component?
Append integer to global list inside function haskell