• 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: Axel Luttgens <email@hidden>
  • Date: Tue, 09 Sep 2003 10:14:27 +0200

Paul Berkowitz wrote:

[...]

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.


Let's change ex. 3 as follows:

set ls to {}
set d to date "vendredi 5 septembre 2003 0:00:00"
set end of ls to d
AddAMonth(d)
ls
--> {date "dimanche 5 octobre 2003 0:00:00"}

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

Clearly, it is not your initial 'set d to AddAMonth(d)' that produced the seemingly surprising result.
In fact, data sharing is at work.
As far as I remember, this has allways been so in AS: a value, liable to data sharing, passed as an argument to a subroutine will be acted upon through data sharing.
Exactly as with:

set lst to {1, 2, 3}
AlterList(lst)
lst
--> {100,2,3}

on AlterList(l)
set item 1 of l to 100
end AlterList

And this doesn't change anything to the fact that aDate (or l in the latter example) is an identifier local to AddAMonth().


It makes no difference throwing 'local' around:


[...]


Because one now just extends data sharing to another local identifier.



The only thing that works is to copy aDate to f, rather than set f to aDate:

[...]


Because 'copy' of course hinders data sharing (as your above sentence already implied it).


Sincerely,
Axel
_______________________________________________
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: Dates gone wild
  • Next by Date: Re: Dates gone wild
  • Previous by thread: Dates gone wild
  • Next by thread: Re: Dates gone wild
  • Index(es):
    • Date
    • Thread