Re: Inner loop accepts values ahead of natural sequence of actions - how can that be?
Re: Inner loop accepts values ahead of natural sequence of actions - how can that be?
- Subject: Re: Inner loop accepts values ahead of natural sequence of actions - how can that be?
- From: "Nigel Garvey" <email@hidden>
- Date: Sun, 11 Jun 2017 10:24:03 +0100
ILJA SHEBALIN wrote on Sat, 10 Jun 2017 14:30:10 +0300:
> set word_list to every word of text of the_text
>set word_frequency_list to {}
>repeat with every_word_ref in word_list
> set the_current_word to contents of every_word_ref
>
> set word_info to missing value
> repeat with record_ref in word_frequency_list --THE QUESTIONABLE LOOP
>(word_frequency_list is a list that contains records). Its position is
>closer to the opening of the outer loop.
> if the_word of record_ref = the_current_word then
> set word_info to contents of record_ref
> #exit repeat -- I discovered it's redundant since the
> script does
>without it.
> end if
> end repeat
>
> if word_info = missing value then --word_info is a record
> set word_info to {the_word:the_current_word, the_count:1}
> set end of word_frequency_list to word_info
> else
> set the_count of word_info to (the_count of word_info) + 1
> end if
>end repeat
> get word_frequency_list
>
>
>What bugs me is that it manages to escape error messages since the inner
>loop contains variables ought to be deemed as undefined (the_word
variable
>in QUESTIONABLE LOOP was NOT defined explicitly before the inner loop
>entered the game). How's that? Nevertheless it works.
Since word_frequency_list is initially empty, the inner repeat doesn't
actually execute during the first iteration of the outer repeat — so
it's not a problem that the record label accessed in it is undefined.
Immediately after this non-execution, word_info is still 'missing
value', so a record is added to word_frequency_list, which both provides
an instance of the label and causes the inner repeat to be executed on
subsequent iterations of the outer loop.
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden