There's an array of strings initialized in "type.c" that's indexed by
type tag. The strings are used for printing a value as "#<...>" when
the value has no other output form. A string like "<rational-number>"
can show up in `dump-memory-stats`, even though exact non-integer
numbers don't use that string for printing.

So, as a first cut, a symbol form of each string would probably make
sense as a result from the new function. You might want to make some
adjustments, such as 'number instead of 'rational-number, or maybe you
want to keep the distinction.

Beware of trying to allocate an array of symbols on initialization: New
type tags can get allocated at run time (though an unsafe API), and
allocating symbols after start-up means that they won't be interned in
the space that is shared by across places. So, any symbols allocated
after startup will need to be in a place-specific array. It may be
simplest to fill a place-local array on demand. You'll probably end up
changing "schthread.h" to add a new place-local variable.

At Sat, 26 Mar 2016 17:34:40 -0700, Alexis King wrote:
> Ok, I’m happy to take a crack at it if you think that’s a good approach.
> I am quite comfortable with C, but I have basically no idea how Racket’s
> internals work, so that’d be the real barrier. I think one of the
> less-technical questions would also just be how to expose this
> information in Racket.
> 
> I do think using a number is probably too fragile, but even then, it
> doesn’t matter too much, since somehow there needs to be a known set of
> values for comparisons. Something like (eq? (type-of some-val)
> type:list) needs to be possible, but I’m not sure where type:list should
> go or what it should actually be called.
> 
> > On Mar 26, 2016, at 16:01, Jay McCarthy <[email protected]> wrote:
> > 
> > We could expose the C virtual machine's type tags and that would be
> > O(1) to a unique number. We could define the number as not being
> > stable across executions of Racket or versions, whichever we like
> > better.
> > 
> > If you're uncomfortable with the number, we could combine it with an
> > O(1) hash lookup from the number to a symbol.
> > 
> > I think an extension like this is achievable for someone with a
> > cursory knowledge of C. You should do it Alexis.
> > 
> > --
> > 
> > The numbers are given here in this enum:
> > 
> > https://github.com/racket/racket/blob/master/racket/src/racket/src/stypes.h
> > 
> > The type tag is just called type:
> > 
> > 
> https://github.com/racket/racket/blob/master/racket/src/racket/include/scheme.h
> #L326`
> > 
> > Jay
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-dev/034504BF-6A0B-4158-B389-4DCA0DED6F
> FD%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-dev/56f73db6.c1c1420a.b865e.6995SMTPIN_ADDED_MISSING%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to