AW: AW: Lines, items, repeat loops, > not always what you think

Jim Ault JimAultWins at yahoo.com
Thu Oct 20 12:32:34 EDT 2005


Very good response, Thomas.
I am focused on other issues in my software development and appreciate that
you took the time to visit this issue.
Bottom line for me is to move data out of and into tables using SQL doing
maintenance in the process.  Adding characters to the data grid may be
necessary, but I don't want them going back into the tables, so I will have
to strip them out. Parallel sorting of containers is my next set of
functions to implement, so I will see what I decide.

Thanks for the improved function for counting items.  Speed will be an issue
later.

By the way, you don't have to save the old itemDel.  When calling a function
or procedure, moving to that handler uses a default delim of "," or the one
that is set in that handler.  Eg. if you set the itemdel to tab, then called
a function, set the itemdel to space, then returned to the first handler,
the itemdel would again be a tab.  This means the scope of the itemDel is
only within the handler (local).

At the moment I will go forward with avoiding the sort descending unless I
after the sort I test for the last char, and your version of the delimCount
function.

I am not really willing to be adding spurious characters to my database just
to the Rev sorts and repeat loops will always work.

Thanks for the good work.

Jim Ault
Las Vegas


On 10/20/05 7:03 AM, "Thomas Fischer" <fischer at mail.sub.uni-goettingen.de>
wrote:

> Hi Jim,
> 
> I'm sitting in a train and just found some time to go through your arguments.
> 
>>> put the number of lines in temp into lineCount
>>> if the last char of temp  is return then add one to lineCount
>> 
>> .. if you are creating a list you should be aware of the style
>> that you use to generate it.  In more complete applications
>> where you arerelying on user input or other data sources, the
>> 'empty' last item is a real item  that needs
>> to be known as 'missing' or not 'filled in' (such as a form).
> 
> Yes, I agree, but this is what I meant with software dependency.
> 
>> One example in a stack of cards.  A inventory list is kept as
>> "one card=one product".
>> -Sort cards by product name.
>> -Build a list of prices from 1 to the number of cards by putting the price
>> into line x of pricesCollected and all are collected
>> -then repeat with x = 1 to the number of lines in pricesCollected to find
>> any missing entries.
>> -If the last card has no price, 567 cards would only loop 566 times
>> The last card needs to be fixed, but would not be done.
>> Made a bit worse if you wanted to rank them the highest to lowest, sort
>> descending would take any empty line and make it last, and a report would
>> not publish the last line.
> 
> I think I see your problem, but it wouldn't happen to me, because I script
> slightly differently.
> I would create my list pricesCollected like this:
> 
> put empty into pricesCollected
> repeat with i = 1 to (the number of cards of this stack)
> -- I don't know: Is there a "for each card" repeat loop?
> -- I'm on the wrong computer to check
> put (priceField of card i) & return after pricesCollected
> -- usually much faster then "put into line i of pricesCollected"
> end repeat
> 
> Now pricesCollected has (number of lines) equal to the number of cards, and
> any missing value will appear as an empty line.
> I think this is part of the xTalk philosophy: (Almost) everything is done in
> unstructured strings. You can think of your data as arrays (line i = a[i]),
> but it is much more efficient to deal with the first (or every) line and add
> lines at the end then accessing them individually.
> 
>> I am doing SQL database table work and searching the tables for
>> missing and incorrect values.  I have to avoid 'sort descending'.
> 
> Again, it depends on your environment. If your SQL database gives you an
> additional return after each column you ask for, fine, if not, add one
> yourself. Similarly for lines: add a tab (or whatever) if needed. If you have
> the final character right, no sorting can screw up your numbers.
I am not really willing to be adding spurious characters to my database just
to the Rev sorts and repeat loops will always work.
>> 
>>> put the number of lines in temp into lineCount
>>> if the last char of temp  is return then add one to lineCount
>>> would be more efficient and give the same result as your delimCount.
>> The delimCount(string, delimiter) function can work with lines (cr) or any
>> item delimeter (/ tab comma quote ^).
> 
> If you really need this, I would suggest to do it like that:
> 
> function delimCount strr, del
>     put the itemDelimiter into saveDelim
>     set the itemDelimiter to del
>     get the number of items in strr
>     if the last char of strr is del then add 1 to it
>     set the itemDelimiter to saveDelim
>     return it
> end delimCount
> 
> This tested about 75 times faster on a list I tried. Only matters if you use
> this a lot, though.
> 
> All the best
> Thomas
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution





More information about the use-livecode mailing list