【发布时间】:2021-10-03 14:15:03
【问题描述】:
我目前正在开发一个模仿 python math 模块的 Applescript 数学库。 python math 模块有一些常量,如Euler's number 等。目前,您可以执行以下操作:
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 常量并遇到了 the official documentation,其中提到了 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 等其他常量的行为,它们会抱怨,即使您尝试将它们设置为自己。
【问题讨论】:
标签: constants applescript