• 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
Variable Ponderance
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Variable Ponderance


  • Subject: Variable Ponderance
  • From: Ben Waldie <email@hidden>
  • Date: Thu, 30 Sep 2004 13:27:09 -0400

I think I have noticed this before, but just never questioned it.

In the following examples, I set a local variable to a value, and then pass that variable down to a handler as a parameter. In the handler, I change the value of this parameter. I would expect this change to be local to the handler only, and not global to the script. So, at the main level of the script, I would expect the variable to retain it's original value, no matter what happens to it in the handler.

In the first example, I pass down a variable containing a number, completely change it to a value of 2, and the variable at the top level of my script behaves as I would expect, retaining its original value. In the second and third examples though, I pass down a variable containing a list or a record, modify part of the list or record, and the variable at the top level of my script does not behave as I would expect. In these 2 cases, the main script treats the variable as it if is a global, remembering the change I made in the handler. This appears to occur only when manipulating the variable, and not when changing it completely. Is this the intended behavior?
--------------------
EXAMPLE 1
--------------------
set x to 1
doSomething(x)
return x
--> 1 -- I would expect 1


on doSomething(y)
	set y to 2
end doSomethingElse
--------------------
EXAMPLE 2
--------------------
set x to {1, 2, 3}
doSomething(x)
return x
--> {2,2,3} -- I would expect {1,2,3}

on doSomething(y)
	set item 1 of y to 2
end doSomething
--------------------
EXAMPLE 3
--------------------
set x to {name:"Ben"}
doSomething(x)
return x
--> {name:"Waldie"} -- I would expect {name:"Ben"}

on doSomething(y)
	set name of y to "Waldie"
end doSomething
--------------------


-Ben

Benjamin S. Waldie
President & CEO
Automated Workflows, LLC
610.935.0652
=============================================
AppleScript and Workflow Automation
Consulting - <http://www.automatedworkflows.com>
AppleScript Info - <http://www.applescriptguru.com>
AppleScript Training - <http://www.applescripttraining.com>
=============================================

_______________________________________________
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


  • Follow-Ups:
    • Re: Variable Ponderance
      • From: Michelle Steiner <email@hidden>
    • Re: Variable Ponderance
      • From: Paul Berkowitz <email@hidden>
  • Prev by Date: Scripting QuarkXPress Books
  • Next by Date: Re: Variable Ponderance
  • Previous by thread: Re: Where am I?
  • Next by thread: Re: Variable Ponderance
  • Index(es):
    • Date
    • Thread