From ai@solvo.ru Thu Aug 16 16:25:18 2001
Received: from grace.solvo.ru (root@grace.solvo.ru [195.201.44.100])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f7GEPHb18265
	for <prolog@swi.psy.uva.nl>; Thu, 16 Aug 2001 16:25:17 +0200 (MET DST)
Received: from elbrus (elbrus.solvo.ru [195.201.44.16])
	by grace.solvo.ru (8.8.8/8.8.8) with SMTP id SAA18812
	for <prolog@swi.psy.uva.nl>; Thu, 16 Aug 2001 18:25:15 +0400
Message-ID: <005701c126bb$6663c940$102cc9c3@elbrus>
From: "Lyosha" <ai@solvo.ru>
To: <prolog@swi.psy.uva.nl>
References: <200108160302.PAA62210@atlas.otago.ac.nz> <004b01c12658$e19c9f00$c901a8c0@MINERVA>
Subject: Re: [SWIPL] Q
Date: Thu, 16 Aug 2001 18:24:45 -0700
Organization: Solvo
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
Disposition-Notification-To: "Lyosha" <ai@solvo.ru>
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200

If [] is not a list then I would expect is_list([]) to fail. However it
succeeds, which
of course we can treat as an exception. :)

I have another question about lists though.

?- A is [2].
A = 2

?- A is [4]*[5].
A = 20

I expected to get an exception when using lists in 'is'.
Like I would get if I type:
?- A is [1.2].
ERROR: '.'/2: Type error: `integer' expected, found `1.2'

It's not to be complained about I guess but I am curious - why is it
happening?
Anyone know?

> > "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))))).
>
>
>
> ----------------
> * To UNSUBSCRIBE, please use the HTML form at
>
>     http://www.swi.psy.uva.nl/projects/SWI-Prolog/index.html#mailinglist
>
> or send mail to prolog-request@swi.psy.uva.nl using the Subject:
"unsubscribe"
> (without the quotes) and *no* message body.
>
> ** An ARCHIVE of this list is maintained at
>
>     http://www.swi.psy.uva.nl/projects/SWI-Prolog/mailinglist/archive/

