Re: disappearing spaces problem

From: Patrick Herring (ph_at_anweald.co.uk)
Date: 10/03/04


Date: Sat, 02 Oct 2004 22:08:49 GMT

Jan Wielemaker <jan@ct.xs4all.nl> wrote:

| 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!').

Just got round to trying this out. My understanding of Prolog has
improved by one whole leap slash bound. Thanks!

I suspect I've been spoilt by languages which tend to treat anything
in characters as a physical object, like typewriters and malloc
routines do.

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


Relevant Pages

  • Re: Accented letters
    ... The same question applies to the apostrophe sign (ASCII code 39). ... So far, I have been unable to scan these special characters, ... other Edingurgh compatible Prologs, in Poplog Prolog. ... In a string the string quote character ...
    (comp.lang.pop)
  • Re: disappearing spaces problem
    ... In most Prolog systems write/1 inserts minimal spaces, brackets, etc. ... I.e. between characters of different class there is no extra space, ... I'm not sure whether or not the ISO standard forces some ... actually a weird predicate as it doesn't insert quotes and therefore ...
    (comp.lang.prolog)
  • Re: Non-Blocking reading from terminal
    ... I am new to this group and, first of all, i want to congratulate ... all of you for the really nice information about Prolog you manage. ... reading and put the characters in a message queue. ...
    (comp.lang.prolog)
  • Re: term into List
    ... > Is there any built-in predicate in prolog that ... > changes term into a list of characters. ...
    (comp.lang.prolog)
  • Re: Defining your own operators
    ... op(602, xfx, |-) ... > Also, quotes do the trick ... > Prolog. ...
    (comp.lang.prolog)