FileMaker Dictionary 関数

FileMaker Dictionary Functions
以下の blockquote部分は上記出典ページの段落、直後の日本語は内容の拙訳です。
拙訳への具体的な「ちげーよバカ!」な突っ込みは大歓迎です。
※ 万一のトラブルは、出典サイトはもちろん、(たとえそれが僕の拙訳のせいだとしても) 一切関知しませんのであしからず。

素晴らしいカスタム関数を発表してくれた sixfriedrice.com の Jesse Antunes / Geoff Coffey に感謝します。


Since many people were impressed with my named parameters article, I decided to write up another post about the dictionary functions. Actually in all fairness I think three people actually liked it. Vincenzo Menanno, Chris Wack and Sam Barnum this post’s for you!

“named parameters (名前付きパラメータ)” 記事 への皆さんの食いつきがなかなかにすばらしいので、”the Dictionary functions” についての別の post を書くことにしました。
まあ、公平にみて、3人の人たちがこれを気に入ってくれると考えています。
Vincenzo Menanno, Chris Wack and Sam Barnum この post は君たち向けです!

Note: This article was revised November 23, 2007. I added the handyDictReplace function. -Geoff

Note: この記事は、2007/11/23 に改訂しました。
重宝な DictReplace 関数を付け足しました。 – Geoff

First I must warn you, I have left the names of the custom functions the same as the functions we use internally. This means they may seem a little obtuse so feel free to change them. I’m also not getting to in-depth into how they actually work because it could take an extra 5 pages or so (yea I know Geoff… I’m lazy… deal with it). I’m sure most of you will get them pretty quickly despite my inept explanations. Oh yea, I also suggest going back and reading the named parameters post before getting into this post otherwise it probably won’t make much sense.

Enjoy…

まず、最初の注意として…
内部的に使っているカスタム関数の名前はそのまま残しました。
ちょこっとダサイかも知れませんので、自由に変更してください。
それに、どのように振る舞うかの詳細についてまでは触れていません。
そこまでやると、簡単にもう5ページくらいかかってしまうので…はいはい面倒くさがりでごめんね。
ほとんどの方は、私のダサダサな説明などいらないくらいにサクっとおわかりになるでしょうし。
そうそう、 以前に post した “named parameters” の記事についても読んでいただいておいた方がよろしいでしょう。
じゃないと、あんまわからない話になってしまうかも。

楽しんでください…

Note: For the duration of this article I will refer to the custom functionPassParameter( name ; value ) in my previous post as #( ). This saves me 12 key strokes and won’t confuse me because that’s what I call it internally.

Note; 以前 “PassParameter ( name ; value )” として紹介したカスタム関数を#( )としています。こいつのおかげで、12キーストローク楽になりましたし、関数の内部で使っているので別に自分は混乱しないです。( bison 注:2011/02/12 21:09:18 修正しますた。by 今泉さんのありがたいツッコミ)

Using a Dictionary in the Script Result

スクリプト結果で、Dictionary を使う

I actually posted this in the comments of the Named Parameters post. The idea here is that you can not only use the named parameter idea in your script parameters but in your script results as well. So just place your dictionary values in the script result dialog of the Exit Script script step and you’ve go yourself named script results. I like to create a little shortcut to access them like so:

さて、これについては、”Named Parameters” の記事のコメントで post しました。
このアイデアがここで意味するものは…
named parameter のアイデアは、スクリプトパラメータだけでなく、スクリプト結果でも同様に使えるんだよ…ということです。
ですから、スクリプト終了のスクリプトステップの スクリプト結果のダイアログに、あなたの dictionary の値を置いたものをスクリプト結果と名付けて処理を進めれるわけです。
私は、以下のようなちょっとしたショートカットを作るのが好きです;

Name: #R ( name )

Checking for a Name in the Dictionary

Dictionary の中の名前をチェックする

There’s also a point where you may want to check if your dictionary contains a certain value. You could do this by simple using your DictGet() custom function on your Dict. By design, a call to the DictGet() will return empty if the name you are looking for isn’t there. That’s when I made DictContains?

また、「特定の値が あなたの dictionary の中に含まれているかどうか」をチェックしたいときもあるでしょう。
これは、シンプルに あなたの Dect について、DictGet ( ) カスタム関数を使うことで可能です。仕組みとして、あなたが探しているものがそこに無ければ、DictGet ( ) をコールすると、空値が返ります。
それで、DictContains? を作ったのです。

Name: DictContains? ( dict, name )

All this is doing is checking the dictionary structure for the name of the value you are looking for and returning true if it finds the value and false if it doesn’t.

これが行うことのすべては、あなたが探している値の名前で、dictionary 構造 をチェックして、存在すれば true を返し、存在しなければ false を返すということです。

Note: This will not find any nested dictionary values. So if you were to store a dictionary within a dictionary ie. #( “Account” ; #( “Name” ; “Jesse” ) & #( “Job” ; “Writing confusing custom functions” ) ) you wouldn’t be able to use the DictContains? custom function to see if Job is in the dictionary because it is inside the account dictionary.

Note: 入れ子になった distionary の値は見つけられません。
ですから譬えば…
#( “Account” ; #( “Name” ; “Jesse” ) & #( “Job” ; “Writing confusing custom functions” ) )
といった dictrionary において、”Job” が dictionary にあるかどうかをチェックするのに
DictContains? を使うことはできません。
なぜなら、”Job” は、Account dictionary の内部に存在するからです。

Removing an Entry from a Dictionary

Dictionary から エントリを削除する

You never know when, but there will be a point where you think… “Man, I wish I could remove a value from my dictionary.” Well, maybe you won’t… but I wrote this thing anyway. If you happen to bump into this situation, you can use the nifty function below. DictRemove() simply removes the dictionary name/value pair specified from the dictionary passed in.

いつとは言えませんが、こう考えることもあるでしょう。
「なあ、オイラの dictionary の中から値を削除したいんだけど…」
…まあ、ないかもしれませんが…とにかくそれについて書きました。
もし、ばったり、そんな状況に出くわしたなら、下記の気の利いた関数を使うことができます。
DictRemove ( ) は、特定の name/value のペアを、受け渡された dictionary からシンプルに削除します。

Name: DictRemove ( dict , name )

Replacing an Entry in a Dictionary

Dictionary のエントリを置換する

This function is primarily for convenience. It combines DictRemove with a new entry to effectively replace a value in the dictionary in one shot:

この関数は、やたら便利だったらありゃしません。
DictRemove と新エントリを結合して、一発で dictionary 中の値を効果的に置き換えます。

Name: DictReplace ( dict, name, value )

Returning the Top Name in a Dictionary

Dictionary 中の Top Name を返す

This custom function was designed to return the name of the first name-value pair in the dictionary. Nothing too special, but I if used in conjunction with the DictRemove() function above, you can pop off the top value of the dictionary with ease.

このカスタム関数は、dictionary 中の 最初の name/value のペアの name を返します。
特別なことは何もしていませんが、上記の DictRemove ( ) 関数と連携させて使うと、簡単に、最初の値を消すことができます。

Name: DictFirst( dict )

Adding to a Dictionary

Dictionary に追加する

This custom function is ridiculously easy. It’s really just a shortcut that looks a little more succinct then actually performing the action manually.

このカスタム関数は、バカほど簡単です。
実際に手動で行うよりほんの少し簡潔にしたショートカットです。

Name:DictAdd( dict; name; value )

Dictionary To String

Dictionaryを文字列に

This is quite frankly my favorite custom function ever. Serioulsy, I have a ton of ridiculous functions that no one uses but me, but this is the creme de la creme. I’ll get slightly more indepth about this function because it can be a little tricky to understand. Here is the signature of the function:

これは、実際率直に言って、お気に入りのカスタム関数です。
マジに、自分以外だれが使うねん…な関数を山ほど使っていますが、こいつは、最高です。
ただ理解するのにちょこっとトリッキーかも知れないので、やや詳細に言及します。
これがこの関数の書式です。

The real magic of this function comes from the Format parameter. This parameter will dictate how you want the data displayed. The function goes through each and every dictionary entry and will put it into whichever format you specific. To achieve this functionality a replace is performed on the Format. $name is replaced with the name of the dictionary entry and $value is replaced with the value of the dictionary entry. Here is the function:

この関数のキモは、Format parameter です。
このパラメータには、「どのようにデータを表示させたいか」を記述します。
この関数は、個々の dictionary エントリに対して実行され、あなたの指定したフォーマットに仕上げます。
$name は、dictionary エントリの name と、$value は、value と置き換えられます。
以下がその関数です。

Name: DictToString( Dict ; Format )

Let’s say your Format parameter is:
たとえば、あなたのフォーマットパラメータが以下のようだったとします。

and your dictionary is

そして、あなたの dictionary がこうだったとします。

the output would be

すると、出力はこうなります。

You can now basically output your dictionaries in any format you so desire. Such as…. you guessed it…. XML.

基本的に、どんなフォーマットにでも思いのままに、あなたの dictionary を出力できます。
たとえば…考えてみそ…XMLとか…

Dictionary To XML

Dictionary を XML に

So once you understand the DictToString() custom function, the DictToXML() function is just a shortcut that I wrote so I don’t have to write the funky format over and over. Here is is:

さて、DictToString ( ) を理解したところで、DictToXML ( ) 関数は、
なんども繰り返し土臭いフォーマットを書かずにすむように作った
単なるショートカットです。
それはこうです。

Name: DictToXML ( dict )

Let’s say you setup your dictionary like so #( “account” ; #( “name” ; “Jesse” ) & #( “birthday” ; “Yesterday” ) ). You’ll notice that I have put a pair of dictionaries within another dictionary named account. The DictToXML function (really the DictToString() function does the bulk of the work but you get the point) will actually iterate through the outside and inside dictionary and output the following:

さて、あなたの dictionary を

と設定したとします。
ふたつの dictionary をアカウントという名前のもうひとつの dictionaryに入れたことがわかりますね。
DictToXML 関数 (ほとんどの機能を DictToString ( ) 関数が行うわけではありますが) は、外側と内側の dictionary を行ったり来たりして、以下を出力します。

This can be very useful for creating tidbits of xml to post to web actions. Sweet Huh?

Webアクションに post するtidbits の XML を生成するのにピッタリだしょ?よかんべ?


  1. FileMaker – マルチプルスクリプトパラメータの受け渡し
  2. マルチプルパラメータのスクリプトへの受け渡し – 応用編
  3. FileMaker Dictionary 関数 (このエントリ)

コメント

  1. […] 拙訳 […]

  2. […] ●bisonさんの和訳 https://bison.jp/filemaker/715.html […]

  3. […] FileMaker Dictionary 関数 […]

  4. hige339 より:

    ファイルメーカーで配列を扱う方法を探していてたどり着きました。
    和訳楽しめました。
    有難うございました。

タイトルとURLをコピーしました