From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Dirk Herrmann Newsgroups: gmane.lisp.guile.devel Subject: Re: GH replacement proposal (includes a bit of Unicode) Date: Sat, 17 Apr 2004 15:21:15 +0200 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <40812F4B.3080700@dirk-herrmanns-seiten.de> References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1082206808 7098 80.91.224.253 (17 Apr 2004 13:00:08 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 17 Apr 2004 13:00:08 +0000 (UTC) Cc: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Apr 17 14:59:57 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BEpQL-0002c4-00 for ; Sat, 17 Apr 2004 14:59:57 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BEpOq-00059Y-3F for guile-devel@m.gmane.org; Sat, 17 Apr 2004 08:58:24 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1BEpOi-00055p-Ml for guile-devel@gnu.org; Sat, 17 Apr 2004 08:58:16 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1BEpOA-0004HG-6s for guile-devel@gnu.org; Sat, 17 Apr 2004 08:58:14 -0400 Original-Received: from [212.227.126.183] (helo=moutng.kundenserver.de) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BEpO9-0004Dv-CK for guile-devel@gnu.org; Sat, 17 Apr 2004 08:57:41 -0400 Original-Received: from [212.227.126.209] (helo=mrelayng.kundenserver.de) by moutng.kundenserver.de with esmtp (Exim 3.35 #1) id 1BEpO8-0005SP-00; Sat, 17 Apr 2004 14:57:40 +0200 Original-Received: from [80.131.34.201] (helo=dirk-herrmanns-seiten.de) by mrelayng.kundenserver.de with asmtp (Exim 3.35 #1) id 1BEpO6-00025B-00; Sat, 17 Apr 2004 14:57:39 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030821 X-Accept-Language: de, en Original-To: Marius Vollmer In-Reply-To: X-Enigmail-Version: 0.76.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime X-Provags-ID: kundenserver.de abuse@kundenserver.de auth:494e3e4d1bf8dc247959c49e6f1f4215 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:3604 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3604 Hello Marius, in general, a nice proposal. I have some suggestions and comments, though. Marius Vollmer wrote: > - int scm_to_bool (SCM); > - int scm_is_true (SCM); > > Return 0 when SCM is SCM_BOOL_F, else return 1. > I would only provide the scm_to_bool variant. There is IMO no benefit in having two functions which do exactly the same thing. Providing these two might give the impression that there is some difference in them. Further, there is always the question whether scm_is_true checks for any true value or explicitly for SCM_BOOL_T. Things would be clearer if instead of scm_is_true the function provided would be scm_is_false, but given scm_to_bool, I see no reason for providing it. Thus, just leave it with scm_to_bool. >** Integers > > - SCM scm_is_integer (SCM val); > Paul has already commented on the return type typo. > - scm_t_intmax scm_to_signed_integer (SCM val, > scm_t_intmax min, scm_t_intmax max); > - scm_t_uintmax scm_to_unsigned_integer (SCM val, scm_t_uintmax max); > Since ISO-C99 specifies the intmax_t and uintmax_t typedefs, I would prefer to have functions scm_to_intmax and scm_to_uintmax, and have them behave similarly to scm_to_int etc. which you describe below. IMO, the boundary checking feature is somewhat too specific. This does, however, not mean that internally we could not use a helper function / macro that implements the functions in this way. In addition, it may make sense to use the generic type names signed integer and unsigned integer to provide additional functions scm_to_signed_integer and scm_to_unsigned_integer that implement the very general conversion idea that Gary Houston had proposed in http://mail.gnu.org/archive/html/guile-devel/2001-09/msg00290.html. > Convert the SCM value VAL to a C integer when it is representable > and when it is between min and max inclusive, or between 0 and max > inclusive. Signal an error when it isn't. [...] > I think your suggestion that scm_to_ should throw an error if the value can not be represented is good, since such errors shall not go unnoticed. For development convenience, however, I would like to have an easy possibility to figure out whether a value can be represented or not, since it is a lot of fuss for a developer to capture errors. Thus we should consider the following possibilities for extension / modification of your proposal: Alternative 1: * change the functions in the following way: scm_to_ (SCM value, int *success) Instead of signalling an error, *success indicates whether the value can be represented. If *success is 0, the returned value is unspecified. If success is NULL, an error is signalled for the case that the value can not be represented. Alternative 2: * provide the following additional functions: scm_to__2 (SCM value, int *success) I have not yet an idea for a good name, thus I have just added the _2 postfix. Alternative 3: * provide the following additional functions: int scm_fits_ (SCM value); Return 1 if the value can be converted to a C value of type , 0 otherwise. If scm_fits_ returns 1 for some value it is guaranteed, that a subsequent call to scm_to_ does not signal an error. The advantage of alternative 1 is, that it does not add additional functions to the API. Further, it is always clear to the user that the conversion may fail. If the user does not care about failure, it is possible to pass the NULL pointer for the success argument. The advantage of alternative 2 is, that the user may choose whether the error checking is of interest or not. Further, the scm_to_ functions can easily be implemented using the scm_to__2 functions. The disadvantage is, that there are a lot of additional API functions, and that it is not easy to find good names to distinguish between the two kinds of functions. The advantage of alternative 3 is, that the scm_fits_ check may be used as a predicate, even if no actual conversion is desired by the user. The disadvantage of alternative 3 is, that for a lot of code the checking will have to be performed twice: The user will first call scm_fits_ and then scm_to_. Both, however, will check whether the value fits. Thus, I would prefer either alternative 1 or 2, favoring alternative 1. >** Floating point numbers > >We don't go to such a great length to cover all possible types >here. "double" ought to be enough, no? > According to ISO-C99 there are the types float, double and long double. For the moment I agree that double would be sufficient. And, since the naming pattern is quite symmetric, it would not be a problem to extend it to float and long double, if there would be interest in the community. > - SCM scm_from_complex_double (double re, double im); > - double scm_to_real_part_double (SCM z); > - double scm_to_imag_part_double (SCM z); > >But remember to use the generic functions scm_make_rectangular, >scm_real_part, etc if you don't care whether the parts of a complex >number are floating point numbers or not. For example, Guile might >someday offer complex numbers where the real part is a fraction >(currently it is always a double) and it is good to be prepared for >this by not treating the parts of a complex as doubles when it is not >needed. > We should be prepared to provide conversion functions for the new ISO-C99 types float _Complex, double _Complex, long double _Complex, float _Imaginary, double _Imaginary and long double _Imaginary. Thus, the naming scheme used above seems a bit confusing if we later expect a function scm_from_double_complex to be added. What about using the pattern scm_from__r__i if a complex is to be constructed from separately given real and imaginary parts, and scm_from_ if a complex is to be constructed from one value? This would allow for a lot of combinations, e. g. the first function from your proposal would be renamed to scm_from_double_r_double_i, other possibilities could be scm_from_float_complex, scm_from_double_r_imaginary_i etc.. Not that these are needed today, but the naming scheme should from the start be designed to be open for such extensions. >** Characters > >A Scheme character in Guile is equivalent to a Unicode code point. > Yes! > - SCM scm_from_locale_string (unsigned char *str, ssize_t len); > > Return a new Scheme string initialized with STR, a string encoded > according to the current locale. When LEN is -1, STR must be > zero-terminated and its length is found that way. Otherwise LEN > gives the length of STR. > I would prefer to have two functions like scm_from_locale_memory (with an unsigned len argument) and scm_from_locale_c_string rather than using -1 as a magic number. The same holds for the other scm_from_ functions that you describe below. > - unsigned char *scm_to_locale_string (SCM str, size_t *lenp); > > Convert STR into a C string that is encoded as specified by the > current locale. Memory is allocated for the C string that can be > freed with 'free'. > > When the current locale can not encode STR, an error is signalled. > > When LENP is not NULL, the number of bytes contained in the returned > string is stored in *LENP. The string is zero-terminated, but it > might contain zero characters in the middle. > Is the terminal zero counted or not? >The above functions always return newly allocated memory. When that >is deemed too expensive, the following functions can be used instead. >However, care must be taken to use them correctly and reasonably. > > - scm_lock_heap (); > - scm_unlock_heap (); > I urgently suggest that we do not provide such a concept. It makes too many implementation details visible to the user (the way, strings are implemented internally) and has influences on critical system parts (memory management). It is not foreseeable in which way this may inhibit further development. From my work on the evaluator I can tell you how much leaked implementation details inhibit improvements. Best regards Dirk _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel