• 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: Dates gone wild
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dates gone wild


  • Subject: Re: Dates gone wild
  • From: Jon Pugh <email@hidden>
  • Date: Tue, 9 Sep 2003 07:39:26 -0700

At 9:05 PM -0700 9/8/03, Paul Berkowitz wrote:
>3.
>set ls to {}
>set d to date "Friday, September 5, 2003 12:00:00 AM"
>set end of ls to d
>set d to AddAMonth(d)
>ls
>--> {date "Sunday, October 5, 2003 12:00:00 AM"} -- !!!
>
>to AddAMonth(aDate)
> set month of aDate to October
> return aDate
>end AddAMonth
>
>[snippage]
>
>But what's going on in ex. 3? Here d is being reassigned, just as in ex. 1,
>only it's doing so as the result of a handler. If the handler merely
>reassigns a new value, (set aDate to date "12/5/03") that does not affect
>ls. But changing the month of aDate changes ls back home! It's as if it has
>global scope.

Actually, it appears that dates are passed by reference. In all of your examples, d and aDate are references to a date object.

For example:

set ls to {}
set d to date "Friday, September 5, 2003 12:00:00 AM"
set end of ls to d
AddAMonth(d)
ls
--> {date "Sunday, October 5, 2003 12:00:00 AM"} -- !!!

to AddAMonth(aDate)
set month of aDate to October
end AddAMonth


You'll notice that we don't even bother reassigning d, which is a communist herring. It's the "set month of a reference to a date" which is changing the list. Making your reference local doesn't help, as you noticed.

Jon
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

References: 
 >Dates gone wild (From: Paul Berkowitz <email@hidden>)

  • Prev by Date: lots of statements after "then" of "if"
  • Next by Date: Re: Dates gone wild
  • Previous by thread: Re: Dates gone wild
  • Next by thread: Re: Dates gone wild
  • Index(es):
    • Date
    • Thread