• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Things I thought I knew, but didn't - variable scope in repeat loops
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Things I thought I knew, but didn't - variable scope in repeat loops


  • Subject: Re: Things I thought I knew, but didn't - variable scope in repeat loops
  • From: Axel Luttgens <email@hidden>
  • Date: Sun, 28 Dec 2008 23:40:37 +0100

Le 27 déc. 08 à 18:48, Doug McNutt a écrit :


Mark got quoted this way:
Applescript builds a list of values (or an iterator/generator) and
sets i to the next value at the top of the loop; it doesn't look at
the current value of i to determine what the next value of i should
be.   So you can do anything you want to i inside the loop and it
won't affect the loop control logic:

Doesn't that imply a limit on the number of times through a repeat loop? If there isn't a stated limit hardware will impose one when that list has to be stored.


I can remember running some Monte-Carlo calculations that were tracking photons making random tracks through the upper atmosphere. The loop count was high enough that 15 bit FORTRAN integers stored in the hardware registers were too small. Using a memory-stored integer at 24 bits created serious speed issues.

No. I wouldn't even think about using an interpreted script for that but I am curious about just what AppleScript's limit really is. Come to think of it, is there a limit on the length of an ordered list in AppleScript? Are such things stored in a stack? Are they linked so that each entry structure requires a memory pointer to the next? Or are the entries for a repeat loop really an array in consecutive memory addresses?

Hello Doug,

Combining the info contained into:

	http://lists.apple.com/archives/AppleScript-Users/2008/Dec/msg00522.html
	http://lists.apple.com/archives/AppleScript-Users/2008/Dec/msg00523.html

it seems that the behavior of:

	repeat with loopVariable (from startValue to stopValue)
		statements
	end repeat

could be rendered as following internal mechanism:

intern i_loopVariable, i_startValue, i_stopValue
set i_loopVariable to loopVariable -- may involve the evaluation of an expression
set i_startValue to startValue -- may involve the evaluation of an expression
set i_stopValue to stopValue -- may involve the evaluation of an expression
local loopVariable -- has no effect if loopVariable is already local
LOOPAGAIN:
set loopVariable to i_loopVariable
statements
set i_loopVariable to i_loopVariable + 1
if i_loopVariable <= i_stopValue then goto LOOPAGAIN


where of course intern, LABEL: and goto do not belong to user-level AppleScript.

According to this scheme, AppleScript's limit would just be its capacity to dicriminate between two consecutive integers, even if expressed as reals because of an integer to real coercion.

HTH,
Axel


_______________________________________________ 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
References: 
 >Re: Things I thought I knew, but didn't - variable scope in repeat loops (From: Richard Rönnbäck <email@hidden>)
 >Re: Things I thought I knew, but didn't - variable scope in repeat loops (From: Doug McNutt <email@hidden>)

  • Prev by Date: Re: Thirteen Scripters Scripting
  • Next by Date: Re: Things I thought I knew, but didn't - variable scope in repeat loops
  • Previous by thread: Re: Things I thought I knew, but didn't - variable scope in repeat loops
  • Next by thread: Re: Things I thought I knew, but didn't - variable scope in repeat loops
  • Index(es):
    • Date
    • Thread