![]() |
![]() |
|
home—info—lectures—exams—hws—archive
Ned's notes: http://www.radford.edu/nokie/classes/380/p.html
fam-tree in slides: http://www.horstmann.com/sjsu/cs152/19-prolog1.html
tutorials: http://www.learnprolognow.com
http://www.amzi.com/AdventureInProlog
jlog, a web interpreter: see hints on Running JLog
- facts vs rules (and starting /usr/local/bin/xsb on a rucs terminal)
To load a file family.P from the xsb prompt, type:
[family].
- a standard family-tree example: 'father(X,Y) :- male(X), parent(X,Y).'
- have them take a crack at 'grandfather', w/ a partner.
- talk/reflect about how this is declarative programming
(just saying 'prolog searches for all solutions', without saying more);
- a recursive rule: 'ancestor'.
- have them take a crack at writing with a partner:
- 'father*' (generalized grandfather; call 'ancestor')
- 'sameLastName' (or, 'sameYChromosone'): check for male-only lineage
- briefly show a tracing of the search (w/o worrying 'bout the search alg)
- talk/reflect about how you can view parameters as input or output params.
- facts *are* just rules w/o variables.
If time:
- singleton variables; using '_' for 'don't-care'
- an example on processing a list: I do some, they do some:
removeOnce( Target, Data, Result ) (search)
contains(Target, Data) (search)
isAllEvens(Data) (search)
filterEvens(Data,Result) (filter)
squareEach(Data,Result) (map)
sum(Data,Total) (fold)
- talk/reflect about matching of sub-lists, in variables. Write 'third'.
(how cool is that?!
Cool enough that other languages copied it: e.g. http://www.radford.edu/itec380/2009fall-ibarland/Lectures/matching.ss )
(Myself, I prefer avoiding or at least downplaying arithmetic, in the first lecture. I do that after talking about the order of rules, which I also usually avoid /don't-get-to on the first day.)
home—info—lectures—exams—hws—archive
| ©2009, Ian Barland, Radford University Last modified 2009.Nov.16 (Mon) |
Please mail any suggestions (incl. typos, broken links) to ibarland |
![]() |