[Top][All Lists]

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

[Chicken-hackers] The use of the null-pointer and null-pointer? procedur

From: Peter Bex
Subject: [Chicken-hackers] The use of the null-pointer and null-pointer? procedures
Date: Tue, 10 May 2011 15:01:13 +0200
User-agent: Mutt/


I was wondering what use does (null-pointer?) has.
The FFI conversion procedures for c-pointer types already return #f for
NULL pointers, so I don't really see how one could get a null-pointer.

I know there's also the (null-pointer) procedure, but I don't see the
use of that, either, considering the c-pointer conversion procedures
already convert #f to NULL the other way around, too.

It looks like we have two ways to represent the same thing, which seems
a bit redundant.  Also, it's confusing as I've seen mistakes like the

  (let ((obj (some-foreign-lambda-that-returns-a-pointer)))
    (when (null-pointer? obj) (cleanup!) (error "something went wrong"))

The above code will generally just work, UNTIL you get a NULL
pointer.  Then you get an error, but not the one you'd expect:

  Error: (null-pointer?) bad argument type - not a pointer-like object: #f

And of course, the cleanup! procedure is *not* run.

Would it be a good idea to deprecate these procedures?

"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
                                                        -- Donald Knuth

reply via email to

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