• 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: *Very* strange script / global variable behavior
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: *Very* strange script / global variable behavior


  • Subject: Re: *Very* strange script / global variable behavior
  • From: Axel Luttgens <email@hidden>
  • Date: Mon, 14 Mar 2005 10:26:57 +0100

Paul Berkowitz wrote:
Re: *Very* strange script / global variable behavior On 3/13/05 11:48 AM, "Axel Luttgens" <email@hidden> wrote:


By contrast, should someone have asked why following code errors,
everybody would have said "hey! that's normal! you wouldn't want to be
able to clash local variables that way, would you?":

    -- Code4
    set SomeProp to "xyz"

    script LogIt
        log SomeProp
    end script

    tell LogIt to run
    --> Error: variable SomeProp is undefined

So, everyone would understand the error produced by Code4 because of
basic and almost universal programming rules.




Hmmm? SomeProp is not a local variable.
I disagree ;-)
Within Code4, SomeProp designates a entity local to LogIt's implicit run handler.
As well as a global variable implicitely declared at the script's top-level.
And those two beasts, the local one and the global one, really are distinct.

It is only when other scoping hints are provided, such as in your Code4A or in my Code1bis, that identifier SomeProp may be brought to designate the same global entity.

But in order for Code4A's log command to be logging (*xyz*), it means that the global SomeProp just declared in LogIt script object has gone out to the top level and "found" an existing SomeProp value. It couldn't do that if SomeProp did not have a quasi-global namespace already - in other languages you'd get a "undefined" error.
I see you point.
But isn't it just about those scoping hints I was talking about in the above?
Without such hints, there are two distinct entities named "SomeProp" in Code4.
Of course, that code needs to be somewhat augmented to make something "useful" out of the local SomeProp:

    -- Code4bis
    set SomeProp to "xyz"

    script LogIt
        set SomeProp to my SomeProp
        log SomeProp
        set SomeProp to "abc"
        log SomeProp
    end script

    tell LogIt to run
    log SomeProp
    --> (*xyz*)
    --> (*abc*)
    --> (*xyz*)

But it may be that we are understanding the locution "local" differently.

Axel

 _______________________________________________
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: *Very* strange script / global variable behavior (From: Paul Berkowitz <email@hidden>)

  • Prev by Date: Re: scripting Captain FTP 4.0030
  • Next by Date: Re: Found records count in Filemaker 6/OS X
  • Previous by thread: Re: *Very* strange script / global variable behavior
  • Next by thread: Re: *Very* strange script / global variable behavior
  • Index(es):
    • Date
    • Thread