• 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: My first question, please be gentle (stack overflow)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: My first question, please be gentle (stack overflow)


  • Subject: Re: My first question, please be gentle (stack overflow)
  • From: Matt Gregory <email@hidden>
  • Date: Mon, 25 Jul 2005 15:09:19 -0400

Ok, that makes more sense.  And it explains why Script Editor itself is also complaining about not being able to save the file ... in both cases it is trying to persist my giant global variable(s).  I obviously need to spend a little more time in the documentation.

Excellent explanation!  Thank you!

matt.

On 7/25/05, Paul Berkowitz <email@hidden> wrote:
No. AS doesn't persist local variables between runs. It persists properties (pre-defined globals) and globals between runs.

The part that is a bit confusing and non-apparent is that AS treats undeclared variables at the top level (i.e. not in a handler) as globals for persistence purposes, although not for scope*, while undeclared variables within handlers (subroutines) are treated as local variables to that handler. So the two ways to avoid the problem you're seeing is to make sure they're not globals by either

  1. Explicitly declaring them as local at the top of the script, or
  2. Putting what would be the top level (implicit or explicit run handler) of the script into a subroutine and calling that with a single line.

That makes them all local variables, which the script does not try to save at the end, so there's no change to the file and no stack overflow either.

[* It is possible (though not advised) to declare a global within a handler. Therefore undeclared variables at the top level need to have this quasi-global attribute of being lookable-up when you declare a global within a handler. I.e. they really do have a sort of "potential" global scope, but it's not operative unless declared global somewhere. I expect that's how undeclared top-level variables end up being treated as globals when the script quits, and AS tries to save them.]

--
Paul Berkowitz



From: Matt Gregory <email@hidden>
Reply-To: Matt Gregory <email@hidden>
Date: Mon, 25 Jul 2005 13:44:26 -0400
To: has <email@hidden>
Cc: <email@hidden>
Subject: Re: My first question, please be gentle (stack overflow)


OOOOH!  I didn't realize that AS tries to persist local variables between runs ... that idea sounds strange to me, but I guess there's a good reason ... I'll have to take a closer look at the docs on it.  That's a little gem to keep in mind!  I should be able to localize all my variables or even make multiple writes to the output file instead of one big write at the end.  

This helps immensely, thank you very much!  Those threads didn't turn up during yesterday's archive search session.  I'll be more careful next time.  Your assistance is very much appreciated!

Thanks again,
matt.

On 7/25/05, has <email@hidden> wrote:
Matt Gregory wrote:

>This all works fine while running in the Script Editor (OS X 10.3.9).  But when I save the script as an Application and run it, I get the error saying the script "could not be saved because the stack overflowed."

http://lists.apple.com/archives/applescript-users/2005//Jul/msg00178.html
http://lists.apple.com/archives/applescript-users/2005//Jul/msg00244.html

has
--
http://freespace.virgin.net/hamish.sanderson/
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:


This email sent to email@hidden



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:


This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: My first question, please be gentle (stack overflow) (From: Matt Gregory <email@hidden>)
 >Re: My first question, please be gentle (stack overflow) (From: Paul Berkowitz <email@hidden>)

  • Prev by Date: Re: My first question, please be gentle (stack overflow)
  • Next by Date: Re: set myList to myList & ... and unexpected results
  • Previous by thread: Re: My first question, please be gentle (stack overflow)
  • Next by thread: Print selected file in the Finder
  • Index(es):
    • Date
    • Thread