From: Damien Kick
Subject: Lost in translation
Date: 
Message-ID: <2dw4i.17895$3P3.1186@newsread3.news.pas.earthlink.net>
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...

From: Markus Triska
Subject: Re: Lost in translation
Date: 
Message-ID: <871wh8g1xv.fsf@gmx.at>
Damien Kick <·····@earthlink.net> writes:

> this "a / b / c" syntax.

That's infix syntax for the term /(/(a,b), c) (functor: /, arity: 2):

 %?- a/b/c == /(/(a,b), c).
 ·@ Yes

That's a bad choice to represent a tuple. It's clearer and cheaper to
use a term like flight(a,b,c). In your Prolog example, infix notation
is used in yet another place:

  %?- a:b == :(a, b).
  ·@ Yes
From: Damien Kick
Subject: Re: Lost in translation
Date: 
Message-ID: <eQT4i.18156$3P3.15038@newsread3.news.pas.earthlink.net>
Markus Triska wrote:
> Damien Kick <·····@earthlink.net> writes:
> 
>> this "a / b / c" syntax.
> 
> That's infix syntax for the term /(/(a,b), c) (functor: /, arity: 2):
> 
>  %?- a/b/c == /(/(a,b), c).
>  ·@ Yes

Ah, I think that what I was forgetting is that '/' only acts as the 
operator for division in the context of 'is', i.e. "X is a/b".  Outside 
of that context, it is a functor like any other.  He could've used 
"a+b+c" just as well (or just as confusingly) as "a/b/c".

> That's a bad choice to represent a tuple. It's clearer and cheaper to
> use a term like flight(a,b,c).

Well, I was personally expecting to see something like flight(a,b,c) 
instead.  Bratko seems to use this <http://tinyurl.com/2m335v> quite a 
bit, though.  The trip planner <http://tinyurl.com/ysqygq> and an eight 
queens solver <http://tinyurl.com/2fded9> being just two examples.  Is 
this not typical prolog style, then?  Either way, it seems like my 
prolog-in-lisp translation indeed did not lose any semantics in the 
translation.

> In your Prolog example, infix notation is used in yet another place:
> 
>   %?- a:b == :(a, b).
>   ·@ Yes

This didn't confuse me, I think, because ':' doesn't already have a 
predefined meaning in prolog.