[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Nov 22 22:43:52 1999 
Subject:Re: enlarging structures 
From:"Stephen F. K. Leach" 
Volume-ID:991122.06 

Hi Lee,

>Hm. I'm not at all sure a dynamic list would help. I simply wish to
>have a structure indexable - by integer or string - of unspecified
>size, so that it can be added to when needed.

Pop11's datastructures are mainly geared up for a functional style,
primarily for efficiency but also as a matter of style.

Of all of Pop11's built in datastructures, the one that is likely
to meet your needs without change is the property.  See * NEWPROPERTY,
* NEWANYPROPERTY, * NEWASSOC, and * NEWMAPPING for the pre-built
constructors.  The most general and complex is -newanyproperty-.

If what you really want is an extensible 1D array, then Pop11 does
not have exactly what you want.  The best thing to do is implement
it.  It is pretty easy ... (I do not have a Poplog to hand so forgive
me if I make some errors.)

defclass lconstant exvector {
     in_use   : pint,
     capacity : pint,
     data
};

define new_exvector();
     consexvector( 0, 0, nullvector )
enddefine;

define lconstant ensure_capacity( n, ex );
     lvars ( i, c, d ) = ex.destexvector;
     if c < n then
         {% d.explode, dupnum( undef, n - c ) %} -> ex.data;
         n -> ex.capacity;
     endif
enddefine;

define add_exvector( x, ex );
     lvars ( i, c, d ) = ex.destexvector;
     if ex.capacity == ex.in_use then
         ensure_capacity( d.datalength * 2 + 8 );
     endif;
     x -> subscrv( i + 1 ->> ex.in_use, d )
enddefine;

define index_exvector( n, ex );
     lvars ( i, _, d ) = ex.destexvector;
     subscrv( fi_check( n, 1, i ), d )
enddefine;

define updaterof index_exvector( v, n, ex );
     lvars ( i, c, d ) = ex.destexvector;
     unless n <= i do
         ensure_capacity( n, ex );
     endunless;
     v -> subscrv( n, ex )
enddefine;

And so on and on ....

However, the fact that Pop11 does not have extensible vectors
built-in should be a big clue that this is not the usual programming
style used.  Perhaps Lee could post a reply indicating the overall
context that this came up.  I think it would be interesting to
compare and contrast the styles of programming.  My 50p says that
what Lee "should" be using is the stack and lists.

Actually, I think not having built-in extensible vectors is a pity.
I have argued in that past that one of Pop11's great strengths is
the ability to mimic the programming styles from other languages.
However, the omission of extensible vectorclass objects is a bit of
a killer for people coming from a Perl (or Basic) background.

Perhaps we should add extensible vectorclass objects to our list of
things to add to Poplog now it is Open Source?  After all, one would
like it to behave properly with regard to things like -length-,
-copy-, and the garbage collector and so on ...

Steve