From mc@uga.edu Thu Aug 16 15:39:35 2001
Received: from mailbu.cc.uga.edu (malibu.cc.uga.edu [128.192.1.103])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f7GDdYb15296
	for <prolog@swi.psy.uva.nl>; Thu, 16 Aug 2001 15:39:34 +0200 (MET DST)
Received: from archa9.cc.uga.edu (arch9.cc.uga.edu) by mailbu.cc.uga.edu (LSMTP for Windows NT v1.1b) with SMTP id <1.001B4145@mailbu.cc.uga.edu>; Thu, 16 Aug 2001 9:39:33 -0400
Received: from MINERVA (dsl-64-128-248-185.telocity.com [64.128.248.185])
	by archa9.cc.uga.edu (8.9.1/8.9.1) with ESMTP id JAA121030
	for <prolog@swi.psy.uva.nl>; Thu, 16 Aug 2001 09:39:29 -0400
Message-ID: <004b01c12658$e19c9f00$c901a8c0@MINERVA>
Reply-To: "Michael A. Covington" <mc@arches.uga.edu>
From: "Michael A. Covington" <mc@arches.uga.edu>
To: <prolog@swi.psy.uva.nl>
References: <200108160302.PAA62210@atlas.otago.ac.nz>
Subject: Re: [SWIPL] Q
Date: Thu, 16 Aug 2001 09:39:28 -0400
MIME-Version: 1.0
Content-Type: text/plain;
	charset="Windows-1252"
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200




> "Andrew V. Diatchkov" <ad@solvo.ru> wrote:
> Type this:
>
> ?- A = '[]',B=[],A=B.
> A = []
> B = []
> Yes
>
> Why '[]' is [] ?
>
> What did you expect it to be?  It's perhaps more accurate to say
> that [] is '[]':
>     name([], Name), Name = "[]".

There's a very simple reason for expecting [] to be something other than
a 2-character atom.  It denotes an empty list.  Now, you and I know that
[] is an atom even though [ and ] with anything else between them is a
list.  But that's a deliberate (and probably useful) ambiguity in the
language.  It would be more consistent if [] were a list with zero
elements.  In fact however [] is not a list at all; it's an atom that we
use to denote an empty list.


> You will also find that
> X = (a,b),
> functor(X, F, 2),
> X = ','
> comes out true,

This is one of Prolog's three uses of commas, another place where the
syntax trips up beginners.


> and that
> A = '{}', B = {}, A = B.
> comes out true.

Again because {} is an atom with very special properties... {a,b} is
'{}' with  a,b  as its argument, and  a,b  is in turn a joined to b by
the infix operator ','   that is to say it is ','(a,b) just as a+b is
'+'(a,b).  It's a rather sticky piece of syntactic sugar for DCG rules.

All these are very amusing bits of syntactic sugar but hardly obvious to
anyone without great experience with the language.

Ah well... In Fortran and in non-ANSI BASIC, there are hardly any
general syntactic rules, and every different statement is sui generis!
And in Lisp everything has the same syntax (and (it (looks (like
(this))))).


