chicken-hackers
[Top][All Lists]
Advanced

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

Re: [Chicken-hackers] [PATCH] [CHICKEN 5] Change numerics representation


From: Peter Bex
Subject: Re: [Chicken-hackers] [PATCH] [CHICKEN 5] Change numerics representations
Date: Tue, 9 Aug 2016 20:25:36 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

On Tue, Aug 09, 2016 at 02:15:56PM -0400, John Cowan wrote:
> Peter Bex scripsit:
> Tagged pointers are
> useful because the tag gives them a Scheme-detectable type, so that you
> can write:
> 
> (define (frob? obj)
>   (and
>     (tagged-pointer? obj)
>     (eq? (pointer-tag obj) 'frob)))
> 
> and treat this subset of pointers just like any other Scheme type.

That's not their main usefulness.  The main usefulness is that you can
treat them like any other _pointer_ type, yet they can be kept apart
if you want to by checking the tag.

If all you needed was a pointer object that you can check for its type,
you can wrap it in a record type.

> By contrast, tag-free pointers can't be safely introspected on, so
> polymorphic code can't do anything with them.

My main concern, after giving it some more thought, is that you can't
easily make the FFI check the pointer type, unless you enforce that
pointer tags are somehow either compile-time constants, or also stored
in some global that's directly accessible to the FFI.  There should be
a low-overhead and simple type check, which is also statically
expressible, otherwise one might just as well define their own
foreign type with conversion procedures, so, a record type with the
pointer inside it like this:

(define-record my-pointer contents)

(define-foreign-type my-pointer c-pointer
  (lambda (mp)
    (unless (my-pointer? mp) (error "incorrect type"))
    (my-pointer-contents mp))
  (make-my-pointer))

So perhaps the tagged pointer is not that useful after all...

Cheers,
Peter

Attachment: signature.asc
Description: Digital signature


reply via email to

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