Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageIn 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
Post Follow-up to this messagePatrick 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. :{
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.