Re: RHS unbound variable



On 6 Feb, 18:20, LudovicoVan <ju...@xxxxxxxxxxxxx> wrote:
On 6 Feb, 14:50, LudovicoVan <ju...@xxxxxxxxxxxxx> wrote:
On 6 Feb, 14:08, Jose Luis <ingenieros.informat...@xxxxxxxxx> wrote:

Hi all,

Maybe, it is a so simple issue, but I am not sure if it is possible
for prolog resolve convert(C, 50) and convert(50, F) with a rule as

convert(Celsius, Fahrenheit) :-
    Celsius is (Fahrenheit - 32) * 5 / 9.

I have read the solution in the Bratko book using { }, but it doesn't
work in SWI-Prolog

convert(Celsius, Fahrenheit) :-
    {Celsius is (Fahrenheit - 32) * 5 / 9}.

Any suggestions?

Thanking you in advance

Hi Jose,

You might simply have two different clauses, checking with the var
predicate whether Celsius vs Farenheit is unbound, and performing the
calculation is the proper direction depending on the case:

    conv(C, F) :- var(C), !, C is ...
    conv(C, F) :- var(F), !, F is ...

FWIW, that's not really correct, in case both C and F are
instanciated. Here is the amended code:

    conv(C, F) :- var(C), !, C is (F - 32) * 5/9.
    conv(C, F) :- F is C * 9/5 - 32.

Sorry: F is C * 9/5 + 32.

-LV

Though the cut is no more green...

-LV



Otherwise, in SWI, you could use Clpqr as follows (although I wouldn't
know how portable it is):

    :- use_module(library(clpr)).

     conv(C, F) :- { C =:= (F - 32) * 5/9 }, !.

(I have added the cuts to avoid unneeded backtracking.)

HTH,

-LV
.



Relevant Pages

  • Re: Calculated Field in a Subform
    ... Ken Snell ... Watts, Total Watts (unbound txt containing Fixture Qty * Watts), ... When I recreate the calculation and refer to column 1, ... control source of the unbound subtotal field is: ...
    (microsoft.public.access.forms)
  • Re: Calculated Field in a Subform
    ... <MS ACCESS MVP> ... Watts, Total Watts (unbound txt containing Fixture Qty * Watts), ... When I recreate the calculation and refer to column 1, ... control source of the unbound subtotal field is: ...
    (microsoft.public.access.forms)
  • Re: Saving a Calculated Values from a Subform
    ... unbound text box and set another event (such as the After Update event of the ... controls that provide the variables for the calculation) to copy that value ... > The 2 fields where I want to store the values are located on the form (not ... > so I am not getting another event triggered on the parent form, ...
    (microsoft.public.access.forms)
  • RE: unbound textboxes do not update(change) in preview mode
    ... If the field are "unbound" they will not recieve the data from anywhere ... If they are based on a result of a calculation from 2 column in the base ... query they will hold that information and they are not really unbound. ... this case they will not refresh with the form. ...
    (microsoft.public.access.forms)
  • Re: Storing calculated field
    ... referred to the calcualtion being performed in an "unbound field". ... If your calculation is to sum two number fields, the text box in which you ... Whether you use the wizard or create your own report, ... you will need to use either a table or query as a record source. ...
    (microsoft.public.access.formscoding)