• 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: sub-routines' error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sub-routines' error


  • Subject: Re: sub-routines' error
  • From: Deivy Petrescu <email@hidden>
  • Date: Wed, 10 May 2017 11:59:11 -0400

> On May 10, 2017, at 09:46 , Axel Luttgens <email@hidden> wrote:
>
>
>> Le 10 mai 2017 à 13:59, Maik Waschfeld a écrit :
>>
>> Hi AS-users,
>>
>> I’m trying to get a little deeper into the sub-routine-thing.
>> But I’m stuck at a strange error -1708, that I can reproduce with the following script.
>>
>> […]
>>
>> When selecting more than one file, so that the sub-routine runs multiple times, I get this error:
>> error „«script» doesn’t understand the message „the_Name“.“ number -1708 from «script»
>>
>> As far as I understand AppleScript, there’s basically nothing wrong with the script.
>>
>> If I replace the „my the_Name(the_File)“ line with
>> tell application "Finder"
>> 	set the_Name to name of the_File
>> end tell
>> no error comes up, even when I select quite a lot files.
>>
>> Any hints, how I get it to work, anyway?
>
> Hello Maik,
>
> This is a nice example of name-space clash in AppleScript. :-)
>
> You may get the gist with that minimal piece:
>
> 	SomeFunction()
> 	--> "xyz"
> 	SomeFunction()
> 	--> error "«script» doesn’t understand the message « SomeFunction »." ...
>
> 	on SomeFunction()
> 		set SomeFunction to "xyz"
> 	end SomeFunction
>
> On first call of SomeFunction, since the name "SomeFunction" is followed by parentheses, the interpretor looks for a handler named that way, finds it and executes it.
> Through that execution, implicit global variable "SomeFunction" is created (and value "xyz" is returned from the handler’s execution, since it’s the last value created through the handler’s execution).
>
> On second call, AppleScript complains about not being able to find a handler named "SomeFunction", since the global variable now hides it.
>
> You may try to avoid the problem by making the identifier local to the handler:
>
> 	SomeFunction()
> 	--> "xyz"
> 	SomeFunction()
> 	—> "xyz"
>
> 	on SomeFunction()
> 		local SomeFunction
> 		set SomeFunction to "xyz"
> 	end SomeFunction
>
> But this tends to become quite ambiguous. ;-)
>
> HTH,
> Axel

Hi Axel,
Thanks for pointing out that there was a new inside the handler assignment.
I missed that.

While your explanation is correct, I believe Mike’s error is an error of logic.
It does not matter if SomeFunction is a handler, a record, list, etc.
If he reassigns the the value of SomeFunction then he can not expect to get the old value back.

His script will work fine with one file chosen, because it calls the handler which will respond accordingly, but then, the handler the_Name disappears and becomes the string, the name of the file, as you showed.


Deivy Petrescu
email@hidden



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >sub-routines' error (From: Maik Waschfeld <email@hidden>)
 >Re: sub-routines' error (From: Axel Luttgens <email@hidden>)

  • Prev by Date: Making a Folder with Test Files
  • Next by Date: Re: sub-routines' error
  • Previous by thread: Re: sub-routines' error
  • Next by thread: Re: sub-routines' error
  • Index(es):
    • Date
    • Thread