problem with counting words

Richard Gaskin ambassador at fourthworld.com
Thu Oct 16 09:59:11 EDT 2014


Dick Kriesel wrote:

> On Oct 14, 2014, at 12:45 PM, Richard Gaskin wrote:
>
>> on mouseUp
>>   put 1000 into n
>>   put "aaa,bbb,ccc#ddd#eee#fff,ggg,hhh" into tSomeData
>>   --
>>   put the millisecs into t
>>   repeat n
>>      get nDepth(tSomeData, 3, comma, 2, "#" )
>>   end repeat
>>   put the millisecs - t into t1
>>   put t1/n &cr& it
>> end mouseUp
>>
>> function nDepth
>>   get param(1)
>>   repeat with i = 2 to paramCount() step 2
>>      set the itemDel to param(i+1)
>>      get item param(i) of it
>>   end repeat
>>   return it
>> end nDepth
>
> That causes an execution error at line 16 when i = 6, and it tries to set the itemDel to empty.
>
> After changing
>    repeat with i = 2 to paramCount() step 2
> to
>    repeat with i = 2 to paramCount()-1 step 2
> it works.

Good catch, Dick.  Your presence on this list is a good argument for the 
benefits of peer code review.

Funny thing is I'd first written it with the "-1", but after reviewing 
it later I couldn't recall why that seemed like a good idea, and since 
it worked well on the sample exercise without it I thought I was just 
being overzealous and removed it.  Moral: when coffee-deprived, trust 
your instincts. :)

I'd only tested it on the use-case given in the earlier posts because I 
couldn't think of one I'd need myself.

For three levels deep I use lines and items, and then change the itemdel 
to get something within an item.

For four or more levels I just use arrays.

I can see the benefit of having human-readable n-depth serialization, 
but I have to wonder if maybe using a widely adopted convention like 
YAML might serve such needs better.  JSON's good too, but YAML is so 
much more writable.

Anyone here have YAMLtoArray/ArrayToYAML handlers?

-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com




More information about the use-livecode mailing list