[plt-scheme] Tagging primitive types?
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.)
--Carl
On 12/1/05, Erich Rast <erich at snafu.de> wrote:
> Hi,
>
> I have a somewhat strange question. Is there any way to tag any kind of
> scheme expression e (symbol, list, numbers, vectors, etc.) with a list
> of other scheme expressions, such that e behaves just like its untagged
> version, but the tags can be mutated and retrieved at any time? (Not
> exactly a *functional* programming idea, I guess)
>
> Examples, where the printing of tags is omitted:
>
> (define a (tag! '(1 2 3) 'my-tag))
> a ==> (1 2 3)
> (list? a) ==> #t
> (car a) ==> 1
> (cdr a) ==> (2 3)
> (tagged? a) ==> #t
> (tags a) ==> (my-tag)
> (tag! a 'another-tag)
> (tags a) ==> (my-tag another-tag)
> (define b (tag a 'third-tag))
> (tags b) ==> (my-tag another-tag third-tag)
> (tags a) ==> (my-tag another-tag)
> (equal? a b) ==> #t
> (untag a) ==> (1 2 3)
> (tagged? (untag a)) ==> #f
>
> Is that possible?
>
> Best regards,
>
> Erich