is there sort of variable instruction in Applescript?

Hi

I’m looking for something as we had in the old times in the high level programming languages

set i to “set var to 3.14”
execute i

Any hint is welcome
Regards
Lazy

You can do this with subroutines.

on run
	i() -- call the subroutine
end run
on i() -- the subroutine
	set var to 3.14
end i
set i to "set var to 3.14"
run script i 

EDIT:
Evals are vulnerable against injections so don’t use any user input there or make sure you escape the data correctly. Another thing is that var is set inside the new created script object by run script and will not be able in the current script object. If you want to be able to access the variables of the script object you should use


set i to "set var to 3.14
return me"
set prototype to run script i
return prototype's var

Why not :


script i
	set var to 3.14
end script

return run script i

Yvan KOENIG (VALLAURIS, France) jeudi 26 janvier 2012 19:00:14

I don’t think it’s relevant to to question because there is no eval (i think that was the whole point) and your code is exactly the same as my first one and you have the same problem as I mentioned in my edited comments how you can use variables and how to solve that problem.

I apologize

I posted because it doesn’t behave like your’s.


set i to "set var to 3.14
return me"

script i1
	set var to 3.14
	return me
end script

script i2
	set var to 3.14
end script

set prototype to run script i

set prototype1 to run script i1

set prototype2 to run script i2

log (get prototype's var)
log (get prototype1's var)
log (get prototype2's var)

The results are :
(3.14)
(var)
Résultat :
error “Il est impossible d’obtenir var of 3.14.” number -1728 from var of 3.14

Yvan KOENIG (VALLAURIS, France) jeudi 26 janvier 2012 20:47:29