adding quotes to numbers 
Author Message
 adding quotes to numbers

I have a prolog database for geographical information which includes numbers for
populations, areas etc. The database includes a natural language
interface written in Quintus prolog. For various reasons, the query and
answer display is handled by ProXL extensions between Quintus and X and
are displayed on a ProXL graphics window.

My problem is that the ProXL draw_string command for writing text to the graphics
window cannot handle numbers unless they are in quotes.

Sometimes numbers are the answers to queries in their own right, eg, what is the
area of france?, and sometimes they are used to calculate an answer, eg. where is
the largest country?' I also generate numerical answers from queries such as 'how
many rivers are there?', what percentage of countries borders spain?' etc.

I could use string_append to add quotes but string_append also only handles
numbers if they are already quoted.

I can't change the numbers in the database to quoted as that would rule out
doing calculations with them. Neither would it help with calcualted numerical
answers. Similar problems arise when storing numbers as words eg, ten.

Any ideas?

From a design point of view, I'd like to be able to say

is the thing to be written out a number?        (easy)
  if so, put quotes round it first.             (not so easy)

--

Jane

------------------------------------------------------------------------------

School of Computer Science              Tel     021 414 3734
University of Birmingham                Fax     021 414 4281
Birmingham
B15 2TT



Fri, 02 Feb 1996 18:07:46 GMT  
 adding quotes to numbers

...

Quote:
> My problem is that the ProXL draw_string command for writing text to the
> graphics window cannot handle numbers unless they are in quotes.

[I see this as a run-time matter (of type conversion) rather than as a
compile-time matter (of syntax), and I've emailed concrete suggestions.]

I think the whole unfortunate business of atoms/integers/floats is
something which Prolog implementors should be embarrassed about.

There is surely nothing in first-order logic which says "thou shalt
have three disjoint primitive types": it merely simplifies the
implementation.

Prolog would be cleaner and simpler if it had just one 'atom' type,
with arithmetic defined over those atoms which happened to be numeric,
and undefined over the rest.  Whether numeric atoms were represented
internally in twos-complement notation or whatever should be irrelevant
to the Prolog user.  I like to program in terms (no pun intended) of
"constants" (the union of atom, integer and float), and avoid using
or creating any atoms which name/2 would rather represent as numbers.

I am over-familiar with arguments in favour of application-oriented
type systems (I am involved in teaching Pascal to undergrads) and I
don't like seeing Prolog on that slippery slope.  By all means let's
build type schemes for Prolog, but keep the core language minimal.

Paul S.
----


 |  .  __).  Keele University, Newcastle,    tel: +44 (0)782 583477 << NEW for
             Staffs ST5 5BG, ENGLAND         fax: +44 (0)782 713082     1993



Fri, 02 Feb 1996 22:29:30 GMT  
 adding quotes to numbers
Let's talk about Prolog types, not about character strings.
By "quotes around numbers" I presume you mean atoms which
look like numbers.

For instance, '2.3' is an atom and 2.3 is a number.

Interconversion is fairly simple:
  number_atom(N,A) :- number_chars(N,C), atom_chars(A,C).

Thus:
  ?- number_atom(2.3,What), writeq(What).
  '2.3'

You're not _inserting quotes_, you're _changing a type_ there.

--
:-  Michael A. Covington, Associate Research Scientist        :    *****

:-  The University of Georgia              phone 706 542-0358 :   *  *  *
:-  Athens, Georgia 30602-7415 U.S.A.     amateur radio N4TMI :  ** *** **  <><



Fri, 02 Feb 1996 23:05:59 GMT  
 adding quotes to numbers

Quote:

>Prolog would be cleaner and simpler if it had just one 'atom' type,
>with arithmetic defined over those atoms which happened to be numeric,
>and undefined over the rest.  Whether numeric atoms were represented
>internally in twos-complement notation or whatever should be irrelevant
>to the Prolog user.

If you restrict legal integer names (no leading zeros, no signs
on postive integers and between minint and maxint)  there is a one-to-one
mapping between integers and their names.  So, as Paul suggests, it is
feasible to have implement atoms whose names are legal integers as
twos-complement integers internally without this being visible to the user.

Unfortunately there is no such one-to-one mapping for floats.
7.5 and 0.75e1 are both names for the same float.  If you used internally
a floating point representation for atoms whose name is a legal float
then both these atoms would have the same representation.

Andrew Taylor



Sat, 03 Feb 1996 16:06:53 GMT  
 adding quotes to numbers
You can't "put quotes around numbers", in general.  You can however convert
numbers to strings (OK, lists of character codes) and strings to atoms.
Look for built-in predicates like

        atom_chars/2
        number_chars/2
        name/2

Greetings,

        Jens.
--


---------------------------------+---------------------------------------------
As the air to a bird, or the sea to a fish, so is contempt to the contemptible.



Sun, 04 Feb 1996 03:43:02 GMT  
 adding quotes to numbers

Quote:

>I think the whole unfortunate business of atoms/integers/floats is
>something which Prolog implementors should be embarrassed about.

>There is surely nothing in first-order logic which says "thou shalt
>have three disjoint primitive types": it merely simplifies the
>implementation.

>Prolog would be cleaner and simpler if it had just one 'atom' type,
>with arithmetic defined over those atoms which happened to be numeric,
>and undefined over the rest.

In what way would that be different from the current situation?

Quote:
>I am over-familiar with arguments in favour of application-oriented
>type systems (I am involved in teaching Pascal to undergrads) and I
>don't like seeing Prolog on that slippery slope.  By all means let's
>build type schemes for Prolog, but keep the core language minimal.

What do you mean by "application-oriented"?

A type scheme doesn't necessarily complicate the core language, it
may just restrict the class of well-formed programs.
For example, a type system like Goedel's doesn't affect the semantics of
type-correct programs at all - it's exactly the same as for a simple
single-sorted (untyped) logic.  It just makes certain programs
illegal, in much the same way as
        asdrj lekrthi t3^%^&%$&^&^%9 238476238476241`sd,sdkfj
is not a legal Prolog program.

On the other hand, a _module_ system *does* modify the semantics of
the language.  ISO Prolog will have a module system.  Would you throw
it away because it increases the complexity of the langauge?

--



Sun, 04 Feb 1996 11:16:07 GMT  
 adding quotes to numbers

Quote:

>>Prolog would be cleaner and simpler if it had just one 'atom' type,
>>with arithmetic defined over those atoms which happened to be numeric,
>>and undefined over the rest.

>In what way would that be different from the current situation?

You would not have '2.3' and 2.3 as different objects in the same language.

Right now, if I remember the draft ISO standard right, all of the following
are different objects, not unifiable with each other:

   2
   2.0
   '2'
   '2.0'
   '2.00'
   '2.000'  etc.

--
:-  Michael A. Covington, Associate Research Scientist        :    *****

:-  The University of Georgia              phone 706 542-0358 :   *  *  *
:-  Athens, Georgia 30602-7415 U.S.A.     amateur radio N4TMI :  ** *** **  <><



Sun, 04 Feb 1996 13:16:10 GMT  
 adding quotes to numbers

To treat numbers the same way as atoms complicates the language.  The
atoms 'a0' and 'a00' are different just as the atoms '1.0' and '1.00'.
The numbers 1.0 and 1.00 are the same though and are both represented
as the floating point number 1.  So, how shall you do with the test:

      1.0 == 1.00   or if you like   '1.0' == '1.00'

Shall it fail or succeed?

--
Roland Karlsson             SICS, PO Box 1263, S-164 28 KISTA, SWEDEN

Telex: 812 6154 7011 SICS   Ttx: 2401-812 6154 7011=SICS



Sun, 04 Feb 1996 16:05:31 GMT  
 adding quotes to numbers

Quote:
> To treat numbers the same way as atoms complicates the language.  The
> atoms 'a0' and 'a00' are different just as the atoms '1.0' and '1.00'.
> The numbers 1.0 and 1.00 are the same though and are both represented
> as the floating point number 1.  So, how shall you do with the test:

>       1.0 == 1.00   or if you like   '1.0' == '1.00'

I think you are confusing atoms with their source syntax representations
(which is how this thread started :-)

The only property of atoms with which Prolog is properly concerned is
their equality: two atoms are either identical or distinct.

It is certainly useful to add predicates which define a total ordering
of atomic values, and which define arithmetic (integer, floating, rational,
whatever) on some values, but these are "library" rather than "core"
facilities.

Do you think Prolog should also have a primitive DATE type like SQL?

Either floats should implemented as a structure of simpler types, e.g.

        float( Exponent, Mantissa)

or Prolog should have some general, extensible mechanism for adding
(for the sake of efficiency) user-defined opaque types.  I accept
that special-casing 'integer' and 'float' is justified on performance
grounds, as might be the special casing of other types (date, char,
map grid reference, long int, ...)

Quote:
> Shall it fail or succeed?

It succeeds iff the atoms denoted are identical.  

Paul
----


 |  .  __).  Keele University, Newcastle,    tel: +44 (0)782 583477 << NEW for
             Staffs ST5 5BG, ENGLAND         fax: +44 (0)782 713082     1993



Sun, 04 Feb 1996 21:52:02 GMT  
 adding quotes to numbers

 ...

Quote:
> On the other hand, a _module_ system *does* modify the semantics of
> the language.  ISO Prolog will have a module system.  Would you throw
> it away because it increases the complexity of the langauge?

I'd be tempted :-)

Isn't modularity essentially a configuration management issue, not a language
issue?  Couldn't it be handled by source-to-source transformation?

PS



Sun, 04 Feb 1996 21:56:14 GMT  
 adding quotes to numbers

...

Quote:
>>Prolog would be cleaner and simpler if it had just one 'atom' type,
>>with arithmetic defined over those atoms which happened to be numeric,
>>and undefined over the rest.
> In what way would that be different from the current situation?

Atoms would just be functors of arity zero.  Prolog arbitrarily forbids

        3(a,b,c)

There would be no runtime "type" exceptions, just failure.

I didn't say it would be more useful, just cleaner and simpler ...

PS



Sun, 04 Feb 1996 22:01:22 GMT  
 adding quotes to numbers

Quote:


> ...
>> On the other hand, a _module_ system *does* modify the semantics of
>> the language.  ISO Prolog will have a module system.  Would you throw
>> it away because it increases the complexity of the langauge?

>I'd be tempted :-)

>Isn't modularity essentially a configuration management issue, not a language
>issue?  Couldn't it be handled by source-to-source transformation?

There are two parts to a module system: avoiding unintended name
clashes, and enforcing encapsulation. The former is a purely syntactic
issue, and could indeed be handled by a source-to-source
transformation, but the latter isn't. Declaring that a particular type
or predicate is local to the module provides information that an
optimizer can use which would otherwise be impossible to obtain except
via global analysis of the entire program, which is often impractical.

But regardless, it makes sense to standarize on one single module
system rather than having everyone hack up their own.

--



Wed, 07 Feb 1996 00:58:33 GMT  
 adding quotes to numbers

Quote:

> Atoms would just be functors of arity zero.  Prolog arbitrarily forbids

>    3(a,b,c)

Wild_LIFE 0.91 allows it, but only in the case of positive integers.

It does not feel like a stable feature, though.

Cheers, Boris Borcic.



Sat, 10 Feb 1996 21:30:26 GMT  
 adding quotes to numbers
Adding features to any root-sort is a very useful aspect of LIFE,
particularly when using graph-colouring algorithms. Therefore this
will be maintained in the LIFE compiler, and can be implemented in
such a way that very little overhead is incurred, in fact we now have
a unification scheme which is just about as efficient as Prolog on fixed
arity terms, but allows dynamic feature tables to be used at any time.

What is possibly not a stable feature is allowing sub-typing of "int" or
"real" and other data-types. Although I have provided for it the data
structures used in the compiler, I don't know hot to implement it
efficiently.

_______________________________________________________________________________

                                                      Tel: (33) (1) 47.14.28.65
Digital Equipment Corporation                         Fax: (33) (1) 47.14.28.99
Paris Research Laboratory
85, avenue Victor Hugo
92500 Rueil-Malmaison Cedex
FRANCE
_______________________________________________________________________________



Tue, 13 Feb 1996 16:08:32 GMT  
 adding quotes to numbers

Quote:



> > Atoms would just be functors of arity zero.  Prolog arbitrarily forbids

> >       3(a,b,c)

> Wild_LIFE 0.91 allows it, but only in the case of positive integers.

> It does not feel like a stable feature, though.

> Cheers, Boris Borcic.

Wild_LIFE allows it for *all* sorts, including all integers and
floats.  I'm not sure what you mean by "stable".  If you mean, is
it theoretically well understood, then the answer is yes, it is.
It is part of the theory of order-sorted feature terms (see
reference).  There is no difference in term semantics between
numbers, non-numbers, and unbound variables (which all behave
differently from each other in Prolog).  If you mean, can it be
implemented efficiently, see Richard Meyer's message.

Peter

Reference:

"Towards a Meaning of LIFE", Hassan Ait-Kaci and Andreas Podelski,
DEC PRL Research Report 11, June 1991 (send message with subject

----------------------------------------------------------------
Peter Van Roy                      DEC Paris Research Laboratory



Tue, 13 Feb 1996 16:48:01 GMT  
 
 [ 15 post ] 

 Relevant Pages 

1. VPREXX Help? Adding number to string number

2. Involuntary, inconsistent adding of blackslashes to quotes in output from script

3. quote numbers?

4. replace single quote to double quote with an example

5. quote quote reshape v

6. When is a quote not a quote?

7. single-quoted string conversion to triple-quoted string

8. Quote.py - Look up stock quotes

9. Quote.py - Look up stock quotes

10. emacs python-mode quote in triple quote font-lock problem

11. Adding up sets of numbers

12. adding random numbers to input lines

 

 
Powered by phpBB® Forum Software