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

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

Categories

HOME
cocoapods
libgdx
apache-nifi
list
blast
windows-8.1
kendo-dropdown
windows-10
dafny
out-of-memory
tabs
dependencies
tfs2015
lapack
documentum
temperature
l20n
varnish-vcl
xsl-fo
activeadmin
pst
uislider
function-points
react-dnd
mod-wsgi
opentext
managed-c++
network-analysis
ibm-connections
microprocessors
xenapp
toad
premake
netbios
steam-web-api
bootstrap-sass
orchardcms-1.8
des
landscape
cheat-engine
coverage.py
notesview
git-tfs
flume-twitter
jenkins-slave
sonarqube5.2
maven-jaxb2-plugin
wikimapia
lvalue
.when
word-2016
emf-compare
multi-touch
okio
jpda
between
node.js-connect
qpixmap
okta-api
openmrs
ioexception
wepay
stack-smash
lowercase
calcite
sqlbase
replicaset
textscan
clarion
console.log
nsmutabledata
lifetime
prism.js
meteor-collections
django-sites
armv6
lru
statechart
contextswitchdeadlock
telerik-ajax
image-scanner
pcspim
uipangesturerecognizer
wiktionary
asio
vows
upshot
asp.net-mvc-views
tessellation
jboss-mdb
html-generation

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App