
String Manipulation Routines
--============_-1268835467==_============
Content-Type: text/plain; charset="us-ascii" ; format="flowed"
Hi,
One of the areas of Poplog that I have often felt was a bit lightweight
is the string manipulation routines. I have forever found myself
writing ugly bits of code like this ...
substring( a, b - a + 1, s )
which just means I want the substring from indexes a to b inclusive, and
things like this
allbutfirst( 2, allbutlast( 2, s ) )
meaning that I want to strip two from the front and back. This gets
ugly when the subexpressions get complex.
By contrast, python has got a very elegant string splicing construct
that looks like
s[ a:b ]
And this gives the same effect as
substring( a, b - a + 1, s )
except that it works on general arrays.
One feature that seems odd at first - but works well in practice - is the
use of negative indices for addressing from the end of an array. So
in Python you would write my second fragment as :-
s[ 2: -3 ]
[The lack of symmetry is due to the use of 0-indexing, incidentally.]
The final straw was reading the REALbasic manual and finding it too has
got the routines I want. REALbasic is a competitor to Visual Basic,
started on the Mac and is now going cross-platform to Windows. It
is immature but is evidently taking over from where HyperCard left off.
I could not suffer this language envy any more :-) So I've written a few
routines, -cut- -allbutcut- and -splice- that give me the power I want.
They work on lists, vectors, strings, words, and general vectorclass
objects. They are general and efficient - but could do with more
testing. However, before I waste my time testing them, I am submitting
them as an attached uuencoded, gzipped, tar archive for general comment.
The running examples above can be written using -cut- as
cut( a, b, s )
and
cut( 3, -3, s )
respectively. [Note that a symmetrical cut has symmetrical arguments,
thanks to the 1-indexing of Poplog. Interpreting -ve indices was a bit
tricky but there is a best answer and I have used it.]
I probably should be posting this to Poplog developers but I thought
it was worth getting some discussion started on the areas Poplog
needs beefing up in. Now Poplog is Open Source we ought to start
thinking collectively about where it needs to go.
I think systems like REALbasic are well worth checking out to get
inspiration. And reading the REALbasic manual made me recall Aaron
Sloman talking about the time Poplog was being named and one suggestion
was SuperBasic. For me, that name encapsulates one of the really
valuable ideas behind Poplog - it is a very friendly, interactive
and super-powered IDE.
So what other languages have features that you really miss in Poplog?
Let's get them into the standard distribution! (I mean, dates? Where
is the date type in Poplog? Doesn't anyone do database programming
apart from me?)
Steve
P.S. As an aside for HP Labs people, the -cut- routines supercedes the
-cutstring- routine.
--============_-1268835467==_============
Content-Type: application/mac-binhex40; name="string_ops.uu"
Content-Disposition: attachment; filename="string_ops.uu"
; modification-date="Mon, 22 Nov 1999 15:36:56 +0000"
(This file must be converted with BinHex 4.0)
<encoded_portion_removed>
--============_-1268835467==_============--