Why do these even exist? It seems absurd. Like with most dynamic languages, AppleScript types seem to be either immutable primitive types like integers and reals which are going to be handed around by value and don't make any sense to use with a reference to, or object-like types like applications, scripts, or records, which are being passed around by reference already. How is a reference to not completely redundant? Here's an example taken from Apple's AppleScript Language Guide (https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html):
tell app "Finder" to set diskRef to a ref to startup disk
--result: startup disk of application "Finder"
So do you mean to tell me that if I did this instead,
tell app "Finder" to set diskObj to startup disk
--result: startup disk of application "Finder"
that the applescript runtime is going to send an apple event sent across to the Finder process telling it, "hey - some guy just asked you to return an octet stream of /dev/disks01 back to me! Haha! I guess he should have asked for a reference to it! Let's get started! This is going to take a while!"
I'm programming in Python and I do this:
m = fileHandle.read( 1000000000 ) #and then wait a little while
n = m
Did I just copy a gig of data around in memory? Of course not. But the existence of a reference to in AppleScript implies that assigning objects to new variables is a by-value operation. And if that's the case, what's the deal with the copy command?
What's going on here?
UPDATE: Well, just consider me a confused Python programmer. Just to make this a bit more clear, I still think
tell app "Finder" to set diskRef to a ref to startup disk
--result: startup disk of application "Finder"
is a poor example (taken from the applescript language guide). But @Chuck's example of a reference to the property itself holding a primitive type that can then be reassigned is a better one. IOW, a reference object is really a variable/property that holds a pointer to another variable or property.