Handling of final delimter (was Re: "this me"?)

Ben Rubinstein benr_mc at cogapp.com
Thu Aug 8 13:45:30 EDT 2013


On 08/08/2013 14:44, Mike Kerner wrote:
> I would LOVE to discuss fixing the bizarre way empty last items are
> treated, starting with either having a preference to modify the behavior,
> separate functions/commands, or tweaking the database library so I don't
> have to deal with this all the time.

Hi Mike,

OK, I'll bite - you keep bringing this unrelated item into the discussion, 
time to put you out of your misery!

This comes up from time to time.  Opinions differ. Here's my take on it (a 
direct lift - thankfully cropped - from a message I wrote a couple of years 
ago - which was neither the first nor the last discussion...)

I think the return (or equally the comma when dealing with items) doesn't 
"belong" to the line that it terminates (as I tend to think of it) - or indeed 
to the line that follows it (as perhaps you do); it is, indeed just a 
delimiter.  It is mandatory to mark the boundary between two lines; it is 
optional at the end of the text.  Therefore one return at the end of some text 
(preceded by a character other than a return) is optional, makes no difference 
to the count of lines.  Two at the end of the text define an empty line 
between the two.  A container consisting just of a single return has one line 
- in effect, it's the empty line between the start of the container and the 
comma.  A container consisting of just two returns has two lines.  When 
extracting one or more lines from a container, the return is included only 
between the returned lines.

It's easier to see with items, and I think it is consistent:

number of items in ","  ---> 1
number of items in ",,"  ---> 2
number of items in ",,a"  ---> 3
number of items in ",,a,"  ---> 3
item 2 to 3 of "a,b,c,d"   ---> b,c

If you take this model:
- that the delimiters are not part of the chunk, but serve only to split text 
into two chunks;
- that if there is no text following the delimiter, there is a chunk before it 
not after it;
- and that the delimiter's appearance at the start of text indicates an empty 
chunk before it;

are there any examples of LC behaviour which are inconsistent with it?

Ben




More information about the use-livecode mailing list