<<script>> doesn't understand the "function_name" message?

Suddenly I’m getting this error when I try to run a script. I get it when I call a function called “UseRAMDisk()”.

This script has about 15 functions and this IS one of them. Editor is giving me error -1708 as soon as I call the function, not even the first line in that function happens.

HOWEVER I do have a variable in the script by the same name. Is that a nono in applescript? Or is the problem something else? It feels like the problem is just a “bad compiling” but who knows.

That’s a BIG no-no. Rename one of them

If thats a no-no, why doesn’t it throw an error when compiling?

It is perfectly legal to change the value of an identifier, for example the same identifier can be used for an integer or a string (or a handler). The no-no part is that the identifier can only be used for one object at a time, so if you set the value of a handler identifier to an integer, it is now an integer and no longer a handler.

This means that you are free to do weird stuff like save the original value of a handler identifier, use the identifier for something else, and later restore it to the original handler, for example:

display dialog "" & class of UseRAMDisk
set oldRAMDisk to UseRAMDisk -- stash the original to restore later

set UseRAMDisk to 7 -- not a handler anymore
display dialog "" & class of UseRAMDisk & return & UseRAMDisk

set UseRAMDisk to oldRAMDisk -- back to being a handler
display dialog "" & class of UseRAMDisk

UseRAMDisk()

on UseRAMDisk()
    return "I am a handler now" -- whatever
end UseRAMDisk

I suppose one usage would be to pass handlers around, but that starts getting complicated since you have to do something else to get any arguments, and AppleScript doesn’t really need any help being weird.

The compiler only checks the code for grammatical correctness, which it has to do in order to be able to compile it. What the code does when it’s run, and the conditions at the time, are the responsibility of the scripter.

It’s possible, although probably best avoided, to use a separate variable with the same label as a handler provided the variable’s explicitly declared local and used in that scope:

on UseRAMDisk()
	say "Hello"
end UseRAMDisk

on doSomethingDaft()
	local UseRAMDisk
	set UseRAMDisk to 4 -- Local variable.
	
	UseRAMDisk() -- The parenthesis implies the handler.
end doSomethingDaft

doSomethingDaft()

It depends on whether the variable is a local, Global or a property.

Scope is the key.