the number of items

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, LCMark

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2902
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: the number of items

Post by mwieder » Wed Aug 14, 2013 10:09 pm

@runrevmark-
Even though you can't represent the list of one empty item with itemSeparator as posed?
You mean like this?

Code: Select all

put the number of items in ""
That's 0 now, and it stays 0 no matter whether you set the itemdelimiter or itemseparator.
And yes, it's a bit of a conundrum, but that's the current situation.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5225
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: the number of items

Post by jacque » Wed Aug 14, 2013 10:37 pm

mwieder wrote:@runrevmark-
Even though you can't represent the list of one empty item with itemSeparator as posed?
You mean like this?

Code: Select all

put the number of items in ""
That's 0 now, and it stays 0 no matter whether you set the itemdelimiter or itemseparator.
And yes, it's a bit of a conundrum, but that's the current situation.
So, "" is zero items, and "," is two items. What's one item?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2902
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: the number of items

Post by mwieder » Wed Aug 14, 2013 11:35 pm

@Jacque- That's rhetorical, right?

Code: Select all

put the number of items in "hello"
That's a little like asking "if there are no words in an empty string and two words in a two-word string, what's a one-word string?"
A delimiter doesn't create items, it just allows you to specify where one ends and another begins.
"hellobucko" is one item, "hello,bucko" is two.

But ah... I see you're asking about empty items. Yeah, that could be a sticky point. Right now "," is one empty item. And still is, if you don't set the itemSeparator to comma.

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1561
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: the number of items

Post by monte » Wed Aug 14, 2013 11:48 pm

Hey guys... I'm wondering if we do stay with the status quo wether the engine should be adding trailing delimiters for us. Here's a code example:

Code: Select all

on mouseUp
   local tTest
   put empty into item 2 of tTest
   put the number of items of tTest -- puts 1
end mouseUp
If the engine ensured the trailing delimiter for us then the code would return the correct result.

delete should probably also ensure a trailing delimiter to make sure deleting item -1 doesn't delete item -2 also...
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

geoffcanyon
Posts: 53
Joined: Thu Aug 15, 2013 9:25 am

Re: the number of items

Post by geoffcanyon » Thu Aug 15, 2013 10:02 am

Setting aside backwards compatibility for a moment, I had a thought about delimiters in general that I thought was interesting, so here goes:

Several people have debated about the number of items. How many items are there in ""? in "test"? in ","? etc. There are two ways to define items: by the delimiters, and by the stuff between the delimiters. Since ",,," contains >0 items, it seems clear that empty is a valid item. It could be dependent on the delimiters as well, but the question of how can be prickly and unintuitive. But if it doesn't depend on the delimiters, then "" is also a valid item. This has a clear analog in SQL where NULL is different than empty, and vice versa. It does mean that there is no such thing as a "list" with 0 items (until we get something equivalent to NULL, anyway) but set that aside for the moment (not talking about backwards compatibility yet).

Now consider words. How are words different than items? The dictionary says, "A word is delimited by one or more spaces, tabs, or returns..." Here's the twist: instead of thinking of the delimiter for words as being any run of whitespace (which I did until a few minutes ago), instead, limit it to just one character, the same way as items. There is still the difference that the character can be one of several, but that doesn't matter for this. The question is, is it possible to get the same sort of results -- count of words, word chunks, etc. -- without resorting to bulking up delimiters to multiple characters? The answer is yes, and it has interesting implications for items. To make words still work properly, instead of changing the delimiter, change the definition of word: a word cannot be empty -- or, empty is not a word. The end result is that words snap back into place: "" is 0 words. "test" is 1 word. " test " is 1 word. Word 2 to 3 of " test this thing " is "this thing" etc.

Now, abstract that concept as an attribute of setting the delimiter -- any delimiter. Specifically: any definition of chunks includes a list of delimiters, and whether or not empty qualifies as a chunk. Under this definition, current items would be: "delimit by comma, empty is a chunk." That means:

"" is 1 item
"," is 2 items
"test," is 2 items
"test, " is 2 items
",test," is 3 items
",,," is 4 items
" , , , " is 4 items

For comparison, if the definition is: "delimit by comma, empty is not a chunk," then:

"" is 0 items
"," is 0 items
"test," is 1 item
"test, " is 2 items
",test," is 1 item
",,," is 0 items
" , , , " is 4 items

Consider how this dovetails with words, where the definition is: "delimit by any of space, tab or return, empty is not a chunk" Then:

"" is 0 words
" " is 0 words
"test " is 1 word
"test b" is 2 words
" test b " is 2 words
" " is 0 words
" a a a " is 3 words

This concept seems simple, powerful, predictable, and comes pretty close to present behavior. I particularly like the idea of "words" not being special, but just being a delimiter/chunk variation.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2234
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: the number of items

Post by [-hh] » Thu Aug 15, 2013 11:09 am

..........
Last edited by [-hh] on Wed Aug 13, 2014 1:28 pm, edited 1 time in total.
shiftLock happens

geoffcanyon
Posts: 53
Joined: Thu Aug 15, 2013 9:25 am

Re: the number of items

Post by geoffcanyon » Thu Aug 15, 2013 1:24 pm

Sorry, I just assumed that -- as is already (nearly) the case, the boundaries of the string are inherent delimiters. "test" would be 1 item or 1 word under all the definitions I listed.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2234
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: the number of items

Post by [-hh] » Fri Aug 16, 2013 1:31 am

..........
Last edited by [-hh] on Wed Aug 13, 2014 1:28 pm, edited 1 time in total.
shiftLock happens

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2902
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: the number of items

Post by mwieder » Fri Aug 16, 2013 1:52 am

Hmmm... with the current definitions, the itemDelimiter can be considered not so much as a delimiter but as a terminator character. Thus

So for a term T of string S and a delimiter char D

T is an item of S if and only if ( (S is not empty) and (T ends with D) or (T is the last term in S) )

Then the following statements are currently true:
"" has 0 items

The following have 1 item:
" "
"test"
"test,"
","

The following have two items:
"a,b"
"test,test,"
" , "

While this is internally consistent, the definition leaves both cognitive problems (e.g., the last 1-item case) and functional problems dealing with real-world data.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2234
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: the number of items

Post by [-hh] » Fri Aug 16, 2013 3:47 am

..........
Last edited by [-hh] on Wed Aug 13, 2014 1:28 pm, edited 1 time in total.
shiftLock happens

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2902
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: the number of items

Post by mwieder » Fri Aug 16, 2013 6:26 am

This is exactly what you mean, isn't it?
Yes, that's it exactly.
(T&D is in S) or (S ends with T) is an exclusive 'or', because both is not possible.
Just to be pedantic about it, it is certainly possible.
"test,test" fulfills both clauses, where T="test" and D=comma.
But you say "," has 1 item.
I'm not saying that's how things should be, I'm describing the current situation, where

Code: Select all

put the number of items of "," -- results in 1

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2234
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: the number of items

Post by [-hh] » Fri Aug 16, 2013 8:42 am

..........
Last edited by [-hh] on Wed Aug 13, 2014 1:28 pm, edited 1 time in total.
shiftLock happens

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2902
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: the number of items

Post by mwieder » Fri Aug 16, 2013 5:32 pm

We are close together, but you were arguing sometimes for the current situation, or more exactly, searching arguments for it.
Yes. Yes, exactly. We now have good descriptions of both the current and proposed situations and some idea of the advantages and disadvantages of each.
This is not pedantic, you are simply right.
Well, it is pedantic in the sense that it's a bit of a side issue from the main body of your argument and doesn't affect any other part. The conclusions still hold and removing that line has no effect.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2234
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: the number of items

Post by [-hh] » Tue Dec 10, 2013 11:38 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 1:28 pm, edited 1 time in total.
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6464
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: the number of items

Post by dunbarx » Wed Dec 11, 2013 6:57 pm

Hermann.

The discussion was about struggling with whether or not a trailing comma ought to indicate a trailing (albeit empty) item. Convention dictates that a leading or internal comma definitely does (albeit empty)

As you say, ",1,2,3" contains four items, but "1,2,3,' contains only three. (I believe, in my heart, that there should be four in each, but, well...)

But when you reverse ",1,2,3" you are orphaning that real first item by virtue of the methodology that does the reversing. The problem is that even though the item is empty, it has status because of its position in the original string. You have to solidify that status, by hand if necessary, or you do indeed lose an item in the process.

Your point is interesting because it hilites (do you spell that word this way in normal communication?) the positional, not logical determining rule in this matter, and so standard methods do not apply well. Maybe it is akin to arithmetic when dealing with infinities; you don't get what you expect.

Craig

Post Reply

Return to “Engine Contributors”