[plt-scheme] immutable? and numbers

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Sep 17 09:23:29 EDT 2008

On Sep 17, Matthew Flatt wrote:
> At Tue, 16 Sep 2008 17:37:14 -0300, "Gustavo Massaccesi" wrote:
> > I tried this:
> > 
> > --------
> > Welcome to DrScheme, version 372 [3m].
> > Language: Textual (MzScheme, includes R5RS) custom.
> > > (immutable? 5)
> > false
> > >
> > --------
> > 
> > I was surprised because it returns #f and not #t.
> > 
> > It is the correct behaviour, according to the manual. But, since it is
> > impossible to mutate 5, it is not the result I expected.
> 
> Agreed. `immutable?' really should have been called something like
> `immutable-variant-of-datatype-that-could-be-mutable?'.

Perhaps simpler organization would be to have a `mutable?' with a
similar implementation (rough, half-guessed sketch):

  static Scheme_Object *
  mutablep (int argc, Scheme_Object *argv[])
  {
    Scheme_Object *v = argv[0];
      return (!SCHEME_INTP(v)
              && !SCHEME_IMMUTABLEP(v)
              && (SCHEME_VECTORP(v)
                  || SCHEME_BYTE_STRINGP(v)
                  || SCHEME_CHAR_STRINGP(v)
                  || SCHEME_BOXP(v)
                  || SCHEME_HASHTP(v)))
            ? scheme_true
            : scheme_false;
  }

then define `immutable?' in terms of that?

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.