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

リストとプロパティリストのローカルおよびグローバルプロパティ

ここで説明されるSenseTalkのグローバルプロパティとローカルプロパティは、スクリプト内のリストとプロパティリストの動作を制御します。これらのオプションを設定または変更することで、フォーマット、挿入方法、および他のアクションをカスタマイズして環境を調整できます。

SenseTalkのリストとプロパティリストに関する完全な情報については、リストプロパティリストをご覧ください。

Closedローカルおよびグローバルプロパティ値の設定または変更

SenseTalkのコマンド Set または Put を使用してグローバルプロパティ値を設定できます。これらのプロパティのいずれかを参照するときは、通常の変数と区別するためにプロパティ名の前に the を使用する必要があります。

例:

set the searchrectangle to [1,2,2,3]

次のようにしてグローバルプロパティ内の特定の名前付きプロパティを追加または変更できます:

set the namedColors.pink to color("RGB,1.0,0.5,0.5") -- namedColorsグローバルプロパティにピンクを追加し、そのRGB色値を定義します
set the listFormat's separator to " & " -- listFormatグローバルプロパティのseparatorプロパティを設定します

プロパティは、setoption コマンドまたは setoptions コマンドを使用して設定または更新することもできます。 setoption コマンドは単一のプロパティを更新することができ、 setoptions は複数のプロパティを更新することができます。

例:

setoption searchrectangle, [1,2,2,3]
setoptions {searchrectangle: [1,2,2,3], scriptlogging: yes}
ノート

setoptionsetoptions はグローバルおよびローカルプロパティの使用に特化しているため、これらのコマンドのコマンド構文においてプロパティ名から the を省略します。

ローカルおよびグローバルプロパティの操作に関する詳細な情報については、SenseTalkのローカルおよびグローバルプロパティを参照してください。

the listFormat グローバルプロパティ

値: 三つの必須値を含むプロパティリストで、追加で二つの値を含むこともあります:

  • prefix: リストがテキストに変換されたときにリストの前に出る文字。
  • separator: リストがテキストに変換されたときにリストの各項目の間に出る文字。
  • suffix: リストがテキストに変換されたときにリストの最後に出る文字
  • quotes (任意): このプロパティはリストの値が引用符で囲まれる方法を定義します。デフォルトでは、リストには quotes 値が設定されていないため、リストの値の引用は the defaultQuoteFormat グローバルプロパティの設定に従います。
  • indent (任意): このプロパティはインデントに使用するテキスト値に設定できます。 indent 値を設定すると、個々のリストアイテムが構造のネストに応じてインデント値の倍数でインデントされた別々の行に表示されます。

デフォルト: 最初に設定されるのは三つの必要な値のみです:

  • prefix: [
  • separator: ,
  • suffix: ]

動作: このグローバルプロパティは、リストをテキスト形式に変換するために使用する形式を定義します。リストをテキストとして表示するとき、リストはprefix値とsuffix値で囲まれ、各リスト項目の間にはseparator値が使用されます。

the listFormatの事前定義された値には、boxListFormatjsonListFormat、およびstandardListFormatが含まれます。

例:

set the ListFormat's separator to period // 'period'キーワードを使用してListFormatのseparatorを"."に設定します

例:

set the listFormat's quotes to "^"
put ["cheese","meat","fruit"] // '[^cheese^,^meat^,^fruit^]'を表示します

例:

set the listformat to {separator:";"}
put ["cheese","meat","fruit"] // 'cheese;meat;fruit'を表示します

例:

set the ListFormat.prefix to "-->"
put ["cheese","meat","fruit"] // '-->cheese,meat,fruit]'を表示します

例:

set the ListFormat to {separator:";",quotes:"^"}
put ["cheese","meat","fruit"] //'^cheese^;^meat^;^fruit^'を表示します

例:

set the listformat to boxListFormat
put (1,2,3,5,7) // 【1】 【2】 【3】 【5】 【7】を表示します

例:

set the listformat to jsonListFormat
put (1,2,3,5,7)

上記の例からの出力は、Runウィンドウに次のように表示されます:

[
1,
2,
3,
5,
7
]

例:

set the listFormat.prefix to "[["
set the listFormat's suffix to "]]"
put [1,2,3,4] // '[[1,2,3,4]]'を表示します
set the listFormat's separator to " & "
set the listFormat's quotes to ["<",">"]
put [5,6,7,8] // '[[<5> & <6> & <7> & <8>]]'を表示します
set the listFormat's indent to " "
put [1,[10,20,30],2]

この例からの最終的なputコマンドは、Runウィンドウに次のように表示されます:

[[
<1> &
[[
<10> &
<20> &
<30>
]] &
<2>
]]

例:

set the listformat to standardListFormat
put [1,2,3,5,7] //'[1,2,3,5,7]'を表示します

関連:

Miscellaneous Operatorsで説明されているsplit byjoined byオペレータは、テキストをリストに、またはその逆に明示的に変換する方法を提供します。リストの操作に関する詳細は、ListsおよびProperty Listsを参照してください。

the propertyListFormat グローバルプロパティ

値: 以下のプロパティ値を含むプロパティリスト:

  • prefix: テキストに変換したときにリストの前に現れる文字。
  • entrySeparator: テキストに変換したときにリストの各キー/値ペアの間に現れる文字。
  • keySeparator: テキストに変換したときにキーとその値の間に現れる文字。
  • suffix: テキストに変換したときにリストを終了する文字。
  • quotes: テキストに変換したときにプロパティ値を引用するために使用される文字または文字列。
  • emptyRepresentation: オブジェクトがテキストに変換されたときにプロパティがない場合に使用される文字または文字列。
  • indent (任意): このプロパティは、リスト内の項目をインデントするために使用されるテキスト値に設定できます。indent値を設定すると、個々のリスト項目が構造のネストに応じてインデント値の倍数によってインデントされた値と共に別々の行に表示されます。
  • asTextEnabled: TrueFalse

デフォルト: 下の 動作 セクションを参照してください。

  • prefix: {
  • entrySeparator: ", " (コンマとスペース)
  • keySeparator: :
  • suffix: }
  • quotes: Standard
  • emptyRepresentation: {:}
  • asTextEnabled: True

動作: このグローバルプロパティは、プロパティリスト(オブジェクト)をテキストに変換するときに使用されるフォーマットを定義します。

asTextEnabledTrue(デフォルト)の場合、オブジェクトのテキスト表現が必要となると、そのオブジェクトにasText関数メッセージが送られ、そのテキスト表現を取得します。オブジェクトがこのメッセージに応答しない場合、asTextまたはasTextFormatプロパティがテキスト表現を得るために使用されます。

asTextEnabledFalseであるか、asTextメカニズムが値を返さない場合、他の値が使用されます。その場合、オブジェクトのプロパティは、それぞれのキー(プロパティ名)がその値の前に位置し、keySeparator(デフォルトは":")で分離され、エントリはentrySeparator(デフォルトは", ")で分離される形でリスト化されます(キーはそのキーのアルファベット順)。

プロパティ値は、quotes値に従って引用されます(プロパティリストに対するデフォルトはStandardです。the defaultQuoteFormatグローバルプロパティを参照)。全体のテキストは、prefixsuffix(デフォルト値は"")で囲まれます。オブジェクトにプロパティがない場合、emptyRepresentationプロパティの値(デフォルトは"{:}")がそのテキスト表現として使用されます。

keySeparatorが空に設定されている場合、オブジェクトのキーはリストには表示されず、その値のみが表示されます。

indent値は、オブジェクト内のエントリをインデントするために使用されるテキスト値に設定できます。空以外に設定されると、各エントリは別の行に表示され、各行は構造のネストに応じてインデント値の倍数でインデントされます。

例:

propertyListFormatのentrySeparatorを"*"に設定する

例:

propertyListFormatのkeySeparatorを"%"に設定する
put {Capitol:"Lansing",Bird:"robin"} // 表示 '[Bird%"robin", Capitol%"Lansing"]'

例:

propertyListFormatを{entrySeparator:";"}に設定する // keySeparatorが空なので、値だけが表示されます
put {Capitol:"Lansing",Bird:"robin"} // 表示 'robin;Lansing'

例:

put {astext:"Michigan",Capitol:"Lansing",Bird:"robin"} // 表示 'Michigan'
propertyListFormat.asTextEnabledをfalseに設定する
put {astext:"Michigan",Capitol:"Lansing",Bird:"robin"} // 表示 '{astext:"Michigan", Bird:"robin", Capitol:"Lansing"}'

例:

propertyListFormatを{entrySeparator:"$",keySeparator:"*"}に設定する
put {Capitol:"Lansing",Bird:"robin"} // 表示 'Bird*robin$Capitol*Lansing'

例:

propertyListFormatにプロパティ{prefix:"[[", suffix:"]]", entrySeparator:"; ", \
keySeparator:" is "}を置き換える
put {A:1,C:3,B:2} -- 表示 [[A is "1"; B is "2"; C is "3"]]
propertyListFormatのkeySeparatorを削除する
propertyListFormat.quotesを"None"に設定する
put {A:1,C:3,B:2} -- 表示 [[1; 2; 3]]
propertyListFormat.emptyRepresentationを"[[no properties]]"に設定する
put {:} -- 表示 [[no properties]]

関連:

プロパティリストをテキスト表現に変換する詳細については、ListsProperty Listsを参照してください。

the listInsertionMode ローカルプロパティ

値: item by item, nested

デフォルト: the defaultListInsertionMode グローバルプロパティ(最初は item by itemに設定)

動作: このローカルプロパティは、リストにアイテムのリストを追加する際のアイテムの振る舞いを制御します。プロパティが item by itemに設定されている場合、追加するリストから各アイテムが個別に追加されます。プロパティが nestedに設定されている場合、追加するリストはネストされたリストとして追加されます。

the listInsertionModeの値は、各ハンドラにローカルです。ハンドラが実行を開始すると、そのハンドラ内の the listInsertionModeは初めて the defaultListInsertionMode グローバルプロパティの値に設定されます。

例:

set the ListInsertionMode to nested // ローカルプロパティ the ListInsertionMode をデフォルトの "item by item" から変更します

例:

set the listInsertionMode to nested
put ["maple","oak","pine"] into localtrees
insert ["willow","sassafras"] after localtrees
log localtrees // 表示 '[maple,oak,pine,[willow,sassafras]]'

例:

put [1,2,3,4] into list // [1,2,3,4]
put ["A","B"] into otherList // [A,B]
insert otherList after item 2 of list // [1,2,A,B,3,4]
set the listInsertionMode to "nested"
insert otherList after item 2 of list // [1,2,[A,B],A,B,3,4]

例:

set Biggest to ["sun","earth"]
set Smallest to ["moon","you"]
log myNestedList(Biggest,Smallest,2) // 表示 '[sun,[moon,you],earth]'
insert Smallest before item 2 of Biggest // The ListInsertionModeはデフォルトの"item by item"に設定されています
log Biggest // 表示 '[sun,moon,you,earth]'
to myNestedList InitialList,SecondaryList,position // カスタム関数ハンドラ "myNestedList" を宣言し、3つのパラメーターを指定します
set the ListInsertionMode to nested // ListInsertionModeローカルプロパティを指定することで、この設定は関数ハンドラのみに適用され、初期スクリプトハンドラには適用されません
insert SecondaryList before item position of InitialList
return InitialList
end myNestedList
先端

特定のハンドラの動作のみを変更したい場合は、the listInsertionModeローカルプロパティを使用します。現在のランタイム環境でスクリプトとハンドラをまたがって設定が維持されるようにするためには、the listInsertionModeローカルプロパティではなく、the defaultListInsertionModeグローバルプロパティを使用します。

関連:

the defaultListInsertionMode グローバルプロパティ

値: item by item, nested

デフォルト: item by item

動作: このグローバルプロパティは、リストにアイテムのリストを追加するときのアイテムの振る舞いを制御します。プロパティが item by itemに設定されている場合、追加するリストから各アイテムが個別に追加されます。プロパティが nestedに設定されている場合、追加するリストはネストされたリストとして追加されます。

例:

set the defaultListInsertionMode to nested

例:

put ["A","B","C"] into Letters
set the defaultListInsertionMode to nested
insert [1,2] before item 2 of Letters
put Letters // 表示 '[A,[1,2],B,C]'

例:

set People to ["Susan","Joe","Ricky","Jennifer"]
set the defaultListInsertionMode to nested
insert ["Robert","Kelly"] into People
log People // 表示 '[Susan,Joe,Ricky,Jennifer,[Robert,Kelly]]'

例子:

put ["A","B","C"] into Letters
set the defaultListInsertionMode to nested
insert [1,2] before item 2 of Letters
put Letters // Displays '[A,[1,2],B,C]'
先端

特定のハンドラから呼び出すときの動作を変更したい場合は、ローカルプロパティの the listInsertionMode を使用してください。現在のランタイム環境のスクリプトとハンドラ間で設定を持続させるためには、グローバルプロパティの the defaultListInsertionMode を使用します(ローカルプロパティの the listInsertionMode ではなく)。

関連:

the DuplicatePropertyKeyMode グローバルプロパティ

値: error, first, last, list

デフォルト: error

動作: プロパティリスト内で同じキーが繰り返される場合、このグローバルプロパティがその扱いを制御します。

  • このプロパティが error に設定されている場合、例外がスローされます。
  • このプロパティが first または last に設定されている場合、そのキーに対して最初(または最後)に指定された値のみが使用されます。重複するキーは無視されます。
  • このプロパティが list に設定されている場合、そのキーに対して指定されたすべての値が受け入れられ、リストに組み合わされます。

例子:

set the DuplicatePropertyKeyMode to error // 重複するキーがあるプロパティリストへの参照があるとエラーをスローします、例えば '{Capitol:"Lansing",Population:"9.928 million",Population:"26"}'

例子:

set the duplicatePropertyKeyMode to last
set meal to ({beverage:"Water",dessert:"Ice Cream",entree:"Hamburger",dessert:"Cake"})
log meal // 表示 '{beverage:"Water", dessert:"Cake", entree:"Hamburger"}'

例子:

set the duplicatePropertyKeyMode to list
set meal to ({beverage:"Water",dessert:"Ice Cream",entree:"Hamburger",dessert:"Cake"})
log meal // 表示 '{beverage:"Water", dessert:[Ice Cream,Cake], entree:"Hamburger"}'

関連:

プロパティリストの操作についての詳細は、プロパティリストをご覧ください。

the strictProperties グローバルプロパティ

値: True, False

デフォルト: False

動作: このプロパティは、プロパティリスト内で設定されていないプロパティにアクセスしようとしたときに何が起こるかを制御します。the strictPropertiesfalseに設定されている場合、SenseTalkは未定義のプロパティの値としてemptyを返します。the strictPropertiestrueに設定すると、未定義のプロパティにアクセスすると例外がスローされます。

例子:

set the StrictProperties to true // 未定義のプロパティを参照するとエラーが発生するようにデフォルトの動作を変更します

例子:

set the StrictProperties to true
put {Capitol:"Lansing",Bird:"robin",Population:"9.928 million"} into Michigan
Log Michigan's Song // 'Song'はプロパティリストで定義されたプロパティではないためエラーをスローします。StrictPropertiesがfalseの場合、ログコマンドは空のメッセージを表示します。

例子:

put a new object into emptyObj
put (property abc of emptyObj) is empty -- 'true'を表示します
set the strictProperties to true
put (property abc of emptyObj) is empty -- throws an exception

the objectContainsItemDefinition グローバルプロパティ

値: AsTextContains, NestedValueContains, KeyOrValueEquals

デフォルト: AsTextContains

動作: このプロパティは、演算子または関数がプロパティリスト内のキーと値にアクセスする方法を制御します。このプロパティがAsTextContains(デフォルトの動作)に設定されている場合、containsItem関数はオブジェクトのテキスト値が検索値を含む場合にtrueを返します。NestedValueContainsに設定されている場合、演算子はオブジェクトの各値に適用され、そのうちのどれかが検索値を含む場合、式はtrueを返します。最後に、KeyOrValueEqualsの設定は、検索値がオブジェクトのキーの一つまたはその値の一つと等しい場合、trueを返します。

例子:

set the objectContainsItemDefinition to KeyOrValueEquals // オブジェクトのキーと値の両方をチェックして、それらが検索値と一致するかどうかを確認します

例子:

set State to {AsText:"Michigan",Capitol:"Lansing",Bird:"robin",Population:"9.928 million"}
log State contains "robin" // 'False'を表示します
set the objectContainsItemDefinition to NestedValueContains
log State contains "robin" // 'True'を表示します

例子:

set PersonalInfo to {asText:"Robert",age:31,hair:"brown",height:"5 feet 11 inches",degrees:["BS","MS"]}
put "hair" is among the keys of PersonalInfo // 'true'を返します
put PersonalInfo contains "hair" // プロパティリストのテキスト値が "Robert" であるため、'false' を返します
set the objectContainsItemDefinition to KeyorValueEquals
put "hair" is in PersonalInfo // hairはプロパティリストのキーであるため、'true'を返します
put "BS" is in PersonalInfo // "BS"はプロパティリストのキーでも値でもないため、'false'を返します
set the objectContainsItemDefinition to NestedValueContains
put PersonalInfo contains "BS" // "BS"はプロパティリストのネストされた値であるため、'true'を返します

関連: