Case of the Curious Comma

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Case of the Curious Comma

Post by RossG » Sat Mar 05, 2016 6:40 am

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.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Case of the Curious Comma

Post by [-hh] » Sat Mar 05, 2016 8:17 am

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
Last edited by [-hh] on Sat Mar 05, 2016 8:21 am, edited 1 time in total.
shiftLock happens

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Case of the Curious Comma

Post by Simon » Sat Mar 05, 2016 8:20 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Case of the Curious Comma

Post by [-hh] » Sat Mar 05, 2016 8:45 am

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
shiftLock happens

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Case of the Curious Comma

Post by RossG » Sat Mar 05, 2016 12:14 pm

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".
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Case of the Curious Comma

Post by dunbarx » Sat Mar 05, 2016 4:50 pm

Hi.

All good stuff.
It's easy enough to delete the first character to get
rid of the leading comma
It is not robust to simply delete the first character. Here be pitfalls.

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
Sounds like unnecessary work? One day you might not think so.

Craig Newman

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Case of the Curious Comma

Post by jacque » Sun Mar 06, 2016 4:45 pm

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

Post Reply