guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: scm_num2float() ?


From: Dirk Herrmann
Subject: Re: scm_num2float() ?
Date: Tue, 4 Sep 2001 21:32:27 +0200 (MEST)

On 4 Sep 2001, Michael Livshin wrote:

> Dirk Herrmann <address@hidden> writes:
> 
> > 1) Type conversion for some C type T requires the conversions T->number
> > and number->T.  The number->T conversion should do some range checking to
> > see, whether the number fits into the desired range.  From a C programmers
> > view, however, it should be possible to check in advance whether a
> > conversion number->T would work, because otherwise it is necessary to set
> > up an error catcher or do the range check by hand, using some scm_less_p
> > checks.  Since this is inconvenient, IMO together with the conversions
> > T->number and number->T we should provide some number_fits_into_T_p
> > predicate.  (Then, again, one could argue that number->T wouldn't need to
> > do the range checks, because the user is responsible for doing them.  
> > Another alternative is to provide two variants of the number->T conversion
> > function:  A type and range checking one, and one that does no
> > checks.)
> 
> another alternative is to provide, together with the simple number->T
> function, a more flexible function like
> 
> int scm_num2foo_ext (SCM num, foo *res);
> 
> which would return 1 on success and 0 on failure.  then the
> `scm_num2foo' thingies would just wrap those.

Yes, that's probably the best solution:  It avoids to execute code twice,
since in many cases the checks for a successfull conversion need to
perform some code that the actual conversion also needs.  This way there
would be only three conversion functions per C type.  However, this would
still give 42 functions (instead of 21 if we use the reduced set of
conversion functions).

Best regards
Dirk Herrmann






reply via email to

[Prev in Thread] Current Thread [Next in Thread]