5 views

Uploaded by JatarAtalaMorenoLacalle

Tutorial about Prolog

Tutorial about Prolog

© All Rights Reserved

- DieQuote_Generator.pdf
- Sudden Python - Tutorials
- SIMATIC S5-115U
- C++ Practical File Complete
- Models Env Corr
- R2HTML
- Digsilent Dpl Tutorial
- Scheme_Book.pdf
- Excel Lab4 Correctlsdkqsmlkion
- tdl
- Space Invaders _ Explore MIT App Inventor
- Python Scientific.pdf
- Consum Program
- 24 TO 28 last
- HC900 Function Block
- Scott_314
- Nintex-PerfImpr-WorkflowProgressTable
- Alevel Computer Science (Pseudocode Notes)
- Inportatn Matlab Functions
- Lab_10_Sp18_208A

You are on page 1of 15

Lists

Lists

[x, 2+2, [a, b, c]] is a list of three elements.

The first element in the list is its head.

The list with the head removed is the tail.

The tail is [2+2, [a, b, c]]

Lists

[a, b, c] = [X, Y, Z]

results in X = a, Y = b, Z = c

[a, b, c] = [Head | Tail]

results in Head = a, Tail = [b, c]

[Head|Tail].

Empty lists will not match [Head|Tail].

a = Head and [b, c] = Tail

If [a, b, c] = [X, Y | Tail], then

a = X, b = Y, and [c] = Tail

If [a, b, c] = [X, Y, Z | Tail], then

a = X, b = Y, c = Z, and [ ] = Tail

The tail of a list is always itself a list.

[X | Y, Z] isnt legal.

parameter as an output variable.

Better: first([Head | Tail], Head).

much of the needed work

first([X | _ ], X).

second([ _, X | _ ], X).

third([ _, _, X | _ ], X).

between structures and lists:

This isnt usually very useful

Recursion

element(1, [X | _ ], X).

element(N, [ _ | X], Y) :M is N - 1,

element(M, X, Y).

This is the typical way to process lists: do something

with the head, recur with the tail.

member

member(X, [X | _ ]).

member(X, [ _ | Y]) :- member(X, Y).

As usual, base cases go first, then recursive cases.

There is in general no need for a fail case, because

the predicate automatically fails if no clause is

matched.

member(_, [ ]) :- fail.

Accumulated Information

clauses of the same predicate have failed.

member(X, [X | _ ]).

If you fail this clause, the first element is not the one

you want, so

member(X, [ _ | Y] :- member(X, Y).

call

exit

redo

fail

loves(chuck, X)

call

fail

female(X)

rich(X)

exit

redo

10

Fail Loops

fail.

print_elements(Tail).

11

notice_objects_at(Place) :at(X, Place),

write('There is a '), write(X),

write(' here.'), nl,

fail.

notice_objects_at(_).

12

loves(chuck, X) :really_ugly(X), !, fail.

13

This is usually what we want.

But sometimes we want to ignore failure (meaning,

force the predicate to succeed).

optional_buzz_off :buzz_off.

optional_buzz_off.

14

The End

15

- DieQuote_Generator.pdfUploaded byovidius1ru1616
- Sudden Python - TutorialsUploaded byAuliya Sant
- SIMATIC S5-115UUploaded byfady
- C++ Practical File CompleteUploaded byKevin Alluvalia
- Models Env CorrUploaded byahmed_497959294
- R2HTMLUploaded byertertre
- Digsilent Dpl TutorialUploaded byAsimenia Korompili
- Scheme_Book.pdfUploaded byvidyan
- Excel Lab4 CorrectlsdkqsmlkionUploaded byAzza Allouch
- tdlUploaded byRakesh Rangan
- Space Invaders _ Explore MIT App InventorUploaded byAriyanto Ari
- Python Scientific.pdfUploaded byhilbert69
- Consum ProgramUploaded bySachin Karekar
- 24 TO 28 lastUploaded bysamiahmedmansour
- HC900 Function BlockUploaded byKan Chora
- Scott_314Uploaded byMike
- Nintex-PerfImpr-WorkflowProgressTableUploaded byapcsaba
- Alevel Computer Science (Pseudocode Notes)Uploaded bySyed Ali
- Inportatn Matlab FunctionsUploaded byZack Obega
- Lab_10_Sp18_208AUploaded byPrabhjot Kaur
- n TheoremUploaded byALBERTO314
- Tutorial_2.pptUploaded byBhavik Mody
- 4/4/12 330 Hudson WorkflowUploaded byJenny May Ratner
- CRnQ,CRnD - Instruction Manual (Detailed Explanations) BFP-A8661-AE (02.15).pdfUploaded bypaulo
- The Best Explanation of Python Decorators I’Ve Ever Seen.Uploaded byPavankumar Karedla
- AspenPropertiesToolsV7 2 RefUploaded byAkk Kol
- CS8151 Unit III NotesUploaded byGunasekaran K AP/CSE-TKEC
- Otu BaseUploaded byJakub Kreisinger
- spto_cm_751906_ENb.pdfUploaded bywiyatno
- Explanations of Data Structure in PDFUploaded byStephanie

- 1304.2215v1Uploaded byAbdul Qadir
- 4985.Practical Optimization. Algorithms and Engineering Applications by Andreas AntoniouUploaded byRuby Chan
- Array ClusterUploaded byrai_mahi7487
- Newton HandoutsUploaded byChris Jerome
- Java PrintingUploaded byLector Pross
- Chapter 9 Hand OutUploaded byAnonymous 7qqXzdtLI
- Travelling Salesman ExplainedUploaded byBalaji MT
- Simplex MethodUploaded byNoor Shafiqaryana Mohammad
- GraphTheoryUploaded byascarb
- tutorial-lex-yaccUploaded bySumanth S Murthy
- Genetic Algorithm Beggin ErsUploaded byLe Professionist
- 1[1]dfsalgoUploaded bynamrata2009
- External Line ClippingUploaded byGovindray Naik
- The Barzilai and Borwein Gradient Method for TheUploaded byRaymath Ben
- Object Oriented Programming (OOP) - CS304 Power Point Slides Lecture 32Uploaded bySameer Hane
- 7 GraphUploaded byirinarm
- Placmnt AdviceUploaded bySri Badma
- Sudkamp SolutionsUploaded byAdil Ahmad
- Optimization Methods SyllabusUploaded byHimanshu Mishra
- Auto PilotUploaded byradhiwibowo
- Oracle DatatypesUploaded byRathish Kumar
- Physics investigatory project on Logic GatesUploaded byNeęrʌj Jʌîswʌł
- ID3 Java ProgramUploaded byReshma Hemant Patel
- Course Plan Discrete MathematicsUploaded byZain Chishti
- Introduction Programming LanguageUploaded byRonnie Galapin
- Binomial CoefficentUploaded byHarsh Tibrewal
- [Doi 10.1109%2Fsaint.2010.60] Ruse, Michelle; Sarkar, Tanmoy; Basu, Samik -- [IEEE 2010 10th IEEE_IPSJ International Symposium on Applications and the Internet (SAINT) - Seoul, Korea (South) (2010.07.Uploaded bykaushal4053
- ShortestPathsUploaded byShivam Pandey
- Hamming Codes Matlab SimulinkUploaded byAnonymous oP3Hdx
- DAA LAB PRGRAMS.pdfUploaded byprabhu