Why can't you declare and use references to variables unless the variable referenced is scoped globally? Please explain the runtime memory or object structure that leads to the following phenomenon:
Script A fails:
on foo()
set l to {0}
set lref to a reference to l
return item 1 of lref
end foo
foo()
Script B succeeds:
on run
set l to {0}
set lref to a reference to l
return item 1 of lref
end run
Script C succeeds:
on foo()
global l
set l to {0}
set lref to a reference to l
return item 1 of lref
end foo
foo()
See also: How do you efficiently build a list within a handler in AppleScript? and Why Can't AppleScript make firstValue of hash into type reference in this test code?