Lost in translation
- From: Damien Kick <dkixk@xxxxxxxxxxxxx>
- Date: Tue, 22 May 2007 06:37:50 GMT
Obviously the best way to work towards proficience with Prolog is to start with lisp... I realize that this is only mostly on topic but I felt obligated to post something lisp after having piled onto the flatulent frog fluster cuck. Thought it might be a nice example of some significant macrology, too.
_Prolog: Programming for Artificial Intelligence_ has an example air travel planner program in it, chapter 4.4, "Travel Agent". From that secction:
The program will be centered around a database holding the flight> [ 9:40 / 10:50 / ba4733 / alldays,
information. This will be represented as a three-argument relation:
timetable(Place1, Place2, ListOfFlights)
where ListOfFlights is a list of structured items of the form:
DepartureTime / ArrivalTime / FlightNumber / ListOfDays
Here the operator '/' only holds together the components of the
structure, and of course does not mean arithmetic division.
ListOfDays is either a list of weekdays or the atom 'alldays'. One
clause of the timetable relation can be, for example:
timetable(london, edinburgh,
19:40 / 20:50 / ba4833 / [mo,tu,we,th,fr,su] ]).
From the little Prolog I know, I'm aware of the "[ a, b, c ]" syntax but I had never before encountered this "a / b / c" syntax. This seems to be the first that this book introduces the '/' operator as anything other than division but it only has the above quoted text to explain it. My translation into Allegro's improvement of Norvig implementation of Prolog is as follows:
(<-- (timetable edinburgh london
(((09 40) (10 50) ba4733 alldays)
((13 40) (14 50) ba4773 alldays)
((19 40) (20 50) ba4833 (mo tu we th fr su)))))
What I'm wondering is if I've lost anything in the translation. Is the above use of '/' really just syntactic sugar for using a list of elements as a structure or is there more going of which I'm not aware?
For what it's worth, I've included my translation of Prolog into prolog-in-lisp below. It seems to give some correct answers, so I think I'm on the right track.
(<-- (route ?from-place ?to-place ?day
((?from-place ?to-place ?flight-number
?departure-time)))
(flight ?from-place ?to-place ?day ?flight-number
?departure-time ?))
(<- (route ?from-place ?to-place ?day
((?from-place ?layover-place ?layover-flight-number
?layover-departure-time)
. ?rest-routes))
(route ?layover-place ?to-place ?day ?rest-route)
(flight ?from-place ?to-place ?day ?layover-flight-number
?layover-departure-time ?layover-arrival-time)
(departure-time ?rest-route ?connecting-departure-time)
(transfer ?layover-arrival-time ?connection-departure-time))
(<-- (flight ?from-place ?to-place ?day ?flight-number
?departure-time ?arrival-time)
(timetable ?from-place ?to-place ?flights)
(member (?departure-time ?arrival-time ?flight-number ?days)
?flights)
(day-of-flight ?day ?days))
(<-- (day-of-flight ?day ?days)
(member ?day ?days))
(<- (day-of-flight ?day all-days)
(member ?day (mo tu we th fr sa su)))
(<-- (departure-time ((?from-place ?to-place ?flight-number
?departure-time)
. ?)
?departure-time))
(<-- (transfer (?hour-of-arrival ?minute-of-arrival)
(?hour-of-departure ?minute-of-departure))
(lispp (>= (+ (* 60 (- ?hour-of-departure ?hour-of-arrival))
(- ?minute-of-departure ?minute-of-arrival))
40)))
I haven't bothered to include the timetable database, though...
.
- Follow-Ups:
- Re: Lost in translation
- From: Markus Triska
- Re: Lost in translation
- Prev by Date: Re: The Harrop Index [was Re: Jon Harrop]
- Next by Date: Re: Macros for seriously interested people
- Previous by thread: PLT Scheme v370
- Next by thread: Re: Lost in translation
- Index(es):
Relevant Pages
|