メインコンテンツまでスキップ

プロパティリストオペレータ

ここで説明するコマンドとオペレータは、プロパティリストを変更して含むプロパティのセットを変更します。

add propertiesまたはreplace propertiesコマンドを使用してプロパティを追加したり、一部のプロパティを可能な限り置換します。remove propertiesおよびretain propertiesコマンドを使用して一部のプロパティを削除します。オブジェクトの一部のプロパティの名前を変更するには、rename propertiesコマンドを使用します。

既存のオブジェクトに影響を与えずにこれらの操作を行うには、コマンドの代わりに対応するオペレータを使用します。

Add Propertiesコマンド、Adding Propertiesオペレータ

動作: add propertiesコマンドとadding propertiesオペレータは、既存のプロパティリストまたはオブジェクトにプロパティリストまたはオブジェクトのプロパティを追加します(それらのプロパティが既に存在しない場合)。これを、既存の値を上書きするreplace propertiesコマンドと比較してみてください。

既存のプロパティリストまたはオブジェクトに新しいプロパティを追加するためにadd propertiesコマンドを使用します。

adding propertiesオペレータを使用して、2つの異なるプロパティリストまたはオブジェクトのプロパティを組み合わせて新しいプロパティリストを作成します。追加する際にプロパティが両方のプロパティリストに存在する場合、sourcePropListのプロパティは常にadditionalPropListのプロパティより優先されます。

コマンド Syntax:
add {the} properties {of} additionalPropList to sourcePropList

オペレータ Syntax:
sourcePropList adding {property | {the} properties {of}} additionalPropList

_additionalPropList_のプロパティが_sourcePropList_にすでに存在する場合、そのプロパティは無視されます。_additionalPropList_が空の場合、コマンドは何も行いません。

例:

put {A:1, C:3} into myObj
add properties {B:2, C:99, D:4} to myObj -- プロパティリスト '{A:1, B:2, C:3, D:4}'になります。add propertiesコマンドは、既存のキーCの値を置換しません。

例:

put {A:1,C:3} into firstProps -- シンプルなプロパティリストから始めます
put firstProps adding properties {B:2, C:99, D:4} into newProps
put newProps -- {A:1, B:2, C:3, D:4}

Replace Propertiesコマンド、Replacing Propertiesオペレータ

動作: replace propertiesコマンドとreplacing propertiesオペレータは、一つのプロパティリストまたはオブジェクトのプロパティを既存のプロパティリストまたはオブジェクトに追加したり、そのプロパティがすでに存在する場合は既存の値を置き換えます。これを、既存の値を上書きしないadd propertiesコマンドと比較してみてください。

既存のプロパティリストまたはオブジェクトに新しいプロパティを追加し、既存のプロパティを置き換えるためにreplace propertiesコマンドを使用します。

replacing propertiesオペレータを使用して、二つの異なるプロパティリストまたはオブジェクトのプロパティを組み合わせて新しいプロパティリストを作成し、二つ目のプロパティリストからの対応するプロパティで最初のプロパティリストのプロパティを上書きします。

コマンド Syntax:
replace {the} properties {of} replacementPropList [of | in] sourcePropList

Operator Syntax:
sourcePropList に名前を変更 {プロパティ | {その} プロパティ} { | を使用して} mapPropertyList

もし_replacementPropList_にあるプロパティがすでに_sourcePropList_に存在するなら、そのプロパティは新しい値に置き換えられます。_replacementPropList_の他の値は_sourcePropList_に追加されます。もし_replacementPropList_が空だった場合、_sourcePropList_は変わりません。

例:

put {A:1, B:2, C:3} into myObj
replace properties {B:"bunny", D:"dog"} of myObj -- プロパティリスト '{A:"1", B:"bunny", C:"3", D:"dog"}'になります。

例:

put {A:1,C:3} into firstProps
put firstProps adding properties {B:2, C:99, D:4} into newProps
put newProps replacing {B:22, D:44} -- {A:1, B:22, C:3, D:44}

Remove Properties コマンド, Removing Properties 演算子

振る舞い: remove propertiesコマンドとremoving properties演算子は、既存のプロパティリストまたはオブジェクトから指定されたプロパティを削除します。この動作はretain propertiesコマンドと比較してみてください、それは明示的に保持されていないすべてのプロパティを削除します。

既存のプロパティリストまたはオブジェクトからいくつかのプロパティを削除するためにremove propertiesコマンドを使用します。

removing properties演算子を使用して、一部のプロパティが削除された1つのプロパティリストのコピーである新しいプロパティリストを作成します。

コマンド 文法:
remove {the} properties {of} propertiesToRemove from sourcePropList

演算子 文法:
sourcePropList removing {property | {the} properties {of}} propertiesToRemove

_propertiesToRemove_は単一のプロパティの名前、プロパティ名のリスト、またはプロパティリストであることができます。プロパティリストが与えられた場合、その値は無視されますが、そのキーは削除するプロパティのリストとして使用されます。_sourcePropList_に存在しないプロパティを削除しようとすると、何も起こりません。

例:

put {A:1, B:2, C:3} into myObj
remove property {B:765} from myObj -- プロパティリスト '{A:1, C:3}' になります。 remove property コマンドは、プロパティと一緒に提供された値が実際のプロパティリストと一致しなくても、プロパティを削除します。
remove properties ["B","C","D"] from myObj -- プロパティリスト '{A:1}' になります。

例:

put {A:1,C:3} into firstProps
put firstProps adding properties {B:2, C:99, D:4} into newProps
put newProps removing properties ("B","C") -- {A:1, D:4}

Retain Properties コマンド, Retaining Properties 演算子

振る舞い: retain propertiesコマンドとretaining properties operatorは、明示的に保持されることを要求されていないプロパティを削除します。これをremove propertiesコマンドと比較してみてください、それは明示的に名前がつけられたプロパティのみを削除します。

既存のプロパティリストまたはオブジェクトから要求されているもの以外のすべてのプロパティを削除するためにretain propertiesコマンドを使用します。

retaining properties演算子を使用して、別のものから新しいプロパティリストを作成し、元のプロパティリストから示されるプロパティのみを含めます。

コマンド 文法:
retain {the} properties {of} propertiesToRetain [of | in] sourcePropList

Operator Syntax:
sourcePropList を維持 {プロパティ | {その} プロパティ {}} propertiesToRetain

propertiesToRetain は単一のプロパティの名前、プロパティ名のリスト、またはプロパティリストであることができます。プロパティリストが与えられた場合、その値は無視されますが、そのキーは維持するプロパティのリストとして使用されます。 sourcePropList に存在しないプロパティを保持しようとすると、何も効果がありません。

例:

put {A:1, B:2, C:3} into myObj
retain properties ["B","C","D"] of myObj -- プロパティリスト'{B:2, C:3}'になります。

例:

put {A:1,C:3} into firstProps -- シンプルなプロパティリストから始めます
put firstProps adding properties {B:2, C:99, D:4} into newProps
put newProps retaining ["B","D","E"] -- {B:2, D:4}

プロパティの名前変更 コマンド、 プロパティの名前変更 オペレータ

動作: プロパティの名前変更 コマンドと プロパティの名前変更 オペレータは、プロパティリストの1つ以上のプロパティの名前を変更します。

名前を変更するプロパティは、プロパティリスト "map" を使用して指定されます。マップのキーは既存のプロパティリストのプロパティの名前で、マップの値はそれらのプロパティの新しい名前です。

マップのすべてのキーが既存のプロパティリストのプロパティ名と一致するわけではない可能性があります。一致しないものは無視されます。また、マップに一致するエントリがない既存のプロパティが存在する可能性もあります。その場合、それらのプロパティはそのままにされます。

既存のプロパティリストまたはオブジェクト内のプロパティの名前を変更するために プロパティの名前変更 コマンドを使用します。

プロパティの名前を変更した修正されたプロパティリストをその場で作成するために プロパティの名前変更 オペレータを使用します。

Command Syntax:
rename [プロパティ | {その} プロパティ] [ | を使用して] sourcePropList [ | を使用して] mapPropertyList
rename [プロパティ | {その} プロパティ] { | を使用して} mapPropertyList [ | を使用して] sourcePropList

Operator Syntax:
sourcePropList renaming {property | {the} properties} {with | using} mapPropertyList

例:

put {A:1, B:2, C:3} into myObj
rename property {b:"bread", D:"donuts"} from myObj -- プロパティリスト'{A:1, bread:2, C:3}'になります。

例:

set cat to {name:"Whiskers", type:"shorthair", color:"gray-striped"}
rename property {type:"breed"} of cat
put cat —> {breed:"shorthair", color:"gray-striped", name:"Whiskers"}

例:

put {x:17, y:42} renaming {x:"time", y:"score"} —> {score:42, time:17}

オペレータ Syntax:

動作: matchingProperties関数は、2つのプロパティリストを比較し、両方に存在し、値が等しいプロパティのみを含む新しいプロパティリストを返します。

構文:
{the} properties [of | in] propertyList1 {that are} {also} [equal to | the same as | identical to | {found} in | {{shared} in} common [with | to] | shared by] {[{the | those} [properties | ones] | those] [of | in]} propertyList2
matchingProperties( propertyList1 , propertyList2 {, caseSensitive} )

例:

set product1 to {
color:red,
size:18,
style:"EMPIRE",
code:"6F-236",
vendor:"Gilford",
status:"discontinued"
}
set product2 to {
color:blue,
size:18,
style:"empire",
finish:"matte",
code:"6G-118",
vendor:"Gilford"
}

put the properties of product1 that are identical to product2
--> {size:18, style:"EMPIRE", vendor:"Gilford"}

put properties of product2 shared in common with those of product1
--> {size:18, style:"empire", vendor:"Gilford"}

put matchingProperties(product1, product2, Yes)
--> {size:18, vendor:"Gilford"}

put properties of product2 shared in common with those of product1 case-sensitive
--> {size:18, vendor:"Gilford"}

関連:

ExcludeProperties 関数

sourcePropList replacing {property | {the} properties {of}} replacementPropList

構文:
{the} properties [of | in] propertyList1 [excluding | without | {that are} different from | [{that are} not | that aren't] [equal to | the same as]] [{the} [properties | ones] | those] {that are} {also} [{found} in | {{shared} in} common [with | to] | shared by | from | of] propertyList2
excludeProperties( propertyList1 , propertyList2 {, caseSensitive} )

例:

set product1 to {
color:red,
size:18,
style:"EMPIRE",
code:"6F-236",
vendor:"Gilford",
status:"discontinued"
}
set product2 to {
color:blue,
size:18,
style:"empire",
finish:"matte",
code:"6G-118",
vendor:"Gilford"
}

put the properties of product1 that are different from the properties of product2
--> {code:"6F-236", color:"red", status:"discontinued"}

put properties of product2 that aren't the same as those in product1
--> {code:"6G-118", color:"blue", finish:"matte"}

put excludeProperties(product1, product2, Yes)
--> {code:"6F-236", color:"red", status:"discontinued", style:"EMPIRE"}

put the properties of product2 excluding those in product1 case sensitive
--> {code:"6G-118", color:"blue", finish:"matte", style:"empire"}

関連: