Monday, May 25, 2020

#1 2020-05-18 12:58:47 pm

robertfern
Member
Registered: 2011-11-29
Posts: 55

Script Debugger 7 bug with list as reference

I'm having a problems with Script Debugger 7.0.12
When I pass a list to a subroutine, it is passed as reference according to AppleScript Language Guide.
My subroutine adds items to the end of the list, but when it returns, the list shown on the right in the variable viewer pane shows the list as empty (unchanged), yet when i then issue a get list command, the proper result shows in the Results Pane

example  code

Applescript:


on run
   local alist
   set alist to {}
   testList(alist, 32) -- this list in the Variable Viewer Pane will show as empty after this command
   get alist -- this command will show the proper result
end run

on testList(blist, x)
   repeat with i from 1 to x
       set end of blist to i
   end repeat
end testList

Last edited by robertfern (2020-05-18 01:00:39 pm)

Offline

 

#2 2020-05-18 01:38:40 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: Script Debugger 7 bug with list as reference

As far as I know, it's not a bug.
We must define the locales which we want to trace in handlers.
If I trigger the button [Step into the handler called in the next statement] I may see the behavior of the list.

Applescript:

on run
   local alist
   set alist to {}
   set alist to my testList(alist, 32) -- this list in the Variable Viewer Pane will show as empty after this command
   --get alist -- this command will show the proper result
end run

on testList(blist, x)
   local blist, i
   repeat with i from 1 to x
       set end of blist to i
   end repeat
   return blist
end testList

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 18 mai 2020 21:38:34

Offline

 

#3 2020-05-18 04:06:29 pm

robertfern
Member
Registered: 2011-11-29
Posts: 55

Re: Script Debugger 7 bug with list as reference

I did not know you could declare a parameter as local.
-- I thought that would cause a conflict.-- edit

This does not solves my issue tho.
I was a trying to not use the set command on a list that should already be modified just by calling the subroutine. The main reason I want to do this is an some cases where i use very, very large lists

the list "alist" was already set as a local in the run handler, and that is where i want to trace it

Thanks.

Robert

Last edited by robertfern (2020-05-18 04:37:01 pm)

Offline

 

#4 2020-05-18 06:07:28 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6362

Re: Script Debugger 7 bug with list as reference

robertfern wrote:

My subroutine adds items to the end of the list, but when it returns, the list shown on the right in the variable viewer pane shows the list as empty (unchanged)



That's because you've declared it local. Remove the local statement.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#5 2020-05-18 08:10:19 pm

robertfern
Member
Registered: 2011-11-29
Posts: 55

Re: Script Debugger 7 bug with list as reference

It works!
But why does declaring it local change anything?
Isn't it by default a local variable anyway?

Robert

Offline

 

#6 2020-05-18 08:23:49 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6362

Re: Script Debugger 7 bug with list as reference

robertfern wrote:

Isn't it by default a local variable anyway?



No, variables declared at the top level or in an explicit run handler are global unless declared otherwise.

Applescript:

on run
   set aList to {"a"}
   testList()
end run

on testList()
   global aList
   display dialog (item 1 of aList)
end testList

AppleScript scope is complicated.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#7 2020-05-19 01:43:59 am

ldicroce
Member
Registered: 2017-11-25
Posts: 197

Re: Script Debugger 7 bug with list as reference

Shane Stanley wrote:

No, variables declared at the top level or in an explicit run handler are global unless declared otherwise.

But then if are  global why this triggers an error?

Applescript:

on run
   set aList to {"a"}
   set bList to {} -- This also should be "global"
   testList()
   display dialog (item 1 of bList) -- ERROR HERE
end run

on testList()
   global aList
   set bList to {"c"} -- fails to update the "global" variable bList ...
   display dialog (item 1 of aList)
end testList

Or ... have I misunderstood the concept of "global"?


Shane Stanley wrote:

AppleScript scope is complicated.

I agree !!!!

Offline

 

#8 2020-05-19 01:54:26 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6362

Re: Script Debugger 7 bug with list as reference

ldicroce wrote:

Or ... have I misunderstood the concept of "global"?



Sort of. As I said, scope is complex in AppleScript. The best explanation of it is still in Matt Neuberg's book.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#9 2020-05-19 07:14:06 am

robertfern
Member
Registered: 2011-11-29
Posts: 55

Re: Script Debugger 7 bug with list as reference

I got a reply from Mark Alldritt at LateNight Software
Here's what he said:

Yes, this is a limitation of the technique we use to implement step-wise execution.  Modifying variables in the way you are doing it is not noticed automatically by Script Debugger.  You can force Script Debugger to see the change to the `alist` variable using this specially formatted comment:

    --=alist

This tells Script Debugger to sample the value of the variable(s) listed at that point in the code.

Cheers 
-Mark

-- YES it works

Robert

Offline

 

#10 2020-05-19 02:41:08 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1258

Re: Script Debugger 7 bug with list as reference

robertfern,

this is not specifically Script Debugger issue. When I run your original script in the Script Editor, I get the same unwanted result. This means: you should pass not whole alist object, but only its contents:

Applescript:


on run
   set alist to {}
   my testList(contents of alist, 32) -- this list in the Variable Viewer Pane will show as empty after this command
   return alist -- this command will show the proper result
end run

on testList(blist, x)
   repeat with i from 1 to x
       set end of blist to i
   end repeat
end testList

Last edited by KniazidisR (2020-05-19 03:00:23 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#11 2020-05-19 07:03:31 pm

robertfern
Member
Registered: 2011-11-29
Posts: 55

Re: Script Debugger 7 bug with list as reference

Works as normal in my "Script Editor"
and since my issue is with a debugging feature, not sure how that applies to "Script Editor".

Also, in this instance of a project i'm working on, I would never pass contents of list as my list is potentially "extremely" large and passing as reference is best to cut down on multiple copies in memory and the creating, copying, and destroying these large lists in memory. As this would cause performance issues.

Please elaborate on what is not working for you,

Thanks,

Robert

Last edited by robertfern (2020-05-19 07:08:33 pm)

Offline

 

#12 2020-05-19 09:38:13 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1258

Re: Script Debugger 7 bug with list as reference

robertfern wrote:

Please elaborate on what is not working for you,



Seeing your original script again. As you tried alist as local variable, I guess that you wanted only the list blist (local) to be modified, and the list alist (global) to remain empty. So... its correct result should be empty list alist, and not contents of blist. Your original script doesn't do the correct job for you either. The only difference between us is that you don’t understand this.

Even if my guess does not hit the target, and you still want to change the contents of the 1st list (global variable) having the 2nd list as independent list (that is, as a local variable of handler testList), then the correct script should be following:

Applescript:


on run
   set alist to {}
   set alist to my testList(contents of alist, 32)
end run

on testList(blist, x)
   repeat with i from 1 to x
       set end of blist to i
   end repeat
   return blist
end testList

Last edited by KniazidisR (2020-05-20 02:15:49 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#13 2020-05-20 09:55:23 am

robertfern
Member
Registered: 2011-11-29
Posts: 55

Re: Script Debugger 7 bug with list as reference

You totally misunderstood.

The correct list should be {1,2,3,4...,31,32} as it is.

blist in the subroutine is "a reference to" alist as this is how AppleScript passes lists as parameters, which is what I want.
So modifying blist in the subroutine is actually modifying alist in the main routine, also what I wanted.

So it is acting as it should

Robert

Last edited by robertfern (2020-05-20 09:56:50 am)

Offline

 

#14 2020-05-20 11:59:57 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 1258

Re: Script Debugger 7 bug with list as reference

robertfern wrote:

You totally misunderstood.


If you didn’t need to worry about changing the contents of alist, and you wanted to do just that, then it is incredibly difficult to understand why you tried to make it a local variable.


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#15 2020-05-20 12:07:21 pm

robertfern
Member
Registered: 2011-11-29
Posts: 55

Re: Script Debugger 7 bug with list as reference

My entire issue had nothing to do with the list being local or not, but was solely on an issue with "Script Debugger"'s ability to debug the changes.

Robert

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)