list


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.

Related Links

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[4]?
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

Categories

HOME
ionic2
webview
artificial-intelligence
bots
key
operating-system
risk-management
semantic-web
tcp
qooxdoo
stored-procedures
u-boot
mutation-testing
bellman-ford
google-awareness
user-defined-types
gravity
salt-cloud
significance
pst
conda
pyopencl
mod-wsgi
jpa-2.1
macromedia
amazon-cloudtrail
ninject
bitbake
openbr
google-play-developer-api
opnet
custom-keyboard
rails-postgresql
swfupload
get-event-store
git-tfs
reverse-dns
docker-ucp
hibernate-ogm
karabiner
openstack-glance
mura
nslayoutconstraint
apache-modules
word-2016
openerp-6
libharu
logical
nsrunloop
system.net.mail
coovachilli
eclemma
static-methods
mercurial-extension
preferenceactivity
voronoi
grinder
largenumber
replicaset
explain
clarion
quercus
nssortdescriptor
ildasm
qt5.4
nidaqmx
windows-messages
boolean-algebra
nosql-aggregation
iosched
assetic
non-ascii-characters
asp.net-mvc-3-areas
wndproc
live-wallpaper
uipangesturerecognizer
fbml
turbine
getimagesize
oracle-pro-c
fuzzy-comparison
rakudo
motif
stretchblt
twitter-feed
chronic

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App