For Programmers: Free Programming Magazines  


Home > Archive > Prolog > September 2004 > disappearing spaces problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author disappearing spaces problem
Patrick Herring

2004-09-09, 8:56 am

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
Jan Wielemaker

2004-09-09, 3:59 pm

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
russell kym horsell

2004-09-10, 3:59 am

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. :{
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com