Failing to understand the oddities of the "line" chunk
Alex Tweedly
alex at tweedly.net
Tue Mar 20 13:53:45 EDT 2012
On 20/03/2012 17:17, Pete wrote:
> So I wouldn't vote for a bug report that asked for lines to behave like
> characters in this respect. I would vote for a bug report that asked for
> this situation to be caught as an error (although I think it would have to
> be a run time error not compile time since the start and end points could
> be variables or expressions).
>
> Lost in this discussion is the reason why someone wanted to do this in the
> first place. Alex, I think it was you that started this whole thread - did
> you have a specific reason for wanting to specify a line range with an end
> point before the start or was it just an observation?
>
No, no specific reason to want to do it - it kind of happened by
accident :-)
And it wasn't so much an observation as a question -
can someone give me a rationale for this behaviour so I can deal
with it better ?
What I *wanted* to do was replace line 'x' of someContainer (and
everything after it) by my new data,
so I did the (temptingly logical - but WRONG) thing of
put newData into line x to -1 of someContainer
NB that is simply wrong, because "line -1" means the last line that is
there - not to the end after what I specified :-)
as it happened, the container had x-1 lines in it at the time (including
a trailing line delimiter, just to confuse things), so that became
equivalent to "put newData into line x to x-1 of someContainer"
I knew that what was happening seemed wrong - but couldn't figure out
how or why. Jacque's explanation showed me what I should do - but still
left that niggling feeling of something being a bit odd.
I can get what I wanted in a couple of safe ways
a. delete line x to -1 of t !! inverted range - but AFAIK it does
the right thing with it in all cases
put newData into line 2 of t
b. put newData into line 2 to kInfinity of t -- where kInfinity is
some arbitrarily large constant
I'm not sure what I would vote for now, hence I haven't yet put in a bug
report. Personally, I'd probably like a run-time error, but I suspect
that the need for backwards compatability would prevent that being
feasible.
-- Alex, still hoping for someone to come up with a "more right" answer :-)
More information about the use-livecode
mailing list