From jan@swi.psy.uva.nl Tue May 22 20:12:45 2001
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f4MICj313343;
	Tue, 22 May 2001 20:12:45 +0200 (MET DST)
Received: (from jan@localhost)
	by gollem.swi.psy.uva.nl (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) id f4MICj109129;
	Tue, 22 May 2001 20:12:45 +0200
Date: Tue, 22 May 2001 20:12:45 +0200
Message-Id: <200105221812.f4MICj109129@gollem.swi.psy.uva.nl>
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Subject: Re: [SWIPL] How to convert atoms to reals
To: =?iso-8859-1?Q?Jo=E3o?= Mariz <joao.mariz@mail.ineti.pt>,
   Swi-PROLOG usergroup <prolog@swi.psy.uva.nl>
In-Reply-To: =?iso-8859-1?Q?Jo=E3o?= Mariz's message of Tue, 22 May 2001 17:39:57 +0100
Phone: +31 - 20 - 525 6121

> I am sorry for taking your time with such simple questions.

Maybe better to subscribe and post this type of questions to the
xpce-users@swi.psy.uva.nl.  Real Prolog users generally don't like GUI :-)

> However, I am trying to convert code from another prolog interpreter,
> and I am still a newbie in SwiProlog and xpce. Althought I spend several
> hours searching in the users guide for predicates that could resolve me
> this question and I did not succeed.
> 
> So please tell me how can I convert from an atom to a real to preform
> later some calculations? Or where can I find this answers in the Users
> Guide.

There are some paragraphs devoted to type-conversion in the XPCE
User Guide if I recall well.  Searching for `convert' should do the
trick.

> Thanks in advance for any help you can provide,
> 
> Joćo
> 
> Example for the XPCE code,
> 
> ask_number:-
>     new(Dialog, dialog('Ask for a Real')),
>     send(Dialog, append, new(Fi, text_item('Float'))),
>     send(Dialog, append, button(ok, and(message(@prolog,  print_floatn,
> Fi?selection)   ,
> 
> message(Dialog, destroy))
>              )                                       ),
>     send(Dialog, open).
> 
> print_floatn(X):- /* X should be a float */
>    Y is X * 1.1, nl, nl,
>    write('X x 1.1 = ') , write(Y).

There are three ways out:

	* send(Fi, type, real).

Text-items can be send a ->type.  If they have that, an attempt to get
the selection calls the <-convert method of the type.  If this fails 
it raises a warning, normally causing the item to `flash'.

	* Use get(@pce, convert, Old, Type, New):

	?- get(@pce, convert, '1.1', real, X).
	X = 1.1

	* Use native Prolog predicates:
	
	?- atom_codes('1.1', Codes),
	   number_codes(X, Codes).
	X = 1.1

	Cheers --- Jan

