我目前正在开发一个模仿 pythonmath
模块的 Applescript 数学库。pythonmath
模块有一些常量,比如欧拉数等。目前,您可以执行以下操作:
set math to script "Math"
log math's E -- logs (*2.718281828459*)
set math's E to 10
log math's E -- logs (*10*)
因此,我尝试搜索 Applescript 常量,并遇到了官方文档,其中指出,You cannot define constants in scripts; constants can be defined only by applications and by AppleScript.
是否有一个聪明的解决方法,或者我必须为这种事情编写一个 .sdef 文件?
编辑:
我现在也试过这个:
log pi -- logs (*3.14159265359*)
set pi to 10
log pi -- logs (*10*)
pi
是一个 Applescript 常量。如果您再次运行脚本而不再次编译,它看起来像这样:
log pi -- logs (*10*)
set pi to 10
log pi -- logs (*10*)
我不想模仿这种行为,但更想模仿其他常量(如ask
, yes
,no
等)的行为,即使您尝试将它们设置为它们自己也会抱怨。