 |
|
 |
|
Next: do shell script "system_profiler...
|
| Author |
Message |
External

Since: Jan 28, 2004 Posts: 4
|
(Msg. 1) Posted: Wed Jan 28, 2004 6:16 pm
Post subject: Is this a known Bug? Archived from groups: alt>comp>lang>applescript (more info?)
|
|
|
In the following code listA changes after listB is modified with a
repeat loop. Why does that happen? If listB is changed outside a repeat
loop, listA is unchanged.
set listA to {{1, 1}, {2, 2}, {3, 3}, {4, 4}}
set listB to listA
repeat with itemx in listB
set item 2 of itemx to (item 1 of itemx) + 1
end repeat
return {listA, listB}
-->{{{1, 2}, {2, 3}, {3, 4}, {4, 5}},
-->{{1, 2}, {2, 3}, {3, 4}, {4, 5}}}
Thanks,
Greg Robb >> Stay informed about: Is this a known Bug? |
|
| Back to top |
|
 |  |
External

Since: Jan 28, 2004 Posts: 4
|
(Msg. 2) Posted: Wed Jan 28, 2004 7:43 pm
Post subject: Re: Is this a known Bug? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <280120040729332982%greg_robb@home.net>, greg robb
<greg_robb.TakeThisOut@home.net> wrote:
Oops! ListA also changes when listB is modified outside of a repeat
loop. Why is listA modified when listB is changed?
set listA to {{1, 1}, {2, 2}, {3, 3}, {4, 4}}
set listB to listA
set item 1 of listB to {1, 7}
return {listA, listB}
-->{{{1, 7}, {2, 2}, {3, 3}, {4, 4}},
-->{{1, 7}, {2, 2}, {3, 3}, {4, 4}}}
> In the following code listA changes after listB is modified with a
> repeat loop. Why does that happen? If listB is changed outside a repeat
> loop, listA is unchanged.
>
>
> set listA to {{1, 1}, {2, 2}, {3, 3}, {4, 4}}
> set listB to listA
> repeat with itemx in listB
> set item 2 of itemx to (item 1 of itemx) + 1
> end repeat
>
> return {listA, listB}
> -->{{{1, 2}, {2, 3}, {3, 4}, {4, 5}},
> -->{{1, 2}, {2, 3}, {3, 4}, {4, 5}}}
>
> Thanks,
> Greg Robb<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Is this a known Bug? |
|
| Back to top |
|
 |  |
External

Since: Nov 12, 2003 Posts: 360
|
(Msg. 3) Posted: Wed Jan 28, 2004 9:00 pm
Post subject: Re: Is this a known Bug? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <280120040856220852%greg_robb@home.net>,
Greg Robb <greg_robb RemoveThis @home.net> wrote:
> In article <280120040729332982%greg_robb@home.net>, greg robb
> <greg_robb RemoveThis @home.net> wrote:
>
>
> Oops! ListA also changes when listB is modified outside of a repeat
> loop. Why is listA modified when listB is changed?
Because the "set" command, when used with a list, does not make a copy
of the data. It simply makes listB points to the same data as listA. If
you want a duplicate copy, you need to use "copy listA to listB".
See : <http://developer.apple.com/documentation/AppleScript/Conceptual/
AppleScriptLangGuide/index.html>
Patrick
--
Patrick Stadelmann <Patrick.Stadelmann RemoveThis @unine.ch><!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Is this a known Bug? |
|
| Back to top |
|
 |  |
External

Since: Nov 12, 2003 Posts: 360
|
(Msg. 4) Posted: Wed Jan 28, 2004 9:03 pm
Post subject: Re: Is this a known Bug? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article
<Patrick.Stadelmann-ABCD86.18002528012004 RemoveThis @news.fu-berlin.de>,
Patrick Stadelmann <Patrick.Stadelmann RemoveThis @unine.ch> wrote:
> In article <280120040856220852%greg_robb@home.net>,
> Greg Robb <greg_robb RemoveThis @home.net> wrote:
>
> > In article <280120040729332982%greg_robb@home.net>, greg robb
> > <greg_robb RemoveThis @home.net> wrote:
> >
> >
> > Oops! ListA also changes when listB is modified outside of a repeat
> > loop. Why is listA modified when listB is changed?
>
> Because the "set" command, when used with a list, does not make a copy
> of the data. It simply makes listB points to the same data as listA. If
> you want a duplicate copy, you need to use "copy listA to listB".
>
> See : <http://developer.apple.com/documentation/AppleScript/Conceptual/
> AppleScriptLangGuide/index.html>
Oops, here's the full URL : <http://developer.apple.com/documentation/
AppleScript/Conceptual/AppleScriptLangGuide/AppleScript.9a.html>
Patrick
--
Patrick Stadelmann <Patrick.Stadelmann RemoveThis @unine.ch><!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Is this a known Bug? |
|
| Back to top |
|
 |  |
External

Since: Jan 28, 2004 Posts: 1
|
(Msg. 5) Posted: Wed Jan 28, 2004 9:03 pm
Post subject: Re: Is this a known Bug? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Thanks Patrick, I thought I was going crazy.
So using "set" shares the data between the two variables as long as a
concatenation or deleting an item doesn't happen.
set listA to {{1, 1}, {2, 2}, {3, 3}, {4, 4}}
set listB to listA
set listB to items 1 thru 3 of listB
return {listA, listB}
-->{{{1, 1}, {2, 2}, {3, 3}, {4, 4}},
-->{{1, 1}, {2, 2}, {3, 3}}}
set listA to {{1, 1}, {2, 2}, {3, 3}, {4, 4}}
set listB to listA
set listB to listB & {7, 7}
return {listA, listB}
-->{{{1, 1}, {2, 2}, {3, 3}, {4, 4}},
-->{{1, 1}, {2, 2}, {3, 3}, {4, 4}, 7, 7}}
set listA to {{1, 1}, {2, 2}, {3, 3}, {4, 4}}
set listB to listA
set listB to items 1 thru 3 of listB & {{8, 8}}
return {listA, listB}
-->{{{1, 1}, {2, 2}, {3, 3}, {4, 4}},
-->{{1, 1}, {2, 2}, {3, 3}, {8, 8}}}
-Greg Robb >> Stay informed about: Is this a known Bug? |
|
| Back to top |
|
 |  |
External

Since: Jul 09, 2003 Posts: 925
|
(Msg. 6) Posted: Wed Jan 28, 2004 10:47 pm
Post subject: Re: Is this a known Bug? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <e50b567e.0401281622.4e3a2de0.TakeThisOut@posting.google.com>, Greg Robb
<grobb.TakeThisOut@agtnet.com> wrote:
> Thanks Patrick, I thought I was going crazy.
>
> So using "set" shares the data between the two variables as long as a
> concatenation or deleting an item doesn't happen.
It only happens with lists, also, not with simple data types.
--
Jerry Kindall, Seattle, WA <http://www.jerrykindall.com/>
Send only plain text messages under 32K to the Reply-To address.
This mailbox is filtered aggressively to thwart spam and viruses.<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Is this a known Bug? |
|
| Back to top |
|
 |  |
External

Since: Jan 26, 2004 Posts: 34
|
(Msg. 7) Posted: Fri Jan 30, 2004 1:39 pm
Post subject: Re: Is this a known Bug? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On 28/01/2004, Greg Robb wrote in message
<e50b567e.0401281622.4e3a2de0.TakeThisOut@posting.google.com>:
> So using "set" shares the data between the two variables as long as a
> concatenation or deleting an item doesn't happen.
>
> set listA to {{1, 1}, {2, 2}, {3, 3}, {4, 4}}
> set listB to listA
> set listB to items 1 thru 3 of listB
> return {listA, listB}
> -->{{{1, 1}, {2, 2}, {3, 3}, {4, 4}},
> -->{{1, 1}, {2, 2}, {3, 3}}}
Correct -- as long as data isn't actually changed. It might help to
think of the 'set' command as automatically having 'a reference to'
in it unless you specify otherwise.
Simon.
--
Posted using test version of software.
Please tell me if anything isn't right.<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: Is this a known Bug? |
|
| Back to top |
|
 |  |
| Related Topics: | Scripting Icons on Desktop (Panther) - Hi, new to OSX and want to reproduce a script I had for OS9 that moved all icons on desktop into several rows center-right of screen then re-positioned them in specific places around the screen - any left in the center were obviously new..
URL / Webloc drop - Does anyone have any pointers or sample code to handle the drop of a URL or "webloc" from something like Safari on to an Applescript application? I'm not having too much luck getting this working. Many thanks. -- rik
echo "blah" >> file.txt - how to do this with AppleScript? - Hi, I have a little AppleScript which calls shell commands to create a text file and append strings to it: ***** -- set variables set filepath to "'/Users/claus/the testfile.txt'" set line1 to "Line 1" set line2 to "Line 2"...
Delete all items of a specific folder - Hi, Beginner?s question: I want to delete all items inside a specific folder. However, the following attempt does not work. Where is the problem? delete every item of "claus:Library:Xchange:iPod:Aufgaben:" Greetings, Claus
Drag and Drop applet for UNIX Diction and Style? - I was wondering if there exists, (or anyone would take it on as a coding project, a drag and drop applet that would save a Style and/or Diction report- a readability score more or less, from a plain text file dropped upon this. This may very well alread... |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|