[plt-scheme] string properties

From: Neil W. Van Dyke (neil at neilvandyke.org)
Date: Sun Jun 20 19:04:53 EDT 2004

ifconfig writes at 01:05 21-Jun-2004 +0200:
> How about
> (define-struct unreal-string (str secret))
> and extending string-procedures to support it?

Sorry, I realize I didn't explain well.

The library I am writing currently has a record type analogous to your
"unreal-string", which contains a normal string plus cached results of
expensive parsing of string.

The library has many procedures that accept either a string or
"unreal-string" and yield an "unreal-string".

The problem with an "unreal-string" is that, although it might as well
be a string in the conceptual model of a user of my library,
"unreal-string" cannot be treated like a string: it doesn't display as a
string, it can't be used in "string-append", etc.  Users have to use
"unreal-string->string" whenever they want a string from an
"unreal-string".

So I'd like to have the library's procedures accept and yield only
strings, but secretly associate "unreal-string" objects with the strings
to cache parse results and avoid gross inefficiency.


Posted on the users mailing list.