
Roberto Bagnara writes:
Hi there,
Hi Roberto (and all) -- have a happy new year!
how can bignums be communicated to/from Ciao Prolog? More precisely, since we have [...] It would seem better to define something like
int ciao_to_integer(ciao_term term, long* pl)
so that 0 is returned if the conversion failed (in which case *pl has not been touched), and a number different from 0 otherwise. Bignums could then be communicated with a pair of functions ciao_get_number_chars() and ciao_put_number_chars(). What do you think?
Completely agreed. I have implemented your suggestion, with some slight rewording and an extra function:
/* Check size */ ciao_bool ciao_fits_in_int(ciao_term term);
/* Try to perform conversion and return a success/failure code */ ciao_bool ciao_to_integer_check(ciao_term term, int *res);
/* Make conversion between arbitrary numbers and strings */ char *ciao_get_number_chars(ciao_term term); ciao_term ciao_put_number_chars(char *number_string);
(Comments on the interface, names, etc. are welcome. There are examples of use at /home/clip/Systems/ciao/lib/foreign_interface/examples/bignums).
I can send you the modified files or leave a complete .tgz for you to download; whatever you prefer.
MCL
___________________________________ "Eso" es mi amiga, y tampoco baila.