Re: Substring patch

From: Erik Ostrom <eostrom_at_research.att.com>
Date: Tue, 03 Dec 1996 19:06:17 -0500

> ...Of course, the other huge problem with my substring patch is that
> changing the contents of either string will change the contents of the
> other. I forgot that Scheme strings were not read only.

And also, I haven't checked this, but are substrings adequately
protected from the garbage collector? Consider the following program:

  (let ((substr (let ((str (string-append "hi" "there")))
                  (substring str 2 7)))
    (gc)
    (display substr))

... note that by the time gc is called, str is no longer allocated as
a variable, so there's no longer anything to mark "hithere" in the
garbage collector, so, I think it'll get swept.

This could probably be fixed without too much trouble; making shared
substrings not share changes is harder. It might be better to take
Guile's approach and make the creation of shared substrings an explicit
action, distinct from `substring'. Shared mutable strings can still
lead to debugging nightmares, but oh well.

--
Another approach would be to change the regexp interface.  For example,
regexps could operate on string ports--returning some sort of match
structure and consuming the port as you go.  Not sure this would be
a good idea, but since you're trying to consume the string with your
lexer, and ports are just right for that sort of thing, it's tempting.
I believe an earlier version of the regexp interface returned matches
as procedures, which could then be called to get at the results of the
match.  So you could do something like this:
  (call-with-input-string "98 + 12"
    (lambda (port)
      (let ((r (string->regexp "^[0-9]][0-9]*")))
        ((r port) 'match))))
... which would _return_ "98" (the string matched by r), and leave
" + 12" to be read from the port.
This is a terrible example, because I'm avoiding the question of how
to deal with failed matches (you don't want it to consume the whole
port while it's looking, because then you lose all the advantage of
having it in a port, but how do you _not_ consume it if it's a file
instead of a string?), but I thought I'd throw it out there as another
way of looking at the problem.
--Erik
Received on Wed Dec 04 1996 - 01:08:38 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST