Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

disappearing spaces problem
Here's a problem I'm having in SWI but have also had with LPA (DOS)
and Sicstus and have never understood let alone solved:

If I do		op( 0500, yfy, and).
then		write( a and b )
gives		a and b
but if I do	op( 0500, yfy, & )
then		write( a & b )
gives		a&b
where the spaces either side of the & have gone. I also get this with
pseudo-random other user-defined ops.

I've always assumed it was down to operator precedence but the above
example shows that's not necessarily it. Any clues?

--
Patrick Herring, Sheffield, UK
http://www.anweald.co.uk

Report this thread to moderator Post Follow-up to this message
Old Post
Patrick Herring
09-09-04 01:56 PM


Re: disappearing spaces problem
In article <413ef91e.7691366@usenet.plus.net>, Patrick Herring wrote:
> Here's a problem I'm having in SWI but have also had with LPA (DOS)
> and Sicstus and have never understood let alone solved:
>
> If I do		op( 0500, yfy, and).
> then		write( a and b )
> gives		a and b
> but if I do	op( 0500, yfy, & )
> then		write( a & b )
> gives		a&b
> where the spaces either side of the & have gone. I also get this with
> pseudo-random other user-defined ops.
>
> I've always assumed it was down to operator precedence but the above
> example shows that's not necessarily it. Any clues?

In most Prolog systems write/1 inserts minimal spaces, brackets, etc.
write(a and b) cannot be written as `aandb' as this is a totally
different term.  `a & b' and `a&b' however read back to the same term.
I.e. between characters of different class there is no extra space,
but if the characters would glue together as a single token a space is
inserted.  I'm not sure whether or not the ISO standard forces some
standard space handling on Prolog systems.

`Solve'?  If you want a particular output you've got to rol your
own.  Prolog simply writes terms using Prolog syntax.  write/1 is
actually a weird predicate as it doesn't insert quotes and therefore
there is no quarantee it is a correct Prolog term.  Using it for
printing the content of an atom without quotes is just about the
only sensible use: write('Hello World!').

Cheers --- Jan

Report this thread to moderator Post Follow-up to this message
Old Post
Jan Wielemaker
09-09-04 08:59 PM


Re: disappearing spaces problem
Patrick Herring <ph@anweald.co.uk> wrote:
> Here's a problem I'm having in SWI but have also had with LPA (DOS)
> and Sicstus and have never understood let alone solved:
> If I do		op( 0500, yfy, and).
> then		write( a and b )
> gives		a and b
> but if I do	op( 0500, yfy, & )
> then		write( a & b )
> gives		a&b
> where the spaces either side of the & have gone. I also get this with
> pseudo-random other user-defined ops.
[...]

I actually would "agree" with these spacing rules.

Some people want to write huge temp files containing operators of
various types. Size (and output time) is then a consideration.

If you need odd-ball rules (sorry!:) then you can usually hook your
own print clauses into "print" or something. You can then define
something like:

print(X&Y) :- print(X), write(' & '), print(Y).

Sometime may be called "display". Maybe called something else these days.
I'm getting on. :{

Report this thread to moderator Post Follow-up to this message
Old Post
russell kym horsell
09-10-04 08:59 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Prolog archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:58 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.