(counting tabbed items)

J. Landman Gay jacque at hyperactivesw.com
Wed May 26 00:34:53 CDT 2004


On 5/25/04 10:19 AM, rand valentine wrote:

>   Thank you for your comment and clarification... could you clarify a bit
> more if you have a moment -- when you write "forcing the compiler to parse
> the tabs," what do you mean exactly -- I'm a linguist, so I know what
> parsing is :-), but I'm not quite clear as to its meaning here.

My language probably wasn't very exact. What I meant was, there needs to 
be a way for the compiler to recognize that the word "tab" is not a 
string of characters but rather the tab constant. It usually does this 
automatically, but when you use the concatenation character "&", the 
engine may assume that the word "tab" is an unquoted string of 
characters that you are trying to concatenate. Since parentheses force 
an evaluation of whatever is between them, putting parentheses around 
the phrase causes the compiler to recognize "tab" as a constant because 
it evaluates each part of the content before doing anything else with it.

(Re-reading that, I'm not sure I explained it any more clearly. Maybe 
someone who hasn't been so sleep deprived can explain it better.)

> 
>   Also, when you write "evaluate the constants first," what are the
> constants and what are not?

Revolution has several pre-defined contstants; words that can be used in 
scripts to represent certain standard values. "Tab" is one of those. So 
are: space, colon, comma, cr, slash, and a bunch of others, including 
all number names between one and ten, and various cursor types, among 
others. See the entry in the dictionary for "constantNames" to get a 
whole list. There's a bunch. You can use constants in scripts instead of 
typing their actual values. That is, you can use "10" or "ten" 
interchangeably; "ten" is the constant. Ditto, "cross" is the constant 
for the cursor with the value of 7.

You can define your own custom constants in your scripts too.

> 
>   And now for a more useful question for my purposes -- say I have a
> tab-delimited string -- if i want to grab the third item from the end, even
> if the last two are empty, I _know_ I can't code:
> 
>   (set the itemDelimiter to tab)...
> 
>   put item -3 of myLine
> 
>   but could I be absolutely certain of getting the right item if I coded
> 
>  put item -3 of "(" & myLine & ")"

No, because no matter how you code it, the third item from the end is 
only going to count backward from the total number of items. Rev removes 
trailing delimiters from the end of the list (that is, the trailing tab 
that delimits an empty last item) so your list will always end up with 
one less item in it if the last one is empty. Your best bet is to count 
from the front. ;)

> 
>   I will experiment with this a bit, but _really_ value your guys'
> (collective) gurucious ex cathedra comments about these most subtle details
> of the mortal world. Thank you again.
> 
> rand
> 
> On 5/25/04 10:00 AM, "use-revolution-request at lists.runrev.com"
> <use-revolution-request at lists.runrev.com> wrote:
> 
> 
> 
>>Because without forcing the compiler to parse the tabs in the first
>>case, each tab is considered a text string. The concatenation looks like
>>this:
>>
>>"tabtabtabtab"
>>
>>If you put parentheses around it, the compiler will evaluate the
>>constants first before working with the string:
>>
>> put the number of items of (tab & tab & tab & tab)
>>
>>Gives 4.
> 
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
> 
> 
> 


-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com


More information about the use-livecode mailing list