guile-devel
[Top][All Lists]
Advanced

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

Re: typechecking


From: Dirk Herrmann
Subject: Re: typechecking
Date: Sun, 30 May 2004 10:40:09 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.2) Gecko/20040220

Han-Wen Nienhuys wrote:

address@hidden writes:
Code like the following:

void f (SCM obj)
{
 if (obj) {
   /* do something */
 }
}

is almost always wrong, since what the user typically wants to check is, whether obj is SCM_BOOL_F or not:

It would be interesting to see if we could map the Scheme semantics
(true = !SCM_BOOL_F) to C. That would require mapping SCM_BOOL_F to
(void*)0x0. Is this desirable, and does anyone see a possibility for this?

SCM values, where the 3 least significant bits are zero indicate non-immediates. That is, the SCM value can without any modification be used as a pointer to a scm_t_cell object on the heap. This works, since scm_t_cell has at least 8 bytes and thus the heap is constructed such that all scm_t_cell objects are placed on an address that is a multiple of 8.

SCM_BOOL_F on the contrary is an immediate value. To make SCM_BOOL_F == 0x00 would require either to introduce it as a special case and leave otherwise the definitions of non-immediates the same, or to change the type system such that non-immediates are characterised differently. Both solutions, however, would require to perform some operation on every access to the heap. On the contrary, they would make all comparisons against SCM_BOOL_F very simple and also help to avoid some errors.

The effects of such a change are difficult to predict. It may be that it is not too much effort to try it out (at least the special case solution), if everywhere the correct access macros are used (SCM_IMP, SCM_FALSEP, ...). Then, for a try you would only have to change those.

Best regards
Dirk





reply via email to

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