Lost in translation



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
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,
> [ 9:40 / 10:50 / ba4733 / alldays,
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...
.



Relevant Pages

  • Re: Inertial-dampening systems
    ... What happens to the inside of the egg? ... >> And I'm getting around ten millivolts in the frog if a 16 tesla field ... Because the time it takes for the current in that magnet to get up to its ... I wasn't talking about an effective surface currect due to electrons ...
    (sci.physics)
  • Re: why not use LISP-imp of Prolog as opposed to Prolog itself?
    ... Lisp has been getting a higher profile lately because of essayists ... Tenth Rule of Programming which states: ... Norvig shows us how to implement Prolog in Lisp. ... instead of Lisp (such as his excellent discussion of natural language ...
    (comp.lang.prolog)
  • Re: Recommended Sources?
    ... > a language) on prolog or lisp. ... Recommendations for learning ... NATURAL LANGUAGE PROCESSING IN PROLOG: ...
    (comp.lang.lisp)
  • Re: Forth and Co - The Return of the Jedi
    ... As was APL if your problems were of a mathematical bent, as was Lisp ... APL, Lisp, Prolog and Forth all have less users now ... it is not just a question of the languages adopted for teaching; ...
    (comp.lang.forth)
  • Fun with DCGs in Allegro
    ... (lemma (cdr body) ... I love being able to weave back and forth between Lisp and Prolog. ... ;;; MM3 headers got to be a little more complicated to express the ...
    (comp.lang.lisp)