[plt-scheme] Tagging primitive types?

From: Erich Rast (erich at snafu.de)
Date: Thu Dec 1 11:15:12 EST 2005

> Erich, are you trying to associate the tags with values, variables, or
> expressions?  If you want to associate a tag with values (in the
> equivalence class generated by eq?) you could use a hash-table stored
> in a parameter or global variable for this.  (If not, I'm unclear on
> what behavior you really want.)

I'm not sure if I understand your answer. Perhaps I didn't express 
myself clear enough---and unfortunately my example was wrong, because I 
used define to set both values, which of course wouldn't work without 
redefining define.

I'm looking for a hack to make an identifier have *two* values. The 
ordinary value is just a normal binding. The second value can be get 
and set only by special functions or macros.

(define a '(1 2 3))
a ==> (1 2 3)        ; ordinary value
(list? a) ==> #t     ; all the 'normal' functions work on the normal 

(tag! a 'TAG) ==> void
a ==> (1 2 3)
(tag a) ==> TAG     ; this is an 'abnormal' function, the getter for 
the second value
(tag! a 'TAG2) ==> void ; tag! is the 'abnormal' setter
(tag a) ==> TAG2
(tagged? a) ==> #t ; tests for the presence of a second value (or 'tag')
(untag a) ==> void
(tagged? a) ==> #f

But I don't know how to do this with a hash table. Consider for example:

(define a '(1 2 3))
(tag! a 'TAG1)
(let ((a '(a b c)))
    (tagged? a))
==> #f

So it's really a second binding, not something global. I was thinking 
about all the syntax information that is apparently dragged around in 
mzscheme and was wondering whether some such under-the-hood mechanism 
can be abused for truly evil purposes like storing additional payload.

Not possible?

Best regards,


Posted on the users mailing list.