#62 Readonly collections

brian Sat 8 Apr 2006

I checked in support for readonly/read-write List and Maps. They both have identical methods:

**
** Return if this List is readonly.  A readonly List is guaranteed to
** be immutable (although its items may be mutable themselves).  Any
** attempt to  modify a readonly List will result in ReadonlyErr.  Use
** rw() to get a read-write List from a readonly List.  Methods
** documented as idempotent may be used safely with a readonly List. 
** This method is idempotent.
**
Bool isRO()

**
** Return if this List is read-write.  A read-write List is mutable
** and may be modified.  Use ro() to get a readonly List from a
** read-write List.  This method is idempotent.
**
Bool isRW()

**
** Get a readonly, immutable List instance with the same contents
** as this List.  If this List is already readonly, then return this.
** Only methods documented as idempotent may be used safely with
** a readonly List, all others will throw ReadonlyErr.  This method
** is idempotent.
**
L ro()

**
** Get a read-write, mutable List instance with the same contents
** as this List.  If this List is already read-write, then return this.
** This method is idempotent.
**
L rw()

I don't think I'm going to do readonly support for Buf. The hit to check for readonly would be too expensive, and I don't think it is all that useful - for the rare cases when you need to guarantee immutability you can just clone the Buf. Do you guys agree?

I haven't bitten off readonly/read-write support for Str. I feel like the same model I did for List and Map should be applied to Str to prevent all the back and forth glue b/w Str and StrBuf - but part of me still cringes at the thought of Str not being guaranteed immutable without calling ro(). What do you guys think? I'm really on the fence on this issue.

andy Sat 8 Apr 2006

List/Map stuff looks good. I think the Buf like that is fine. Not sure about the Str issue - but in alot of cases where I should use a StrBuf I will just use this syntax:

str := "This is some $value"

And that could be optimized to use a StrBuf.

Login or Signup to reply.