AppleScript数据共享机制解析

需积分: 44 37 下载量 201 浏览量 更新于2024-08-08 收藏 2.4MB PDF 举报
"数据共享机制-ak09911-preliminary-e-00" 在AppleScript中,数据共享机制是指在复制和修改数据时,特别是通过赋值语句如"set b to a"来处理原数据和新数据内容的方式。AppleScript的数据处理方式与大多数主流编程语言保持一致。 **基本数据类型的共享机制(不含Record和List)** 对于非Record和List类型的变量,AppleScript采取的是"拷贝"机制,即pass-by-value。这意味着当执行"set b to a"时,变量b会得到变量a的一个值的副本。例如,如果a等于1,然后设置b等于a,那么b也将等于1。即使随后改变了b的值(例如,将其设为0),这不会影响a的值,因为它们各自持有独立的副本。因此,修改a或b不会互相影响彼此的值。 ```appleScript set a to 1 set b to a -- 这时,a和b都等于1 set b to 0 -- 修改b后,a仍为1,b变为0 ``` **Record和List的数据共享机制** 然而,对于Record和List类型的数据,AppleScript采用"共享数据,只增加引用参考"的方式,即pass-by-reference。这意味着如果将一个Record或List赋值给另一个变量,两个变量将共享同一个数据结构,而不是拥有独立的副本。因此,修改其中一个变量会影响到另一个变量,因为它们都指向同一个内存位置。 ```appleScript set a to {1, 2, 3, 4, 5} set b to a -- 这时,a和b都引用同样的List changeFirstItemOf b to 6 -- 改变b的第一个元素,a的第一个元素也会改变,因为它们共享数据 ``` 在上面的例子中,改变b的第一个元素时,a的第一个元素也会相应地改变,因为它们都引用了同一List。这种共享机制在处理复杂数据结构时非常重要,但同时也需要谨慎操作,以防止无意间修改了不应该改动的数据。 AppleScript是一种简单易学且实用的脚本语言,适用于MacOSX平台。它允许用户通过脚本自动化各种任务,提高工作效率。本教程旨在提供AppleScript的基础知识,并通过实例解释数据共享机制,帮助读者更好地理解和使用AppleScript。尽管教程中的一些截图基于特定版本的MacOSX,但基本概念和语法在不同版本的系统中是通用的。对于想要深入学习AppleScript的用户,推荐查阅苹果官方的《AppleScript Language Guide》以及相关的在线资源。

解释:% 'Distance' - Distance measure, in P-dimensional space, that KMEANS % should minimize with respect to. Choices are: % {'sqEuclidean'} - Squared Euclidean distance (the default) % 'cosine' - One minus the cosine of the included angle % between points (treated as vectors). Each % row of X SHOULD be normalized to unit. If % the intial center matrix is provided, it % SHOULD also be normalized. % % 'Start' - Method used to choose initial cluster centroid positions, % sometimes known as "seeds". Choices are: % {'sample'} - Select K observations from X at random (the default) % 'cluster' - Perform preliminary clustering phase on random 10% % subsample of X. This preliminary phase is itself % initialized using 'sample'. An additional parameter % clusterMaxIter can be used to control the maximum % number of iterations in each preliminary clustering % problem. % matrix - A K-by-P matrix of starting locations; or a K-by-1 % indicate vector indicating which K points in X % should be used as the initial center. In this case, % you can pass in [] for K, and KMEANS infers K from % the first dimension of the matrix. % % 'MaxIter' - Maximum number of iterations allowed. Default is 100. % % 'Replicates' - Number of times to repeat the clustering, each with a % new set of initial centroids. Default is 1. If the % initial centroids are provided, the replicate will be % automatically set to be 1. % % 'clusterMaxIter' - Only useful when 'Start' is 'cluster'. Maximum number % of iterations of the preliminary clustering phase. % Default is 10. %

2023-05-18 上传