Case of the Curious Comma
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Case of the Curious Comma
I have a routine which generates ten random numbers
and the result is as expected....
3,12,5,32,13,26,7,19,8,15,
but when I sort the items numeric ascending I get
,3,5,7,8,12,13,15,19,26,32
Is this as expected?
I thought the lack of the last comma might have been
causing another problem which I'll post if I fail to figure
it out.
and the result is as expected....
3,12,5,32,13,26,7,19,8,15,
but when I sort the items numeric ascending I get
,3,5,7,8,12,13,15,19,26,32
Is this as expected?
I thought the lack of the last comma might have been
causing another problem which I'll post if I fail to figure
it out.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
Re: Case of the Curious Comma
Empty is, when handled as number, equivalent to zero.
And a numeric sort compares empty to other numbers.
Others do that setting also, for example spreadsheat apps as Excel for empty cells.
For example the following is in LC true:
empty+3=3
min(1,,2)=0
This doesn't matter if one is adding numbers, but one should have the second example in mind, that could be misleading.
So, in fact, for numerical uses,
... your random list ends with zero
... and the sorted list has a zero in front of it
... and the minimum of your list is zero, as long as an item is empty,
-hh
And a numeric sort compares empty to other numbers.
Others do that setting also, for example spreadsheat apps as Excel for empty cells.
For example the following is in LC true:
empty+3=3
min(1,,2)=0
This doesn't matter if one is adding numbers, but one should have the second example in mind, that could be misleading.
So, in fact, for numerical uses,
... your random list ends with zero
... and the sorted list has a zero in front of it
... and the minimum of your list is zero, as long as an item is empty,
-hh
Last edited by [-hh] on Sat Mar 05, 2016 8:21 am, edited 1 time in total.
shiftLock happens
Re: Case of the Curious Comma
H Ross,
You've just open a can of worms... again
http://forums.livecode.com/viewtopic.php?f=7&t=22859
That's just one of the posts.
Simon
You've just open a can of worms... again

http://forums.livecode.com/viewtopic.php?f=7&t=22859
That's just one of the posts.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Case of the Curious Comma
Hi Simon,
that was now a bit overcross
I think here is the "real" problem not the *last* empty item but, more general, an *empty* item. And how this is handled by LC for numerical procedures.
I think this is definetely NOT a bug here but a setting with sometimes unwanted side-effects. The last-item-and-number-of-items-discussion is ... whatever you name it. It's useless to argue there.
Recently I made an enhancement request for product(<list>). If that comes, then we have to be acquainted with the setting "one= empty item". That is we have then, logically true, (because these are different "empty"s, an empty-0 and an empty-1, as neutral elements for addition and multiplication):
empty*(empty+empty) = 1*0=0 but also empty*empty + empty*empty = 1+1=2,
what proves 0=2.
Have fun!
Hermann
that was now a bit overcross

I think here is the "real" problem not the *last* empty item but, more general, an *empty* item. And how this is handled by LC for numerical procedures.
I think this is definetely NOT a bug here but a setting with sometimes unwanted side-effects. The last-item-and-number-of-items-discussion is ... whatever you name it. It's useless to argue there.
Recently I made an enhancement request for product(<list>). If that comes, then we have to be acquainted with the setting "one= empty item". That is we have then, logically true, (because these are different "empty"s, an empty-0 and an empty-1, as neutral elements for addition and multiplication):
empty*(empty+empty) = 1*0=0 but also empty*empty + empty*empty = 1+1=2,
what proves 0=2.
Have fun!
Hermann
shiftLock happens
Re: Case of the Curious Comma
Thank you all for your comments.
It's easy enough to delete the first character to get
rid of the leading comma - it's just cosmetic I think -
and put a comma at the end although it's not necessary
except when I put another group of comma-delimited
numbers after the first.
No matter, it's still easier that "C".
It's easy enough to delete the first character to get
rid of the leading comma - it's just cosmetic I think -
and put a comma at the end although it's not necessary
except when I put another group of comma-delimited
numbers after the first.
No matter, it's still easier that "C".
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
Re: Case of the Curious Comma
Hi.
All good stuff.
It takes a little more effort, but I would take the time to check each item and only delete if it empty.
Sounds like unnecessary work? One day you might not think so.
Craig Newman
All good stuff.
It is not robust to simply delete the first character. Here be pitfalls.It's easy enough to delete the first character to get
rid of the leading comma
It takes a little more effort, but I would take the time to check each item and only delete if it empty.
Code: Select all
repeat for each item tItem in yourVar
if tItem is a number then put tItem & "," after newVar
Craig Newman
Re: Case of the Curious Comma
Alternately delete the last comma before doing the sort. That's shorter than a repeat loop and you know it's there if the handler created the list itself.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com